mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-14 19:55:45 +02:00
fixing bugs 50807 and 50808, content assist in functions: foo( []
This commit is contained in:
parent
caa5d189ab
commit
5d46138a5d
21 changed files with 434 additions and 156 deletions
|
@ -44,6 +44,7 @@ import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumeratorReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
|
@ -125,7 +126,7 @@ public class CompleteParseBaseTest extends TestCase
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind, org.eclipse.cdt.core.parser.ast.IASTNode)
|
||||
*/
|
||||
public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context) {
|
||||
public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.ALL;
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null );
|
||||
assertEquals( result.getPrefix(), prefix );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -170,7 +170,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.ALL;
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null );
|
||||
assertEquals( result.getPrefix(), prefix );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -276,7 +276,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.METHODS;
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext(), null );
|
||||
assertEquals( result.getPrefix(), prefix );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -320,7 +320,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertNotNull( node.getCompletionContext() );
|
||||
assertTrue( node.getCompletionContext() instanceof IASTVariable );
|
||||
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext(), null );
|
||||
assertEquals( result.getPrefix(), prefix );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -362,7 +362,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertNotNull( node.getCompletionContext() );
|
||||
assertTrue( node.getCompletionContext() instanceof IASTVariable );
|
||||
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.METHODS }, node.getCompletionContext(), null );
|
||||
assertEquals( result.getPrefix(), prefix );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -398,7 +398,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE );
|
||||
assertNull( node.getCompletionContext() );
|
||||
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.LOCAL_VARIABLES }, node.getCompletionContext() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( prefix, new IASTNode.LookupKind [] { IASTNode.LookupKind.LOCAL_VARIABLES }, node.getCompletionContext(), null );
|
||||
assertEquals( result.getPrefix(), prefix );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -442,7 +442,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
assertEquals( result.getResultsSize(), 2 );
|
||||
|
||||
|
@ -455,7 +455,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS, IASTNode.LookupKind.METHODS },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
iter = result.getNodes();
|
||||
|
@ -493,7 +493,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
LookupKind[] kinds = new LookupKind[ 1 ];
|
||||
kinds[0] = LookupKind.FIELDS;
|
||||
|
||||
ILookupResult result = inquestion.lookup( "a", kinds, null ); //$NON-NLS-1$
|
||||
ILookupResult result = inquestion.lookup( "a", kinds, null, null ); //$NON-NLS-1$
|
||||
assertEquals(result.getResultsSize(), 3 );
|
||||
}
|
||||
|
||||
|
@ -526,7 +526,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
LookupKind[] kinds = new LookupKind[ 1 ];
|
||||
kinds[0] = LookupKind.FIELDS;
|
||||
|
||||
ILookupResult result = inquestion.lookup( "a", kinds, null ); //$NON-NLS-1$
|
||||
ILookupResult result = inquestion.lookup( "a", kinds, null, null ); //$NON-NLS-1$
|
||||
assertEquals(result.getResultsSize(), 3 );
|
||||
}
|
||||
|
||||
|
@ -547,7 +547,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
IASTField field = (IASTField) result.getNodes().next();
|
||||
|
@ -571,7 +571,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
IASTField field = (IASTField) result.getNodes().next();
|
||||
|
@ -596,7 +596,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.THIS },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
assertEquals( result.getResultsSize(), 4 );
|
||||
|
||||
|
@ -626,7 +626,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
IASTCompletionNode node = parse( code, index );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.TYPEDEFS },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
|
||||
|
@ -657,7 +657,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
Set results = new HashSet();
|
||||
results.add( "aInteger"); //$NON-NLS-1$
|
||||
|
@ -701,7 +701,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
|
||||
Set results = new HashSet();
|
||||
results.add( "DEF"); //$NON-NLS-1$
|
||||
|
@ -726,7 +726,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( "", //$NON-NLS-1$
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 2 );
|
||||
|
||||
Iterator i = result.getNodes();
|
||||
|
@ -761,7 +761,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertEquals( node.getCompletionKind(), CompletionKind.MEMBER_REFERENCE );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
Iterator i = result.getNodes();
|
||||
IASTMethod doorBell = (IASTMethod) i.next();
|
||||
|
@ -786,7 +786,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[] {IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 3 );
|
||||
Iterator i = result.getNodes();
|
||||
assertTrue( i.next() instanceof IASTField );
|
||||
|
@ -828,7 +828,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
IASTCompletionNode node = parse( code, index );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
|
||||
Iterator iter = result.getNodes();
|
||||
|
@ -878,35 +878,35 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertNotNull( node );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 2 );
|
||||
|
||||
node = parse( code + "a2-> ", code.length() + 4 ); //$NON-NLS-1$
|
||||
assertNotNull( node );
|
||||
result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
|
||||
node = parse( code + "a3-> ", code.length() + 4 ); //$NON-NLS-1$
|
||||
assertNotNull( node );
|
||||
result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 2 );
|
||||
|
||||
node = parse( code + "a4-> ", code.length() + 4 ); //$NON-NLS-1$
|
||||
assertNotNull( node );
|
||||
result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 2 );
|
||||
|
||||
node = parse( code + "a5-> ", code.length() + 4 ); //$NON-NLS-1$
|
||||
assertNotNull( node );
|
||||
result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 4 );
|
||||
}
|
||||
|
||||
|
@ -928,7 +928,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
IASTCompletionNode node = parse( code, index );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.ALL },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
}
|
||||
|
||||
|
@ -950,7 +950,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertNotNull( node.getFunctionParameters() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertNotNull(result);
|
||||
assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 );
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
assertNotNull( node.getFunctionParameters() );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.LOCAL_VARIABLES },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertNotNull(result);
|
||||
assertEquals( result.getResultsSize(), ( i == 0 ) ? 2 : 1 );
|
||||
}
|
||||
|
@ -990,10 +990,40 @@ public class CompletionParseTest extends CompletionParseBaseTest {
|
|||
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.CONSTRUCTORS },
|
||||
node.getCompletionContext() );
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 1 );
|
||||
IASTMethod constructor = (IASTMethod) result.getNodes().next();
|
||||
assertEquals( constructor.getName(), "Foo" );
|
||||
}
|
||||
|
||||
public void testBug50807() throws Exception
|
||||
{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "void foo();" );
|
||||
writer.write( "void foo( int );" );
|
||||
writer.write( "void foo( int, char );" );
|
||||
writer.write( "void foo( int, int, int );" );
|
||||
writer.write( "void bar(){ " );
|
||||
|
||||
String code = writer.toString() + "foo( SP";
|
||||
IASTCompletionNode node = parse( code, code.indexOf( "SP" ) );
|
||||
|
||||
assertEquals( node.getCompletionPrefix(), "" );
|
||||
assertEquals( node.getFunctionName(), "foo" );
|
||||
ILookupResult result = node.getCompletionScope().lookup( node.getFunctionName(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS },
|
||||
node.getCompletionContext(), null );
|
||||
assertEquals( result.getResultsSize(), 4 );
|
||||
|
||||
code = writer.toString() + "foo( 1, SP";
|
||||
node = parse( code, code.indexOf( "SP" ) );
|
||||
|
||||
assertEquals( node.getCompletionPrefix(), "" );
|
||||
assertEquals( node.getFunctionName(), "foo" );
|
||||
result = node.getCompletionScope().lookup( node.getFunctionName(),
|
||||
new IASTNode.LookupKind[]{ IASTNode.LookupKind.FUNCTIONS },
|
||||
node.getCompletionContext(), node.getFunctionParameters() );
|
||||
|
||||
assertEquals( result.getResultsSize(), 2 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2652,7 +2652,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
ISymbol anotherVar = table.newSymbol( "anotherVar", TypeInfo.t_int );
|
||||
foo.addSymbol( anotherVar );
|
||||
|
||||
List results = foo.prefixLookup( null, "a", false );
|
||||
List results = foo.prefixLookup( null, "a", false, null );
|
||||
assertTrue( results != null );
|
||||
assertEquals( results.size(), 2 );
|
||||
|
||||
|
@ -2686,7 +2686,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
D.addSymbol( aField );
|
||||
D.addSymbol( aMethod );
|
||||
|
||||
List results = D.prefixLookup( null, "a", true );
|
||||
List results = D.prefixLookup( null, "a", true, null );
|
||||
|
||||
assertTrue( results != null );
|
||||
assertEquals( results.size(), 2 );
|
||||
|
@ -2738,7 +2738,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
B.addSymbol( af2 );
|
||||
|
||||
|
||||
List results = B.prefixLookup( null, "a", true );
|
||||
List results = B.prefixLookup( null, "a", true, null );
|
||||
|
||||
assertTrue( results != null );
|
||||
assertEquals( results.size(), 3 );
|
||||
|
@ -2803,7 +2803,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
f.addUsingDirective( V );
|
||||
f.addUsingDirective( W );
|
||||
|
||||
List results = f.prefixLookup( null, "a", false );
|
||||
List results = f.prefixLookup( null, "a", false, null );
|
||||
|
||||
assertTrue( results != null );
|
||||
assertEquals( results.size(), 1 );
|
||||
|
@ -2946,7 +2946,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
ISymbol aLocal = table.newSymbol( "aLocal", TypeInfo.t_int );
|
||||
f.addSymbol( aLocal );
|
||||
|
||||
List results = f.prefixLookup( new TypeFilter( LookupKind.STRUCTURES ), "A", false );
|
||||
List results = f.prefixLookup( new TypeFilter( LookupKind.STRUCTURES ), "A", false, null );
|
||||
|
||||
assertEquals( results.size(), 3 );
|
||||
|
||||
|
@ -2954,7 +2954,7 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
assertTrue( results.contains( A2 ) );
|
||||
assertTrue( results.contains( a3 ) );
|
||||
|
||||
results = f.prefixLookup( null, "a", false );
|
||||
results = f.prefixLookup( null, "a", false, null );
|
||||
assertEquals( results.size(), 7 );
|
||||
assertTrue( results.contains( aF ) );
|
||||
assertTrue( results.contains( A2 ) );
|
||||
|
@ -2964,23 +2964,23 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
assertTrue( results.contains( aa ) );
|
||||
assertTrue( results.contains( aLocal ) );
|
||||
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.FUNCTIONS ), "a", false );
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.FUNCTIONS ), "a", false, null );
|
||||
assertEquals( results.size(), 1 );
|
||||
assertTrue( results.contains( aFoo ) );
|
||||
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.METHODS ), "a", false );
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.METHODS ), "a", false, null );
|
||||
assertEquals( results.size(), 1 );
|
||||
assertTrue( results.contains( aF ) );
|
||||
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.LOCAL_VARIABLES ), "a", false );
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.LOCAL_VARIABLES ), "a", false, null );
|
||||
assertEquals( results.size(), 1 );
|
||||
assertTrue( results.contains( aLocal ) );
|
||||
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.VARIABLES ), "a", false );
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.VARIABLES ), "a", false, null );
|
||||
assertEquals( results.size(), 1 );
|
||||
assertTrue( results.contains( aa ) );
|
||||
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.FIELDS), "a", false );
|
||||
results = f.prefixLookup( new TypeFilter( LookupKind.FIELDS), "a", false, null );
|
||||
assertEquals( results.size(), 1 );
|
||||
assertTrue( results.contains( a3_int ) );
|
||||
}
|
||||
|
|
|
@ -58,15 +58,17 @@ public interface IASTNode {
|
|||
public String getPrefix();
|
||||
public Iterator getNodes();
|
||||
public int getResultsSize();
|
||||
public int getIndexOfNextParameter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param prefix
|
||||
* @param kind
|
||||
* @param context
|
||||
* @param functionParameters
|
||||
* @return
|
||||
* @throws LookupError
|
||||
*/
|
||||
public ILookupResult lookup( String prefix, LookupKind[] kind, IASTNode context) throws LookupError, ASTNotImplementedException;
|
||||
public ILookupResult lookup( String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,19 +217,19 @@ public class ASTMethod extends ASTFunction implements IASTMethod
|
|||
* @param prefix
|
||||
* @param thisContainer
|
||||
* @param qualification
|
||||
* @param lookInThis
|
||||
* @param filter
|
||||
* @param lookInThis
|
||||
* @param lookupResults
|
||||
* @return
|
||||
* @throws LookupError
|
||||
*/
|
||||
protected List performPrefixLookup(String prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter) throws LookupError {
|
||||
protected List performPrefixLookup(String prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter, List paramList) throws LookupError {
|
||||
if( filter.isLookingInThis() ){
|
||||
try{
|
||||
ISymbol thisPointer = thisContainer.lookup( ParserSymbolTable.THIS );
|
||||
ISymbol thisClass = ( thisPointer != null ) ? thisPointer.getTypeSymbol() : null;
|
||||
if( thisClass != null && thisClass instanceof IContainerSymbol ){
|
||||
return ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true );
|
||||
return ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true, paramList );
|
||||
}
|
||||
} catch (ParserSymbolTableException e) {
|
||||
throw new LookupError();
|
||||
|
@ -237,7 +237,7 @@ public class ASTMethod extends ASTFunction implements IASTMethod
|
|||
throw new LookupError();
|
||||
}
|
||||
} else {
|
||||
return super.performPrefixLookup( prefix, thisContainer, qualification, filter );
|
||||
return super.performPrefixLookup( prefix, thisContainer, qualification, filter, paramList );
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -11,11 +11,13 @@
|
|||
package org.eclipse.cdt.internal.core.parser.ast.complete;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator;
|
||||
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
||||
|
@ -34,7 +36,7 @@ public class ASTNode implements IASTNode {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind, org.eclipse.cdt.core.parser.ast.IASTNode)
|
||||
*/
|
||||
public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context) throws LookupError, ASTNotImplementedException {
|
||||
public ILookupResult lookup(String prefix, LookupKind[] kind, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException {
|
||||
|
||||
if( ! ( this instanceof ISymbolOwner ) ){
|
||||
return null;
|
||||
|
@ -47,6 +49,10 @@ public class ASTNode implements IASTNode {
|
|||
IContainerSymbol thisContainer = (IContainerSymbol) symbol;
|
||||
IContainerSymbol qualification = ( context != null ) ? ((ASTNode)context).getLookupQualificationSymbol() : null;
|
||||
|
||||
List parameters = createLookupParameterList( functionParameters );
|
||||
|
||||
int paramIndex = ( parameters != null ) ? parameters.size() : 0;
|
||||
|
||||
if( thisContainer.getSymbolTable().getParserMode() != ParserMode.COMPLETION_PARSE ){
|
||||
throw new ASTNotImplementedException();
|
||||
}
|
||||
|
@ -68,7 +74,7 @@ public class ASTNode implements IASTNode {
|
|||
filter.addAcceptedType( LookupKind.ALL );
|
||||
}
|
||||
|
||||
List lookupResults = performPrefixLookup(prefix, thisContainer, qualification, filter);
|
||||
List lookupResults = performPrefixLookup(prefix, thisContainer, qualification, filter, parameters);
|
||||
|
||||
if(lookupResults == null)
|
||||
return null;
|
||||
|
@ -91,26 +97,27 @@ public class ASTNode implements IASTNode {
|
|||
|
||||
SymbolIterator iterator = new SymbolIterator( lookupResults.iterator() );
|
||||
|
||||
return new Result( prefix, iterator, lookupResults.size() );
|
||||
return new Result( prefix, iterator, lookupResults.size(), paramIndex );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param prefix
|
||||
* @param thisContainer
|
||||
* @param qualification
|
||||
* @param lookInThis
|
||||
* @param filter
|
||||
* @param paramList TODO
|
||||
* @param lookInThis
|
||||
* @param lookupResults
|
||||
* @return
|
||||
* @throws LookupError
|
||||
*/
|
||||
protected List performPrefixLookup(String prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter) throws LookupError {
|
||||
protected List performPrefixLookup(String prefix, IContainerSymbol thisContainer, IContainerSymbol qualification, TypeFilter filter, List paramList) throws LookupError {
|
||||
List results = null;
|
||||
try {
|
||||
if( qualification != null ){
|
||||
results = qualification.prefixLookup( filter, prefix, true );
|
||||
results = qualification.prefixLookup( filter, prefix, true, paramList );
|
||||
} else {
|
||||
results = thisContainer.prefixLookup( filter, prefix, false );
|
||||
results = thisContainer.prefixLookup( filter, prefix, false, paramList );
|
||||
}
|
||||
} catch (ParserSymbolTableException e) {
|
||||
throw new LookupError();
|
||||
|
@ -134,20 +141,35 @@ public class ASTNode implements IASTNode {
|
|||
return false;
|
||||
}
|
||||
|
||||
public List createLookupParameterList( IASTExpression parameterExpression ){
|
||||
if( parameterExpression == null )
|
||||
return null;
|
||||
|
||||
List params = new LinkedList();
|
||||
ASTExpression exp = (ASTExpression) parameterExpression;
|
||||
while( exp != null ){
|
||||
params.add( exp.getResultType().getResult() );
|
||||
exp = (ASTExpression) exp.getRHSExpression();
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
private class Result implements ILookupResult{
|
||||
private String prefix;
|
||||
private Iterator iterator;
|
||||
private int resultsNumber;
|
||||
private int parameterIndex;
|
||||
|
||||
public Result( String pref, Iterator iter, int resultsSize ){
|
||||
public Result( String pref, Iterator iter, int resultsSize, int paramIndex ){
|
||||
prefix = pref;
|
||||
iterator = iter;
|
||||
resultsNumber = resultsSize;
|
||||
|
||||
parameterIndex = paramIndex;
|
||||
}
|
||||
|
||||
public String getPrefix() { return prefix; }
|
||||
public Iterator getNodes() { return iterator; }
|
||||
public int getResultsSize() { return resultsNumber; }
|
||||
public int getResultsSize() { return resultsNumber; }
|
||||
public int getIndexOfNextParameter() { return parameterIndex; }
|
||||
}
|
||||
}
|
|
@ -206,7 +206,7 @@ public class ASTExpression implements IASTExpression {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind[], org.eclipse.cdt.core.parser.ast.IASTNode)
|
||||
*/
|
||||
public ILookupResult lookup(String prefix, LookupKind[] k, IASTNode context) throws LookupError, ASTNotImplementedException {
|
||||
public ILookupResult lookup(String prefix, LookupKind[] k, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException {
|
||||
// Not provided in this mode
|
||||
throw new ASTNotImplementedException();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.parser.ast.quick;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +23,7 @@ public class ASTNode implements IASTNode {
|
|||
public ILookupResult lookup(
|
||||
String prefix,
|
||||
LookupKind[] kind,
|
||||
IASTNode context) {
|
||||
IASTNode context, IASTExpression functionParameters) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.ast.quick;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScopedTypeSpecifier;
|
||||
|
@ -41,7 +42,7 @@ public class ASTScopedTypeSpecifier extends ASTQualifiedNamedElement implements
|
|||
public ILookupResult lookup(
|
||||
String prefix,
|
||||
LookupKind[] kind,
|
||||
IASTNode context) {
|
||||
IASTNode context, IASTExpression functionParameters) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
|
||||
|
@ -106,7 +107,7 @@ public class ASTTemplateParameter implements IASTTemplateParameter, IASTOffsetab
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind[], org.eclipse.cdt.core.parser.ast.IASTNode)
|
||||
*/
|
||||
public ILookupResult lookup(String prefix, LookupKind[] lookupKind, IASTNode context) throws LookupError, ASTNotImplementedException {
|
||||
public ILookupResult lookup(String prefix, LookupKind[] lookupKind, IASTNode context, IASTExpression functionParameters) throws LookupError, ASTNotImplementedException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -809,23 +809,29 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
return null;
|
||||
}
|
||||
|
||||
public List prefixLookup( TypeFilter filter, String prefix, boolean qualified ) throws ParserSymbolTableException{
|
||||
public List prefixLookup( TypeFilter filter, String prefix, boolean qualified, List paramList ) throws ParserSymbolTableException{
|
||||
LookupData data = new LookupData( prefix, filter );
|
||||
data.qualified = qualified;
|
||||
data.mode = ParserSymbolTable.LookupMode.PREFIX;
|
||||
data.parameters = paramList;
|
||||
|
||||
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();
|
||||
constructors = new LinkedList( ((IDerivableContainerSymbol)this).getConstructors() );
|
||||
}
|
||||
|
||||
if( data.foundItems == null || data.foundItems.isEmpty() ){
|
||||
if( constructors != null )
|
||||
return new LinkedList( constructors );
|
||||
else
|
||||
if( constructors != null ){
|
||||
if( paramList != null ){
|
||||
ParserSymbolTable.resolveFunction( data, constructors );
|
||||
return constructors;
|
||||
} else {
|
||||
return constructors;
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
} else {
|
||||
//remove any ambiguous symbols
|
||||
|
@ -840,13 +846,28 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
|
||||
Iterator iter = data.foundItems.keySet().iterator();
|
||||
Object obj = null;
|
||||
List tempList = null;
|
||||
while( iter.hasNext() ){
|
||||
obj = data.foundItems.get( iter.next() );
|
||||
|
||||
if( obj instanceof List ){
|
||||
//a list must be all functions?
|
||||
if( paramList != null )
|
||||
ParserSymbolTable.resolveFunction( data, (List) obj );
|
||||
list.addAll( (List) obj );
|
||||
} else{
|
||||
list.add( obj );
|
||||
if( paramList != null && ((ISymbol)obj).isType( TypeInfo.t_function ) )
|
||||
{
|
||||
if( tempList == null )
|
||||
tempList = new LinkedList();
|
||||
else
|
||||
tempList.clear();
|
||||
tempList.add( obj );
|
||||
ParserSymbolTable.resolveFunction( data, tempList );
|
||||
list.addAll( tempList );
|
||||
} else {
|
||||
list.add( obj );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,13 +80,14 @@ public interface IContainerSymbol extends ISymbol {
|
|||
* @param filter
|
||||
* @param prefix
|
||||
* @param qualified
|
||||
* @param paramList TODO
|
||||
* @return
|
||||
* @throws ParserSymbolTableException
|
||||
* Reason: r_BadTypeInfo if during lookup, we come across a class inheriting from a symbol which is not an
|
||||
* IDerivableContainerSymbol
|
||||
* r_CircularInheritance if during lookup, we come across a class with a circular inheritance tree
|
||||
*/
|
||||
public List prefixLookup( TypeFilter filter, String prefix, boolean qualified ) throws ParserSymbolTableException;
|
||||
public List prefixLookup( TypeFilter filter, String prefix, boolean qualified, List paramList ) throws ParserSymbolTableException;
|
||||
|
||||
/**
|
||||
* Lookups
|
||||
|
|
|
@ -989,6 +989,7 @@ public class ParserSymbolTable {
|
|||
return null;
|
||||
}
|
||||
|
||||
//reduce our set of candidate functions to only those who have the right number of parameters
|
||||
reduceToViable( data, functions );
|
||||
|
||||
if( data.exactFunctionsOnly && data.templateParameters == null ){
|
||||
|
@ -1027,31 +1028,32 @@ public class ParserSymbolTable {
|
|||
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
|
||||
}
|
||||
|
||||
IParameterizedSymbol bestFn = null; //the best function
|
||||
IParameterizedSymbol currFn = null; //the function currently under consideration
|
||||
IParameterizedSymbol bestFn = null; //the best function
|
||||
IParameterizedSymbol currFn = null; //the function currently under consideration
|
||||
Cost [] bestFnCost = null; //the cost of the best function
|
||||
Cost [] currFnCost = null; //the cost for the current function
|
||||
|
||||
Iterator iterFns = functions.iterator();
|
||||
Iterator sourceParams = null;
|
||||
Iterator targetParams = null;
|
||||
Iterator sourceParams = null; //the parameters the function is being called with
|
||||
Iterator targetParams = null; //the current function's parameters
|
||||
|
||||
TypeInfo source = null; //parameter we are called with
|
||||
TypeInfo target = null; //function's parameter
|
||||
|
||||
int comparison;
|
||||
Cost cost = null;
|
||||
Cost temp = null;
|
||||
|
||||
TypeInfo source = null;
|
||||
TypeInfo target = null;
|
||||
|
||||
boolean hasWorse = false;
|
||||
boolean hasBetter = false;
|
||||
boolean ambiguous = false;
|
||||
boolean currHasAmbiguousParam = false;
|
||||
boolean bestHasAmbiguousParam = false;
|
||||
Cost cost = null; //the cost of converting source to target
|
||||
Cost temp = null; //the cost of using a user defined conversion to convert source to target
|
||||
|
||||
boolean hasWorse = false; //currFn has a worse parameter fit than bestFn
|
||||
boolean hasBetter = false; //currFn has a better parameter fit than bestFn
|
||||
boolean ambiguous = false; //ambiguity, 2 functions are equally good
|
||||
boolean currHasAmbiguousParam = false; //currFn has an ambiguous parameter conversion (ok if not bestFn)
|
||||
boolean bestHasAmbiguousParam = false; //bestFn has an ambiguous parameter conversion (not ok, ambiguous)
|
||||
|
||||
List parameters = null;
|
||||
|
||||
if( numSourceParams == 0 ){
|
||||
//f() is the same as f( void )
|
||||
parameters = new LinkedList();
|
||||
parameters.add( new TypeInfo( TypeInfo.t_void, 0, null ) );
|
||||
numSourceParams = 1;
|
||||
|
@ -1136,6 +1138,12 @@ public class ParserSymbolTable {
|
|||
if( currFnCost[ j ].rank < 0 ){
|
||||
hasWorse = true;
|
||||
hasBetter = false;
|
||||
|
||||
if( data.mode == LookupMode.PREFIX ){
|
||||
//for prefix lookup, just remove from the function list those functions
|
||||
//that don't fit the parameters
|
||||
iterFns.remove();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1152,6 +1160,10 @@ public class ParserSymbolTable {
|
|||
}
|
||||
}
|
||||
|
||||
//during a prefix lookup, we don't need to rank the functions
|
||||
if( data.mode == LookupMode.PREFIX )
|
||||
continue;
|
||||
|
||||
//If function has a parameter match that is better than the current best,
|
||||
//and another that is worse (or everything was just as good, neither better nor worse).
|
||||
//then this is an ambiguity (unless we find something better than both later)
|
||||
|
@ -1225,11 +1237,30 @@ public class ParserSymbolTable {
|
|||
int numParameters = ( data.parameters == null ) ? 0 : data.parameters.size();
|
||||
int num;
|
||||
|
||||
if( data.mode == LookupMode.PREFIX )
|
||||
{
|
||||
if( numParameters >= 1 )
|
||||
numParameters++;
|
||||
}
|
||||
|
||||
//Trim the list down to the set of viable functions
|
||||
IParameterizedSymbol function;
|
||||
Iterator iter = functions.iterator();
|
||||
Object obj = null;
|
||||
while( iter.hasNext() ){
|
||||
function = (IParameterizedSymbol) iter.next();
|
||||
obj = iter.next();
|
||||
//sanity check
|
||||
if( obj instanceof IParameterizedSymbol ){
|
||||
function = (IParameterizedSymbol) obj;
|
||||
if( !function.isType( TypeInfo.t_function) && !function.isType( TypeInfo.t_constructor ) ){
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
num = ( function.getParameterList() == null ) ? 0 : function.getParameterList().size();
|
||||
|
||||
//if there are m arguments in the list, all candidate functions having m parameters
|
||||
|
@ -1265,6 +1296,10 @@ public class ParserSymbolTable {
|
|||
//a candidate function having more than m parameters is viable only if the (m+1)-st
|
||||
//parameter has a default argument
|
||||
else {
|
||||
if( data.mode == LookupMode.PREFIX ){
|
||||
//during prefix lookup, having more parameters than what is provided is ok
|
||||
continue;
|
||||
}
|
||||
ListIterator listIter = function.getParameterList().listIterator( num );
|
||||
TypeInfo param;
|
||||
for( int i = num; i > ( numParameters - num + 1); i-- ){
|
||||
|
|
|
@ -588,7 +588,7 @@ public class TemplateFactory extends ExtensibleSymbol implements ITemplateFactor
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#prefixLookup(org.eclipse.cdt.internal.core.parser.pst.TypeFilter, java.lang.String, boolean)
|
||||
*/
|
||||
public List prefixLookup(TypeFilter filter, String prefix, boolean qualified) throws ParserSymbolTableException {
|
||||
public List prefixLookup(TypeFilter filter, String prefix, boolean qualified, List paramList) throws ParserSymbolTableException {
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
2004-05-07 Andrew Niefer
|
||||
- handle content assist for function references so that the function is not inserted if we are just getting signature
|
||||
info for the popup
|
||||
- created CProposalContextInformation which implements IContextInformation and IContextInformationExtension
|
||||
so that we can better place the context popup after content assist for functions
|
||||
|
||||
* src/org/eclipse/cdt/internal/ui/text/contentassist/CProposalContextInformation.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/contentassist/ResultCollector.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/contentassist/ICompletionRequestor.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionRequestorAdaptor.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java
|
||||
* src/org/eclipse/cdt/internal/ui/text/contentassist/CCompletionProcessor.java
|
||||
|
||||
2004-05-05 Bogdan Gheorghe
|
||||
Moved the index enablement constants to IndexManager to allow the index manager
|
||||
to load enablement settings if not done so by the property page
|
||||
|
|
|
@ -622,7 +622,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
visibility,
|
||||
completionStart,
|
||||
completionLength,
|
||||
relevance);
|
||||
relevance, true, completionStart);
|
||||
break;
|
||||
case ICElement.C_FUNCTION:
|
||||
case ICElement.C_FUNCTION_DECLARATION:
|
||||
|
@ -632,7 +632,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
match.getReturnType(),
|
||||
completionStart,
|
||||
completionLength,
|
||||
relevance);
|
||||
relevance, true, completionStart);
|
||||
break;
|
||||
case ICElement.C_CLASS:
|
||||
resultCollector.acceptClass(
|
||||
|
@ -667,7 +667,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
|||
match.getName(),
|
||||
completionStart,
|
||||
completionLength,
|
||||
relevance);
|
||||
relevance, completionStart);
|
||||
break;
|
||||
case ICElement.C_ENUMERATION:
|
||||
resultCollector.acceptEnumeration(
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on May 6, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||
|
||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||
import org.eclipse.jface.text.contentassist.IContextInformationExtension;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*/
|
||||
public class CProposalContextInformation implements IContextInformation, IContextInformationExtension {
|
||||
/** The name of the context */
|
||||
private String fContextDisplayString;
|
||||
/** The information to be displayed */
|
||||
private String fInformationDisplayString;
|
||||
/** The position to display the information */
|
||||
private int fInformationPosition;
|
||||
/** The image to be displayed */
|
||||
private Image fImage;
|
||||
|
||||
/**
|
||||
* Creates a new context information without an image.
|
||||
*
|
||||
* @param contextDisplayString the string to be used when presenting the context
|
||||
* @param informationDisplayString the string to be displayed when presenting the context information
|
||||
*/
|
||||
public CProposalContextInformation(String contextDisplayString, String informationDisplayString) {
|
||||
this(null, contextDisplayString, informationDisplayString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new context information with an image.
|
||||
*
|
||||
* @param image the image to display when presenting the context information
|
||||
* @param contextDisplayString the string to be used when presenting the context
|
||||
* @param informationDisplayString the string to be displayed when presenting the context information,
|
||||
* may not be <code>null</code>
|
||||
*/
|
||||
public CProposalContextInformation(Image image, String contextDisplayString, String informationDisplayString) {
|
||||
//Assert.isNotNull(informationDisplayString);
|
||||
fImage= image;
|
||||
fContextDisplayString= contextDisplayString;
|
||||
fInformationDisplayString= informationDisplayString;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IContextInformation#equals(Object)
|
||||
*/
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof IContextInformation) {
|
||||
IContextInformation contextInformation= (IContextInformation) object;
|
||||
boolean equals= fInformationDisplayString.equalsIgnoreCase(contextInformation.getInformationDisplayString());
|
||||
if (fContextDisplayString != null)
|
||||
equals= equals && fContextDisplayString.equalsIgnoreCase(contextInformation.getContextDisplayString());
|
||||
return equals;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IContextInformation#getInformationDisplayString()
|
||||
*/
|
||||
public String getInformationDisplayString() {
|
||||
return fInformationDisplayString;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IContextInformation#getImage()
|
||||
*/
|
||||
public Image getImage() {
|
||||
return fImage;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IContextInformation#getContextDisplayString()
|
||||
*/
|
||||
public String getContextDisplayString() {
|
||||
if (fContextDisplayString != null)
|
||||
return fContextDisplayString;
|
||||
return fInformationDisplayString;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.jface.text.contentassist.IContextInformationExtension#getContextInformationPosition()
|
||||
*/
|
||||
public int getContextInformationPosition() {
|
||||
return fInformationPosition;
|
||||
}
|
||||
|
||||
public void setContextInformationPosition( int pos ){
|
||||
fInformationPosition = pos;
|
||||
}
|
||||
}
|
|
@ -45,6 +45,7 @@ import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
|
@ -79,6 +80,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
ICompletionRequestor requestor;
|
||||
int completionStart = 0;
|
||||
int completionLength = 0;
|
||||
int completionOrigin = 0;
|
||||
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
|
||||
private Map macroMap = null;
|
||||
private ContentAssistElementRequestor elementRequestor = null;
|
||||
|
@ -178,8 +180,8 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
IASTCompletionNode result = null;
|
||||
try {
|
||||
// set timeout
|
||||
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
|
||||
int timeout = store.getInt(ContentAssistPreference.TIMEOUT_DELAY);
|
||||
IPreferenceStore prefStore = CUIPlugin.getDefault().getPreferenceStore();
|
||||
int timeout = prefStore.getInt(ContentAssistPreference.TIMEOUT_DELAY);
|
||||
elementRequestor.setTimeout(timeout);
|
||||
|
||||
// start timer
|
||||
|
@ -205,7 +207,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
}
|
||||
}
|
||||
|
||||
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly){
|
||||
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly, int parameterIndex){
|
||||
if(node instanceof IASTField){
|
||||
IASTField field = (IASTField)node;
|
||||
if(addStaticFieldsOnly && (!field.isStatic()))
|
||||
|
@ -255,10 +257,20 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
int relevance = computeRelevance(ICElement.C_METHOD, prefix, method.getName());
|
||||
|
||||
String parameterString = ASTUtil.getParametersString(ASTUtil.getFunctionParameterTypes(method));
|
||||
|
||||
int contextInfoOffset = completionOrigin;
|
||||
if( parameterIndex > -1 && parameterString.length() > 0){
|
||||
int idx = 0;
|
||||
for( int i = 0; i < parameterIndex; i++ ){
|
||||
idx = parameterString.indexOf( ',', idx );
|
||||
}
|
||||
contextInfoOffset -= idx;
|
||||
}
|
||||
|
||||
requestor.acceptMethod(method.getName(),
|
||||
parameterString,
|
||||
ASTUtil.getType(method.getReturnType()),
|
||||
method.getVisiblity(), completionStart, completionLength, relevance);
|
||||
method.getVisiblity(), completionStart, completionLength, relevance, (parameterIndex == -1 ), contextInfoOffset);
|
||||
}
|
||||
else if(node instanceof IASTFunction){
|
||||
IASTFunction function = (IASTFunction)node;
|
||||
|
@ -268,10 +280,20 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
int relevance = computeRelevance(ICElement.C_FUNCTION, prefix, function.getName());
|
||||
|
||||
String parameterString = ASTUtil.getParametersString(ASTUtil.getFunctionParameterTypes(function));
|
||||
|
||||
int contextInfoOffset = completionOrigin;
|
||||
if( parameterIndex > -1 && parameterString.length() > 0){
|
||||
int idx = 0;
|
||||
for( int i = 0; i < parameterIndex; i++ ){
|
||||
idx = parameterString.indexOf( ',', idx );
|
||||
}
|
||||
contextInfoOffset -= idx;
|
||||
}
|
||||
|
||||
requestor.acceptFunction(function.getName(),
|
||||
parameterString,
|
||||
ASTUtil.getType(function.getReturnType()),
|
||||
completionStart, completionLength, relevance);
|
||||
completionStart, completionLength, relevance, (parameterIndex == -1 ), contextInfoOffset);
|
||||
}
|
||||
else if(node instanceof IASTClassSpecifier){
|
||||
IASTClassSpecifier classSpecifier = (IASTClassSpecifier)node;
|
||||
|
@ -372,7 +394,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
|
||||
private void addMacroToCompletions (String prefix, String macroName){
|
||||
int relevance = computeRelevance(ICElement.C_MACRO, prefix, macroName);
|
||||
requestor.acceptMacro(macroName, completionStart, completionLength, relevance);
|
||||
requestor.acceptMacro(macroName, completionStart, completionLength, relevance, completionOrigin);
|
||||
}
|
||||
|
||||
private void addMacrosToCompletions(String prefix, Iterator macros){
|
||||
|
@ -386,10 +408,10 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
}
|
||||
|
||||
private void addToCompletions (ILookupResult result){
|
||||
addToCompletions(result, false, false);
|
||||
addToCompletions(result, false, false, -1);
|
||||
}
|
||||
|
||||
private void addToCompletions (ILookupResult result, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly){
|
||||
private void addToCompletions (ILookupResult result, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly, int paramIndex){
|
||||
if(result == null){
|
||||
log("Lookup Results = null ................. !!! No Lookup Results found !!! "); //$NON-NLS-1$
|
||||
return;
|
||||
|
@ -401,15 +423,15 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
|
||||
while (nodes.hasNext()){
|
||||
IASTNode node = (IASTNode) nodes.next();
|
||||
addNodeToCompletions(node, result.getPrefix(), numberOfElements, addStaticMethodsOnly, addStaticFieldsOnly);
|
||||
addNodeToCompletions(node, result.getPrefix(), numberOfElements, addStaticMethodsOnly, addStaticFieldsOnly, paramIndex );
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
private ILookupResult lookup(IASTScope searchNode, String prefix, LookupKind[] kinds, IASTNode context){
|
||||
private ILookupResult lookup(IASTScope searchNode, String prefix, LookupKind[] kinds, IASTNode context, IASTExpression expression){
|
||||
try {
|
||||
logLookups (kinds);
|
||||
ILookupResult result = searchNode.lookup (prefix, kinds, context);
|
||||
ILookupResult result = searchNode.lookup (prefix, kinds, context, expression);
|
||||
return result ;
|
||||
} catch (IASTNode.LookupError ilk ){
|
||||
// do we want to do something here?
|
||||
|
@ -462,7 +484,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
kinds[0] = IASTNode.LookupKind.FIELDS;
|
||||
kinds[1] = IASTNode.LookupKind.METHODS;
|
||||
kinds[2] = IASTNode.LookupKind.ENUMERATORS;
|
||||
result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions (result);
|
||||
}
|
||||
|
||||
|
@ -486,16 +508,16 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
kinds[8] = IASTNode.LookupKind.ENUMERATORS;
|
||||
kinds[9] = IASTNode.LookupKind.CONSTRUCTORS;
|
||||
*/
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
// lookup static members (field / methods) in types
|
||||
if( (completionNode.getCompletionContext() != null)
|
||||
&& (completionNode.getCompletionContext() instanceof IASTClassSpecifier)
|
||||
&& (((IASTClassSpecifier) completionNode.getCompletionContext()).getClassKind() != ASTClassKind.ENUM) ){
|
||||
if (completionNode.getCompletionScope() instanceof IASTCodeScope){
|
||||
addToCompletions(result, true, true);
|
||||
addToCompletions(result, true, true, -1);
|
||||
}
|
||||
else {
|
||||
addToCompletions(result, false, true);
|
||||
addToCompletions(result, false, true, -1);
|
||||
}
|
||||
} else {
|
||||
addToCompletions(result);
|
||||
|
@ -515,7 +537,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
kinds[1] = IASTNode.LookupKind.ENUMERATIONS;
|
||||
kinds[2] = IASTNode.LookupKind.NAMESPACES;
|
||||
kinds[3] = IASTNode.LookupKind.TYPEDEFS;
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
} else // prefix is empty, we can not look for everything
|
||||
{
|
||||
|
@ -536,7 +558,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
ILookupResult result = null;
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.STRUCTURES;
|
||||
result = lookup(searchNode, classSpec.getName(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, classSpec.getName(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
}
|
||||
|
@ -558,7 +580,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
if (completionNode.getCompletionPrefix().length() > 0){
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.ALL;
|
||||
result = lookup(searchNode, prefix, kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, prefix, kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
else // prefix is empty
|
||||
|
@ -568,24 +590,24 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// we are inside of a method
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.THIS;
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
|
||||
kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
} else {
|
||||
// we are inside of a function
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
} else {
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.ALL;
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
}
|
||||
|
@ -601,7 +623,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// only look for classes
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.CLASSES;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
|
||||
|
@ -611,7 +633,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// only look for classes
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.STRUCTS;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
private void completionOnUnionReference(IASTCompletionNode completionNode){
|
||||
|
@ -620,7 +642,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// only look for classes
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.UNIONS;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
private void completionOnEnumReference(IASTCompletionNode completionNode){
|
||||
|
@ -629,7 +651,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// only look for classes
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.ENUMERATIONS;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
|
||||
|
@ -639,7 +661,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// only look for namespaces
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.NAMESPACES;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
private void completionOnExceptionReference(IASTCompletionNode completionNode){
|
||||
|
@ -652,16 +674,16 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
}
|
||||
private void completionOnMacroReference(IASTCompletionNode completionNode){
|
||||
// 1. Get the search scope node
|
||||
IASTScope searchNode = completionNode.getCompletionScope();
|
||||
//IASTScope searchNode = completionNode.getCompletionScope();
|
||||
// only look for macros
|
||||
List result = lookupMacros(completionNode.getCompletionPrefix());
|
||||
addMacrosToCompletions(completionNode.getCompletionPrefix(), result.iterator());
|
||||
}
|
||||
private void completionOnNewTypeReference(IASTCompletionNode completionNode){
|
||||
// 1. Get the search scope node
|
||||
IASTScope searchNode = completionNode.getCompletionScope();
|
||||
//IASTScope searchNode = completionNode.getCompletionScope();
|
||||
// look for the specific type being newed and the scope
|
||||
IASTNode context = completionNode.getCompletionContext();
|
||||
//IASTNode context = completionNode.getCompletionContext();
|
||||
// basic completion on all types
|
||||
completionOnTypeReference(completionNode);
|
||||
}
|
||||
|
@ -669,11 +691,24 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
private void completionOnConstructorReference(IASTCompletionNode completionNode){
|
||||
// 1. Get the search scope node
|
||||
IASTScope searchNode = completionNode.getCompletionScope();
|
||||
// only lookup constructors
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.CONSTRUCTORS;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
|
||||
addToCompletions(result);
|
||||
if( completionNode.getFunctionName().length() > 0 &&
|
||||
completionNode.getCompletionContext() == null )
|
||||
{
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[]{ IASTNode.LookupKind.STRUCTURES };
|
||||
ILookupResult result = lookup( searchNode, completionNode.getFunctionName(), kinds, null, null );
|
||||
if( result.getResultsSize() == 1 ){
|
||||
IASTClassSpecifier cls = (IASTClassSpecifier) result.getNodes().next();
|
||||
kinds[ 0 ] = IASTNode.LookupKind.CONSTRUCTORS;
|
||||
result = lookup( searchNode, completionNode.getCompletionPrefix(), kinds, cls, completionNode.getFunctionParameters() );
|
||||
addToCompletions( result, false, false, result.getIndexOfNextParameter() );
|
||||
}
|
||||
} else {
|
||||
// only lookup constructors
|
||||
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
|
||||
kinds[0] = IASTNode.LookupKind.CONSTRUCTORS;
|
||||
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext(), null);
|
||||
addToCompletions(result);
|
||||
}
|
||||
}
|
||||
private void completionOnFunctionReference(IASTCompletionNode completionNode){
|
||||
//NOTE:
|
||||
|
@ -682,22 +717,24 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
// looked up for FUNCTION_REFRENCE then please update the documentation in
|
||||
// IASTCompletionNode.java.
|
||||
String prefix = completionNode.getCompletionPrefix();
|
||||
|
||||
boolean functionsOnly = false;
|
||||
IASTNode.LookupKind[] kinds = null;
|
||||
if( prefix.length() == 0 )
|
||||
{
|
||||
kinds = new IASTNode.LookupKind[] { IASTNode.LookupKind.CONSTRUCTORS, IASTNode.LookupKind.FUNCTIONS, IASTNode.LookupKind.METHODS };
|
||||
prefix = completionNode.getFunctionName();
|
||||
functionsOnly = true;
|
||||
}
|
||||
else
|
||||
kinds = new IASTNode.LookupKind[] { IASTNode.LookupKind.ALL };
|
||||
|
||||
ILookupResult result = lookup(completionNode.getCompletionScope(), prefix, kinds, completionNode.getCompletionContext());
|
||||
addToCompletions(result);
|
||||
|
||||
List macros = lookupMacros(completionNode.getCompletionPrefix());
|
||||
addMacrosToCompletions(prefix, macros.iterator());
|
||||
ILookupResult result = lookup(completionNode.getCompletionScope(), prefix, kinds, completionNode.getCompletionContext(), completionNode.getFunctionParameters());
|
||||
addToCompletions(result, false, false, functionsOnly ? result.getIndexOfNextParameter() : -1 );
|
||||
|
||||
if( !functionsOnly ){
|
||||
List macros = lookupMacros(completionNode.getCompletionPrefix());
|
||||
addMacrosToCompletions(prefix, macros.iterator());
|
||||
}
|
||||
}
|
||||
|
||||
public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset) {
|
||||
|
@ -725,6 +762,7 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
}
|
||||
|
||||
// set the completionStart and the completionLength
|
||||
completionOrigin = completionOffset;
|
||||
completionStart = completionOffset - completionNode.getCompletionPrefix().length();
|
||||
completionLength = completionNode.getCompletionPrefix().length();
|
||||
CompletionKind kind = completionNode.getCompletionKind();
|
||||
|
|
|
@ -42,7 +42,7 @@ public class CompletionRequestorAdaptor implements ICompletionRequestor {
|
|||
public void acceptFunction(
|
||||
String name,
|
||||
String parameterString,
|
||||
String returnType, int completionStart, int completionLength, int relevance) {
|
||||
String returnType, int completionStart, int completionLength, int relevance, boolean insertFunctionName, int contextInfoOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class CompletionRequestorAdaptor implements ICompletionRequestor {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.ICompletionRequestor#acceptMacro(java.lang.String)
|
||||
*/
|
||||
public void acceptMacro(String name, int completionStart, int completionLength, int relevance) {
|
||||
public void acceptMacro(String name, int completionStart, int completionLength, int relevance, int contextInfoOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class CompletionRequestorAdaptor implements ICompletionRequestor {
|
|||
public void acceptMethod(
|
||||
String name,
|
||||
String parameterString,
|
||||
String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance) {
|
||||
String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance, boolean insertFunctionName, int contextInfoOffset) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -16,14 +16,14 @@ public interface ICompletionRequestor {
|
|||
void acceptField(String name, String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance);
|
||||
void acceptVariable(String name, String returnType, int completionStart, int completionLength, int relevance);
|
||||
void acceptLocalVariable(String name, String returnType, int completionStart, int completionLength, int relevance);
|
||||
void acceptMethod(String name, String parameterString, String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance);
|
||||
void acceptFunction(String name, String parameterString, String returnType, int completionStart, int completionLength, int relevance);
|
||||
void acceptMethod(String name, String parameterString, String returnType, ASTAccessVisibility visibility, int completionStart, int completionLength, int relevance, boolean insertFunctionName, int contextInfoOffset);
|
||||
void acceptFunction(String name, String parameterString, String returnType, int completionStart, int completionLength, int relevance, boolean insertFunctionName, int contextInfoOffset);
|
||||
void acceptClass(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptStruct(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptUnion(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptTypedef(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptNamespace(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptMacro(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptMacro(String name, int completionStart, int completionLength, int relevance, int contextInfoOffset);
|
||||
void acceptEnumeration(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptEnumerator(String name, int completionStart, int completionLength, int relevance);
|
||||
void acceptKeyword(String name, int completionStart, int completionLength, int relevance);
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
import org.eclipse.cdt.ui.FunctionPrototypeSummary;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.contentassist.ContextInformation;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
/**
|
||||
|
@ -63,7 +62,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
/*
|
||||
* Create a proposal
|
||||
*/
|
||||
public CCompletionProposal createProposal(String replaceString, String displayString, String infoString, String arguments, Image image, int offset, int length, int relevance){
|
||||
public CCompletionProposal createProposal(String replaceString, String displayString, String infoString, String arguments, int contextInfoOffset, Image image, int offset, int length, int relevance){
|
||||
CCompletionProposal proposal;
|
||||
|
||||
proposal = new CCompletionProposal(
|
||||
|
@ -76,7 +75,9 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
fTextViewer);
|
||||
|
||||
if(arguments != null && arguments.length() > 0) {
|
||||
proposal.setContextInformation(new ContextInformation(replaceString, arguments));
|
||||
CProposalContextInformation info = new CProposalContextInformation(replaceString, arguments);
|
||||
info.setContextInformationPosition(contextInfoOffset - 1);
|
||||
proposal.setContextInformation( info );
|
||||
}
|
||||
|
||||
// The info string could be populated with documentation info.
|
||||
|
@ -110,7 +111,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(VAR_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -137,7 +138,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(TYPE_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -151,7 +152,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
String returnType,
|
||||
int completionStart,
|
||||
int completionLength,
|
||||
int relevance) {
|
||||
int relevance, boolean insertFunctionName, int contextInfoOffset ) {
|
||||
String replaceString = ""; //$NON-NLS-1$
|
||||
String displayString = ""; //$NON-NLS-1$
|
||||
String arguments = ""; //$NON-NLS-1$
|
||||
|
@ -185,11 +186,14 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
ImageDescriptor imageDescriptor = CElementImageProvider.getFunctionImageDescriptor();
|
||||
image = registry.get( imageDescriptor );
|
||||
|
||||
if( !insertFunctionName ){
|
||||
replaceString = ""; //$NON-NLS-1$
|
||||
}
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
arguments, image, completionStart, completionLength, relevance);
|
||||
arguments, contextInfoOffset, image, completionStart, completionLength, relevance);
|
||||
|
||||
boolean userMustCompleteParameters= (arguments != null && arguments.length() > 0);
|
||||
boolean userMustCompleteParameters= (arguments != null && arguments.length() > 0) && insertFunctionName;
|
||||
|
||||
char[] triggers= userMustCompleteParameters ? METHOD_WITH_ARGUMENTS_TRIGGERS : METHOD_TRIGGERS;
|
||||
proposal.setTriggerCharacters(triggers);
|
||||
|
@ -228,7 +232,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
image = registry.get( imageDescriptor );
|
||||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(VAR_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -240,7 +244,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
String name,
|
||||
int completionStart,
|
||||
int completionLength,
|
||||
int relevance) {
|
||||
int relevance, int contextInfoOffset) {
|
||||
|
||||
String replaceString = ""; //$NON-NLS-1$
|
||||
String displayString = ""; //$NON-NLS-1$
|
||||
|
@ -279,7 +283,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
arguments, image, completionStart, completionLength, relevance);
|
||||
arguments, contextInfoOffset, image, completionStart, completionLength, relevance);
|
||||
|
||||
proposal.setTriggerCharacters(VAR_TRIGGERS);
|
||||
|
||||
|
@ -302,7 +306,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
ASTAccessVisibility visibility,
|
||||
int completionStart,
|
||||
int completionLength,
|
||||
int relevance) {
|
||||
int relevance, boolean insertFunctionName, int contextInfoOffset) {
|
||||
|
||||
String replaceString = ""; //$NON-NLS-1$
|
||||
String displayString = ""; //$NON-NLS-1$
|
||||
|
@ -336,11 +340,15 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
ImageDescriptor imageDescriptor = CElementImageProvider.getMethodImageDescriptor(visibility);
|
||||
image = registry.get( imageDescriptor );
|
||||
|
||||
if( !insertFunctionName ){
|
||||
//completion only to display the infoString, don't actually insert text
|
||||
replaceString = ""; //$NON-NLS-1$
|
||||
}
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
arguments, image, completionStart, completionLength, relevance);
|
||||
arguments, contextInfoOffset, image, completionStart, completionLength, relevance );
|
||||
|
||||
boolean userMustCompleteParameters= (arguments != null && arguments.length() > 0);
|
||||
boolean userMustCompleteParameters= (arguments != null && arguments.length() > 0) && insertFunctionName;
|
||||
|
||||
char[] triggers= userMustCompleteParameters ? METHOD_WITH_ARGUMENTS_TRIGGERS : METHOD_TRIGGERS;
|
||||
proposal.setTriggerCharacters(triggers);
|
||||
|
@ -376,7 +384,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(TYPE_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -403,7 +411,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
image = registry.get( imageDescriptor );
|
||||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(TYPE_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -430,7 +438,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
image = registry.get( imageDescriptor );
|
||||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(TYPE_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -460,7 +468,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
image = registry.get( imageDescriptor );
|
||||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, image, completionStart, completionLength, relevance);
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(), null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(VAR_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -487,7 +495,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(TYPE_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -516,7 +524,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(VAR_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -543,7 +551,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(TYPE_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
@ -571,7 +579,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
|
|||
// no image for keywords
|
||||
// create proposal and add it to completions list
|
||||
CCompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
|
||||
null, image, completionStart, completionLength, relevance);
|
||||
null, 0, image, completionStart, completionLength, relevance);
|
||||
proposal.setTriggerCharacters(VAR_TRIGGERS);
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue