mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-17 22:15:23 +02:00
bug 60298 - fix prefix lookup of constructors
This commit is contained in:
parent
dc6207ddf8
commit
e86d9d4a94
4 changed files with 33 additions and 1 deletions
|
@ -982,4 +982,18 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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" );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ public class ASTNode implements IASTNode {
|
||||||
s.getASTExtension().getPrimaryDeclaration() == null )
|
s.getASTExtension().getPrimaryDeclaration() == null )
|
||||||
{
|
{
|
||||||
iter.remove();
|
iter.remove();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( context != null && ((ASTNode)context).shouldFilterLookupResult( s ) )
|
if( context != null && ((ASTNode)context).shouldFilterLookupResult( s ) )
|
||||||
|
|
|
@ -816,7 +816,16 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
|
|
||||||
ParserSymbolTable.lookup( data, this );
|
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() ){
|
if( data.foundItems == null || data.foundItems.isEmpty() ){
|
||||||
|
if( constructors != null )
|
||||||
|
return new LinkedList( constructors );
|
||||||
|
else
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
//remove any ambiguous symbols
|
//remove any ambiguous symbols
|
||||||
|
@ -841,6 +850,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( constructors != null )
|
||||||
|
list.addAll( constructors );
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,11 @@ public class TypeFilter {
|
||||||
acceptedKinds.add( kind );
|
acceptedKinds.add( kind );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean willAccept( TypeInfo.eType type ){
|
||||||
|
return( acceptedTypes.contains( TypeInfo.t_any ) ||
|
||||||
|
acceptedTypes.contains( type ) );
|
||||||
|
}
|
||||||
|
|
||||||
public boolean shouldAccept( ISymbol symbol ){
|
public boolean shouldAccept( ISymbol symbol ){
|
||||||
return shouldAccept( symbol, symbol.getTypeInfo() );
|
return shouldAccept( symbol, symbol.getTypeInfo() );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue