1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Andrew Niefer

CORE

Support the content assist lookup kind LookupKind.THIS, where the lookup 
looks in the class of the this pointer.
Fix a bug where the forward declared functions/methods appeared twice in 
the content assist results .

TESTS

Added ContextualParseTest::testCompletionLookup_LookupKindTHIS
This commit is contained in:
John Camelon 2004-01-07 02:00:22 +00:00
parent 24e017a04a
commit 7a48cc3a16
7 changed files with 98 additions and 22 deletions

View file

@ -1,3 +1,6 @@
2004-01-06 Andrew Niefer
Added ContextualParseTest::testCompletionLookup_LookupKindTHIS
2004-01-06 John Camelon 2004-01-06 John Camelon
Added CompleteParseASTTest::testBug43110() and QuickParseASTTests::testBug43110(). Added CompleteParseASTTest::testBug43110() and QuickParseASTTests::testBug43110().

View file

@ -371,4 +371,54 @@ public class ContextualParseTest extends CompleteParseBaseTest {
assertEquals( aLocal.getName(), "aLocal" ); assertEquals( aLocal.getName(), "aLocal" );
assertEquals( aParameter.getName(), "aParameter" ); assertEquals( aParameter.getName(), "aParameter" );
} }
public void testCompletionLookup_LookupKindTHIS() throws Exception{
StringWriter writer = new StringWriter();
writer.write( "int aGlobalVar;" );
writer.write( "namespace NS { " );
writer.write( " int aNamespaceFunction(){}" );
writer.write( " class Base { " );
writer.write( " protected: int aBaseField;" );
writer.write( " };" );
writer.write( " class Derived : public Base {" );
writer.write( " int aMethod();" );
writer.write( " };" );
writer.write( "}" );
writer.write( "int NS::Derived::aMethod(){");
writer.write( " int aLocal;" );
writer.write( " a ");
String code = writer.toString();
int index = code.indexOf( " a " );
IASTCompletionNode node = parse( code, index + 2 );
assertNotNull( node );
assertEquals( node.getCompletionPrefix(), "a" );
assertTrue( node.getCompletionScope() instanceof IASTMethod );
LookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS },
node.getCompletionContext() );
assertEquals( result.getResultsSize(), 2 );
Iterator iter = result.getNodes();
IASTMethod method = (IASTMethod) iter.next();
IASTField field = (IASTField) iter.next();
assertFalse( iter.hasNext() );
assertEquals( method.getName(), "aMethod" );
assertEquals( field.getName(), "aBaseField" );
result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS, IASTNode.LookupKind.METHODS },
node.getCompletionContext() );
assertEquals( result.getResultsSize(), 1 );
iter = result.getNodes();
method = (IASTMethod) iter.next();
assertFalse( iter.hasNext() );
assertEquals( method.getName(), "aMethod" );
}
} }

View file

@ -1,3 +1,7 @@
2004-01-06 Andrew Niefer
For Content Assist, support lookup using LookupKind.THIS (lookup in the class of the this pointer )
Fix bug where forward declared method/functions appeared twice in the content assist lookup results.
2004-01-06 John Camelon 2004-01-06 John Camelon
Renamed IToken::tELIPSE to IToken::tELLIPSIS Renamed IToken::tELIPSE to IToken::tELLIPSIS
Partially fixed Bug 43110 : Parser support needed for functions with ellipses Partially fixed Bug 43110 : Parser support needed for functions with ellipses

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol; import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension; import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner; import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException; import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter; import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
@ -52,19 +53,34 @@ public class ASTNode implements IASTNode {
throw new LookupException(); throw new LookupException();
} }
TypeFilter filter = null; boolean lookInThis = false;
if( kind != null && kind.length > 0 ){
filter = new TypeFilter( kind[0] ); TypeFilter filter = new TypeFilter();
for( int i = 1; i < kind.length; i++ ){ if( kind != null ){
filter.addFilteredType( kind[i] ); for( int i = 0; i < kind.length; i++ ){
filter.addAcceptedType( kind[i] );
if( kind[i] == LookupKind.THIS ){
lookInThis = true;
if( kind.length == 1 ){
filter.addAcceptedType( LookupKind.ALL );
}
} else {
filter.addAcceptedType( kind[i] );
}
} }
} else { } else {
filter = new TypeFilter(); filter.addAcceptedType( LookupKind.ALL );
} }
List lookupResults = null; List lookupResults = null;
try { try {
if( qualification != null ){ if( lookInThis ){
ISymbol thisPointer = thisContainer.lookup( ParserSymbolTable.THIS );
ISymbol thisClass = ( thisPointer != null ) ? thisPointer.getTypeSymbol() : null;
if( thisClass != null && thisClass instanceof IContainerSymbol ){
lookupResults = ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true );
}
} else if( qualification != null ){
lookupResults = qualification.prefixLookup( filter, prefix, true ); lookupResults = qualification.prefixLookup( filter, prefix, true );
} else { } else {
lookupResults = thisContainer.prefixLookup( filter, prefix, false ); lookupResults = thisContainer.prefixLookup( filter, prefix, false );

View file

@ -381,9 +381,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
ISymbol foundSymbol = null; ISymbol foundSymbol = null;
LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() ); LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() );
data.filter.addFilteredType( TypeInfo.t_class ); data.filter.addAcceptedType( TypeInfo.t_class );
data.filter.addFilteredType( TypeInfo.t_struct ); data.filter.addAcceptedType( TypeInfo.t_struct );
data.filter.addFilteredType( TypeInfo.t_union ); data.filter.addAcceptedType( TypeInfo.t_union );
data.foundItems = ParserSymbolTable.lookupInContained( data, inSymbol ); data.foundItems = ParserSymbolTable.lookupInContained( data, inSymbol );

View file

@ -388,7 +388,7 @@ public class ParserSymbolTable {
Iterator iter = ( object instanceof List ) ? ((List)object).iterator() : null; Iterator iter = ( object instanceof List ) ? ((List)object).iterator() : null;
ISymbol symbol = ( iter != null ) ? (ISymbol) iter.next() : (ISymbol) object; ISymbol symbol = ( iter != null ) ? (ISymbol) iter.next() : (ISymbol) object;
List functionList = new LinkedList(); Set functionSet = new HashSet();
ISymbol obj = null; ISymbol obj = null;
IContainerSymbol cls = null; IContainerSymbol cls = null;
@ -400,7 +400,11 @@ public class ParserSymbolTable {
foundSymbol = symbol; foundSymbol = symbol;
if( foundSymbol.isType( TypeInfo.t_function ) ){ if( foundSymbol.isType( TypeInfo.t_function ) ){
functionList.add( foundSymbol ); if( foundSymbol.isForwardDeclaration() && foundSymbol.getTypeSymbol() != null ){
foundSymbol = foundSymbol.getTypeSymbol();
}
functionSet.add( foundSymbol );
} else { } else {
//if this is a class-name, other stuff hides it //if this is a class-name, other stuff hides it
if( foundSymbol.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) ){ if( foundSymbol.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) ){
@ -448,7 +452,7 @@ public class ParserSymbolTable {
} }
} }
int numFunctions = functionList.size(); int numFunctions = functionSet.size();
boolean ambiguous = false; boolean ambiguous = false;
@ -457,8 +461,8 @@ public class ParserSymbolTable {
if( obj != null && cls.getContainingSymbol() != obj.getContainingSymbol()){ if( obj != null && cls.getContainingSymbol() != obj.getContainingSymbol()){
ambiguous = true; ambiguous = true;
} }
if( functionList != null ){ if( !functionSet.isEmpty() ){
Iterator fnIter = functionList.iterator(); Iterator fnIter = functionSet.iterator();
IParameterizedSymbol fn = null; IParameterizedSymbol fn = null;
for( int i = numFunctions; i > 0; i-- ){ for( int i = numFunctions; i > 0; i-- ){
fn = (IParameterizedSymbol) fnIter.next(); fn = (IParameterizedSymbol) fnIter.next();
@ -477,7 +481,7 @@ public class ParserSymbolTable {
return obj; return obj;
} }
} else if( numFunctions > 0 ) { } else if( numFunctions > 0 ) {
return functionList; return new LinkedList( functionSet );
} }
if( ambiguous ){ if( ambiguous ){

View file

@ -22,7 +22,6 @@ import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
public class TypeFilter { public class TypeFilter {
public TypeFilter(){ public TypeFilter(){
acceptedTypes.add( TypeInfo.t_any );
} }
public TypeFilter( Set types ){ public TypeFilter( Set types ){
@ -35,15 +34,15 @@ public class TypeFilter {
public TypeFilter( LookupKind kind ){ public TypeFilter( LookupKind kind ){
acceptedKinds.add( kind ); acceptedKinds.add( kind );
populatedFilteredTypes( kind ); populatedAcceptedTypes( kind );
} }
public void addFilteredType( TypeInfo.eType type ){ public void addAcceptedType( TypeInfo.eType type ){
acceptedTypes.add( type ); acceptedTypes.add( type );
} }
public void addFilteredType( LookupKind kind ) { public void addAcceptedType( LookupKind kind ) {
populatedFilteredTypes( kind ); populatedAcceptedTypes( kind );
acceptedKinds.add( kind ); acceptedKinds.add( kind );
} }
@ -95,7 +94,7 @@ public class TypeFilter {
/** /**
* @param lookupKind * @param lookupKind
*/ */
private void populatedFilteredTypes(LookupKind kind) { private void populatedAcceptedTypes(LookupKind kind) {
if ( kind == LookupKind.ALL ) { acceptedTypes.add( TypeInfo.t_any ); } if ( kind == LookupKind.ALL ) { acceptedTypes.add( TypeInfo.t_any ); }
else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class ); else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class );
acceptedTypes.add( TypeInfo.t_struct ); acceptedTypes.add( TypeInfo.t_struct );