1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-15 04:55:22 +02:00

bug 60298 - fix prefix lookup of constructors

This commit is contained in:
Andrew Niefer 2004-05-05 19:06:01 +00:00
parent dc6207ddf8
commit e86d9d4a94
4 changed files with 33 additions and 1 deletions

View file

@ -981,5 +981,19 @@ public class CompletionParseTest extends CompletionParseBaseTest {
assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 );
}
}
public void testConstructors() throws Exception
{
String code = "class Foo{ public: Foo(); }; Foo::SP ";
IASTCompletionNode node = parse( code, code.indexOf( "SP" ) );
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.CONSTRUCTORS },
node.getCompletionContext() );
assertEquals( result.getResultsSize(), 1 );
IASTMethod constructor = (IASTMethod) result.getNodes().next();
assertEquals( constructor.getName(), "Foo" );
}
}

View file

@ -82,6 +82,7 @@ public class ASTNode implements IASTNode {
s.getASTExtension().getPrimaryDeclaration() == null )
{
iter.remove();
continue;
}
if( context != null && ((ASTNode)context).shouldFilterLookupResult( s ) )

View file

@ -816,8 +816,17 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
ParserSymbolTable.lookup( data, this );
List constructors = null;
if( filter != null && filter.willAccept( TypeInfo.t_constructor ) && (this instanceof IDerivableContainerSymbol) ){
if( getName().startsWith( prefix ) )
constructors = ((IDerivableContainerSymbol)this).getConstructors();
}
if( data.foundItems == null || data.foundItems.isEmpty() ){
return null;
if( constructors != null )
return new LinkedList( constructors );
else
return null;
} else {
//remove any ambiguous symbols
if( data.ambiguities != null && !data.ambiguities.isEmpty() ){
@ -840,6 +849,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
list.add( obj );
}
}
if( constructors != null )
list.addAll( constructors );
return list;
}

View file

@ -46,6 +46,11 @@ public class TypeFilter {
acceptedKinds.add( kind );
}
public boolean willAccept( TypeInfo.eType type ){
return( acceptedTypes.contains( TypeInfo.t_any ) ||
acceptedTypes.contains( type ) );
}
public boolean shouldAccept( ISymbol symbol ){
return shouldAccept( symbol, symbol.getTypeInfo() );
}