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

Content Assist work

This commit is contained in:
Hoda Amer 2003-12-17 19:21:32 +00:00
parent c01adea573
commit 33f033599d
45 changed files with 285 additions and 562 deletions

View file

@ -1,3 +1,6 @@
2003-12-17 Hoda Amer
Small modifications to cope with the new interfaces
2003-12-15 Andrew Niefer 2003-12-15 Andrew Niefer
added ContextualParseTest.testCompletionLookup_Unqualified added ContextualParseTest.testCompletionLookup_Unqualified
added ContextualParseTest.testCompletionLookup_Qualified added ContextualParseTest.testCompletionLookup_Qualified

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor; import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor;
@ -109,38 +110,44 @@ public class CompletionProposalsTest extends TestCase{
String buffer = tu.getBuffer().getContents(); String buffer = tu.getBuffer().getContents();
Document document = new Document(buffer); Document document = new Document(buffer);
int pos = buffer.indexOf(" a ") + 2; int pos = buffer.indexOf(" a ") + 2;
int length = 0;
CCompletionProcessor completionProcessor = new CCompletionProcessor(null); CCompletionProcessor completionProcessor = new CCompletionProcessor(null);
ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, length, tu); IWorkingCopy wc = null;
try{
wc = tu.getWorkingCopy();
}catch (CModelException e){
fail("Failed to get working copy");
}
ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, wc);
try { try {
Thread.sleep(MAGIC_NUMBER); Thread.sleep(MAGIC_NUMBER);
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
fail( "Bogdan's hack did not suffice"); fail( "Bogdan's hack did not suffice");
} }
assertEquals(results.length, 7); assertEquals(results.length, 8);
for (int i = 0; i<results.length; i++){ for (int i = 0; i<results.length; i++){
ICompletionProposal proposal = results[i]; ICompletionProposal proposal = results[i];
String displayString = proposal.getDisplayString(); String displayString = proposal.getDisplayString();
switch(i){ switch(i){
case 0: // case 0 is a key word found by the parser "auto"
case 1:
assertEquals(displayString, "aVariable"); assertEquals(displayString, "aVariable");
break; break;
case 1: case 2:
assertEquals(displayString, "aFunction() bool"); assertEquals(displayString, "aFunction() bool");
break; break;
case 2: case 3:
assertEquals(displayString, "aClass"); assertEquals(displayString, "aClass");
break; break;
case 3: case 4:
assertEquals(displayString, "anotherClass"); assertEquals(displayString, "anotherClass");
break; break;
case 4: case 5:
assertEquals(displayString, "anEnumeration"); assertEquals(displayString, "anEnumeration");
break; break;
case 5: case 6:
assertEquals(displayString, "AStruct"); assertEquals(displayString, "AStruct");
break; break;
case 6: case 7:
assertEquals(displayString, "AMacro"); assertEquals(displayString, "AMacro");
break; break;
} }

View file

@ -121,7 +121,7 @@ public class CompleteParseBaseTest extends TestCase
/* (non-Javadoc) /* (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) * @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 LookupResult lookup(String prefix, LookupKind kind, IASTNode context) throws LookupException { public LookupResult lookup(String prefix, LookupKind[] kind, IASTNode context) throws LookupException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View file

@ -133,10 +133,11 @@ public class ContextualParseTest extends CompleteParseBaseTest {
assertNotNull( prefix ); assertNotNull( prefix );
assertTrue( node.getCompletionScope() instanceof IASTFunction ); assertTrue( node.getCompletionScope() instanceof IASTFunction );
assertEquals( prefix, "a" ); assertEquals( prefix, "a" );
assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.VARIABLE_TYPE ); assertEquals( node.getCompletionKind(), IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE );
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
LookupResult result = node.getCompletionScope().lookup( prefix, IASTNode.LookupKind.ALL, node.getCompletionContext() ); kinds[0] = IASTNode.LookupKind.ALL;
LookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext() );
assertEquals( result.getPrefix(), prefix ); assertEquals( result.getPrefix(), prefix );
Iterator iter = result.getNodes(); Iterator iter = result.getNodes();
@ -177,7 +178,9 @@ public class ContextualParseTest extends CompleteParseBaseTest {
assertNotNull( node.getCompletionContext() ); assertNotNull( node.getCompletionContext() );
assertTrue( node.getCompletionContext() instanceof IASTClassSpecifier ); assertTrue( node.getCompletionContext() instanceof IASTClassSpecifier );
LookupResult result = node.getCompletionScope().lookup( prefix, IASTNode.LookupKind.ALL, node.getCompletionContext() ); IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
kinds[0] = IASTNode.LookupKind.ALL;
LookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext() );
assertEquals( result.getPrefix(), prefix ); assertEquals( result.getPrefix(), prefix );
Iterator iter = result.getNodes(); Iterator iter = result.getNodes();
@ -229,7 +232,9 @@ public class ContextualParseTest extends CompleteParseBaseTest {
assertNotNull( node.getCompletionContext() ); assertNotNull( node.getCompletionContext() );
assertTrue( node.getCompletionContext() instanceof IASTClassSpecifier ); assertTrue( node.getCompletionContext() instanceof IASTClassSpecifier );
LookupResult result = node.getCompletionScope().lookup( prefix, IASTNode.LookupKind.METHODS, node.getCompletionContext() ); IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
kinds[0] = IASTNode.LookupKind.METHODS;
LookupResult result = node.getCompletionScope().lookup( prefix, kinds, node.getCompletionContext() );
assertEquals( result.getPrefix(), prefix ); assertEquals( result.getPrefix(), prefix );
Iterator iter = result.getNodes(); Iterator iter = result.getNodes();

View file

@ -1,3 +1,6 @@
2003-12-17 Hoda Amer
Content Assist work : Integrated with Parser and Symbol table modifications
2003-12-15 Andrew Niefer 2003-12-15 Andrew Niefer
Changed IASTNode.lookup to take the context as a parameter Changed IASTNode.lookup to take the context as a parameter
created ASTNode to implement IASTNode, ASTSymbolOwner extends it. created ASTNode to implement IASTNode, ASTSymbolOwner extends it.

View file

@ -29,5 +29,4 @@ public class Enum
{ {
return enumValue; return enumValue;
} }
} }

View file

@ -58,6 +58,6 @@ public interface IASTNode {
public Iterator getNodes(); public Iterator getNodes();
} }
public LookupResult lookup( String prefix, LookupKind kind, IASTNode context) throws LookupException; public LookupResult lookup( String prefix, LookupKind[] kind, IASTNode context) throws LookupException;
} }

View file

@ -114,7 +114,7 @@ public class ContextualParser extends Parser implements IParser {
/** /**
* @return * @return
*/ */
private IASTCompletionNode.CompletionKind getCompletionKind() { protected IASTCompletionNode.CompletionKind getCompletionKind() {
return kind; return kind;
} }

View file

@ -767,6 +767,8 @@ public abstract class Parser implements IParser
if( scope instanceof IASTClassSpecifier ) if( scope instanceof IASTClassSpecifier )
setCompletionKind( CompletionKind.FIELD_TYPE ); setCompletionKind( CompletionKind.FIELD_TYPE );
else if (scope instanceof IASTCodeScope)
setCompletionKind( CompletionKind.SINGLE_NAME_REFERENCE);
else else
setCompletionKind( CompletionKind.VARIABLE_TYPE ); setCompletionKind( CompletionKind.VARIABLE_TYPE );
try try

View file

@ -96,11 +96,4 @@ public class ASTASMDefinition extends ASTAnonymousDeclaration implements IASTASM
public void exitScope(ISourceElementRequestor requestor) public void exitScope(ISourceElementRequestor requestor)
{ {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -118,12 +118,4 @@ public class ASTAbstractTypeSpecifierDeclaration
{ {
return offsets.getEndingOffset(); return offsets.getEndingOffset();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -18,7 +18,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
* @author jcamelon * @author jcamelon
* *
*/ */
public abstract class ASTAnonymousDeclaration implements IASTDeclaration public abstract class ASTAnonymousDeclaration extends ASTNode implements IASTDeclaration
{ {
private final IContainerSymbol ownerScope; private final IContainerSymbol ownerScope;
/** /**

View file

@ -113,11 +113,4 @@ public class ASTLinkageSpecification extends ASTAnonymousDeclaration implements
/* do nothing */ /* do nothing */
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -30,7 +30,7 @@ public class ASTNode implements IASTNode {
/* (non-Javadoc) /* (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) * @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 LookupResult lookup(String prefix, LookupKind kind, IASTNode context) throws LookupException { public LookupResult lookup(String prefix, LookupKind[] kind, IASTNode context) throws LookupException {
if( ! ( this instanceof ISymbolOwner ) || ( context != null && !(context instanceof ISymbolOwner) ) ){ if( ! ( this instanceof ISymbolOwner ) || ( context != null && !(context instanceof ISymbolOwner) ) ){
return null; return null;
} }
@ -52,7 +52,16 @@ public class ASTNode implements IASTNode {
throw new LookupException(); throw new LookupException();
} }
TypeFilter filter = new TypeFilter( kind ); TypeFilter filter = null;
if( kind != null && kind.length > 0 ){
filter = new TypeFilter( kind[0] );
for( int i = 1; i < kind.length; i++ ){
filter.addFilteredType( kind[i] );
}
} else {
filter = new TypeFilter();
}
List lookupResults = null; List lookupResults = null;
try { try {
if( qualification != null ){ if( qualification != null ){
@ -64,6 +73,9 @@ public class ASTNode implements IASTNode {
throw new LookupException(); throw new LookupException();
} }
if(lookupResults == null)
return null;
ListIterator iter = lookupResults.listIterator(); ListIterator iter = lookupResults.listIterator();
while( iter.hasNext() ){ while( iter.hasNext() ){
ISymbol s = (ISymbol) iter.next(); ISymbol s = (ISymbol) iter.next();

View file

@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpecifier
{ {
private final List refs; private final List refs;
private ISymbol symbol; private ISymbol symbol;
@ -148,13 +148,4 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
{ {
return symbol.getTypeInfo().checkBit( TypeInfo.isImaginary ); return symbol.getTypeInfo().checkBit( TypeInfo.isImaginary );
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -22,7 +22,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTTemplateDeclaration implements IASTTemplateDeclaration public class ASTTemplateDeclaration extends ASTNode implements IASTTemplateDeclaration
{ {
/** /**
* *
@ -122,11 +122,4 @@ public class ASTTemplateDeclaration implements IASTTemplateDeclaration
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -20,7 +20,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateInstantiation;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTTemplateInstantiation implements IASTTemplateInstantiation public class ASTTemplateInstantiation extends ASTNode implements IASTTemplateInstantiation
{ {
/** /**
* *
@ -104,11 +104,4 @@ public class ASTTemplateInstantiation implements IASTTemplateInstantiation
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -20,7 +20,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateSpecialization;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTTemplateSpecialization implements IASTTemplateSpecialization public class ASTTemplateSpecialization extends ASTNode implements IASTTemplateSpecialization
{ {
/** /**
* *
@ -104,11 +104,4 @@ public class ASTTemplateSpecialization implements IASTTemplateSpecialization
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -25,7 +25,7 @@ import org.eclipse.cdt.internal.core.parser.ast.Offsets;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTUsingDeclaration implements IASTUsingDeclaration public class ASTUsingDeclaration extends ASTNode implements IASTUsingDeclaration
{ {
private final IASTScope ownerScope; private final IASTScope ownerScope;
private final boolean isTypeName; private final boolean isTypeName;
@ -128,11 +128,4 @@ public class ASTUsingDeclaration implements IASTUsingDeclaration
{ {
return declaration; return declaration;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -123,11 +123,4 @@ public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUs
return namespace; return namespace;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -97,13 +97,4 @@ public class ASTASMDefinition
public void exitScope(ISourceElementRequestor requestor) public void exitScope(ISourceElementRequestor requestor)
{ {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -115,13 +115,4 @@ public class ASTAbstractTypeSpecifierDeclaration
public void exitScope(ISourceElementRequestor requestor) public void exitScope(ISourceElementRequestor requestor)
{ {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -23,7 +23,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNode;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTCompilationUnit implements IASTCompilationUnit, IASTQScope { public class ASTCompilationUnit extends ASTNode implements IASTCompilationUnit, IASTQScope {
private List declarations = new ArrayList(); private List declarations = new ArrayList();
/* (non-Javadoc) /* (non-Javadoc)
@ -74,13 +74,4 @@ public class ASTCompilationUnit implements IASTCompilationUnit, IASTQScope {
/* do nothing */ /* do nothing */
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -17,7 +17,7 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
* @author jcamelon * @author jcamelon
* *
*/ */
public abstract class ASTDeclaration implements IASTDeclaration { public abstract class ASTDeclaration extends ASTNode implements IASTDeclaration {
private final IASTScope scope; private final IASTScope scope;
public ASTDeclaration( IASTScope scope ) public ASTDeclaration( IASTScope scope )

View file

@ -23,7 +23,7 @@ import org.eclipse.cdt.internal.core.parser.ast.NamedOffsets;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTElaboratedTypeSpecifier implements IASTElaboratedTypeSpecifier public class ASTElaboratedTypeSpecifier extends ASTNode implements IASTElaboratedTypeSpecifier
{ {
private NamedOffsets offsets = new NamedOffsets(); private NamedOffsets offsets = new NamedOffsets();
@ -156,11 +156,4 @@ public class ASTElaboratedTypeSpecifier implements IASTElaboratedTypeSpecifier
{ {
offsets.setNameEndOffset(o); offsets.setNameEndOffset(o);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -281,13 +281,4 @@ public class ASTFunction extends ASTDeclaration implements IASTFunction
{ {
return hasFunctionTryBlock; return hasFunctionTryBlock;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -126,13 +126,4 @@ public class ASTLinkageSpecification
/* do nothing */ /* do nothing */
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -146,11 +146,4 @@ public class ASTNamespaceAlias extends ASTDeclaration implements IASTNamespaceAl
{ {
offsets.setNameEndOffset(o); offsets.setNameEndOffset(o);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -160,11 +160,4 @@ public class ASTNamespaceDefinition extends ASTDeclaration implements IASTNamesp
{ {
offsets.setNameEndOffset(o); offsets.setNameEndOffset(o);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -0,0 +1,34 @@
/*
* Created on 17/12/2003
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package org.eclipse.cdt.internal.core.parser.ast.quick;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupException;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult;
/**
* @author hamer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
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 LookupResult lookup(
String prefix,
LookupKind[] kind,
IASTNode context)
throws LookupException {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -13,6 +13,9 @@ package org.eclipse.cdt.internal.core.parser.ast.quick;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTScopedTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTScopedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupException;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult;
import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement; import org.eclipse.cdt.internal.core.parser.ast.ASTQualifiedNamedElement;
/** /**
@ -36,9 +39,13 @@ public class ASTScopedTypeSpecifier extends ASTQualifiedNamedElement implements
return scope; return scope;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind) * @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 LookupResult lookup(String prefix, LookupKind kind, IASTNode context) { public LookupResult lookup(
String prefix,
LookupKind[] kind,
IASTNode context)
throws LookupException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View file

@ -23,7 +23,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
* @author jcamelon * @author jcamelon
* *
*/ */
public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier public class ASTSimpleTypeSpecifier extends ASTNode implements IASTSimpleTypeSpecifier
{ {
private final boolean imaginary; private final boolean imaginary;
private final boolean complex; private final boolean complex;
@ -193,12 +193,4 @@ public class ASTSimpleTypeSpecifier implements IASTSimpleTypeSpecifier
{ {
return imaginary; return imaginary;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -137,12 +137,4 @@ public class ASTTemplateDeclaration extends ASTDeclaration implements IASTTempla
/* do nothing */ /* do nothing */
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -120,12 +120,4 @@ public class ASTTemplateInstantiation extends ASTDeclaration implements IASTTemp
/* do nothing */ /* do nothing */
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -114,12 +114,4 @@ public class ASTTemplateSpecialization extends ASTDeclaration implements IASTTem
/* do nothing */ /* do nothing */
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -148,12 +148,4 @@ public class ASTTypedefDeclaration extends ASTDeclaration implements IASTTypedef
{ {
offsets.setNameEndOffset(o); offsets.setNameEndOffset(o);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -113,11 +113,4 @@ public class ASTUsingDeclaration
{ {
throw new ASTNotImplementedException(); throw new ASTNotImplementedException();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -105,11 +105,4 @@ public class ASTUsingDirective
{ {
throw new ASTNotImplementedException(); throw new ASTNotImplementedException();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -229,12 +229,4 @@ public class ASTVariable extends ASTDeclaration implements IASTVariable
{ {
offsets.setNameEndOffset(o); offsets.setNameEndOffset(o);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTNode#lookup(java.lang.String, org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind)
*/
public LookupResult lookup(String prefix, LookupKind kind, IASTNode context) {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -1,3 +1,6 @@
2003-12-17 Hoda Amer
Content Assist work: Completion Engine calling new lookups
2003-12-15 Andrew Niefer 2003-12-15 Andrew Niefer
Updated CompletionEngine to match new signature for IASTNode.lookup Updated CompletionEngine to match new signature for IASTNode.lookup

View file

@ -10,12 +10,9 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.BasicSearchMatch;
@ -23,7 +20,6 @@ import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CElement;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.search.matching.OrPattern; import org.eclipse.cdt.internal.core.search.matching.OrPattern;
import org.eclipse.cdt.internal.corext.template.ContextType; import org.eclipse.cdt.internal.corext.template.ContextType;
@ -32,7 +28,6 @@ import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.text.CParameterListValidator; import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
import org.eclipse.cdt.internal.ui.text.CWordFinder;
import org.eclipse.cdt.internal.ui.text.template.TemplateEngine; import org.eclipse.cdt.internal.ui.text.template.TemplateEngine;
import org.eclipse.cdt.ui.CSearchResultLabelProvider; import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -42,16 +37,13 @@ import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.text.ICCompletionProposal; import org.eclipse.cdt.ui.text.ICCompletionProposal;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ContextInformation; import org.eclipse.jface.text.contentassist.ContextInformation;
import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator; import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
/** /**
@ -218,26 +210,23 @@ public class CCompletionProcessor implements IContentAssistProcessor {
IWorkingCopy unit = fManager.getWorkingCopy(fEditor.getEditorInput()); IWorkingCopy unit = fManager.getWorkingCopy(fEditor.getEditorInput());
IDocument document = viewer.getDocument(); IDocument document = viewer.getDocument();
currentOffset = documentOffset;
currentSourceUnit = unit;
ICCompletionProposal[] results = null; ICCompletionProposal[] results = null;
try { try {
if (document != null) { // if (document != null) {
//
// int offset = documentOffset;
// int length = 0;
//
// Point selection = viewer.getSelectedRange();
// if (selection.y > 0) {
// offset = selection.x;
// length = selection.y;
// }
int offset = documentOffset; results = evalProposals(document, documentOffset, unit);
int length = 0; // }
Point selection = viewer.getSelectedRange();
if (selection.y > 0) {
offset = selection.x;
length = selection.y;
}
results = evalProposals(document, offset, length, unit);
}
} catch (Exception e) { } catch (Exception e) {
CUIPlugin.getDefault().log(e); CUIPlugin.getDefault().log(e);
} }
@ -276,37 +265,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
return results; return results;
} }
private ICElement getCurrentScope(ITranslationUnit unit, int documentOffset){
// quick parse the unit
Map elements = unit.parse();
// figure out what element is the enclosing the current offset
ICElement currentScope = unit;
Iterator i = elements.keySet().iterator();
while (i.hasNext()){
CElement element = (CElement) i.next();
if ((element.getStartPos() < documentOffset )
&& ( element.getStartPos() + element.getLength() > documentOffset)
)
{
if(currentScope instanceof ITranslationUnit){
currentScope = element;
}else
if (currentScope instanceof CElement){
CElement currentScopeElement = (CElement) currentScope;
if(
(currentScopeElement.getStartPos() < element.getStartPos())
&& (
(currentScopeElement.getStartPos() + currentScopeElement.getLength() )
> (element.getStartPos() + element.getLength()) )
)
currentScope = element;
}
}
}
return currentScope;
}
/** /**
* Order the given proposals. * Order the given proposals.
*/ */
@ -319,114 +277,23 @@ public class CCompletionProcessor implements IContentAssistProcessor {
/** /**
* Evaluate the actual proposals for C * Evaluate the actual proposals for C
*/ */
public ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ITranslationUnit unit) {
try{
currentOffset = pos;
currentSourceUnit = unit.getWorkingCopy();
} catch (CModelException e){
}
return order (evalProposals(document, pos, length, getCurrentScope (unit, pos)));
}
private ICCompletionProposal[] evalProposals(IDocument document, int startPos, int length, ICElement currentScope) {
boolean isDereference = false;
IRegion region;
String frag = "";
int pos = startPos;
// Move back the pos by one the position is 0-based
if (pos > 0) {
pos--;
}
// TODO: Check to see if we are trying to open for a structure/class, then // TODO: Check to see if we are trying to open for a structure/class, then
// provide that structure's completion instead of the function/variable
// completions. This needs to be properly dealt with so that we can
// offer completion proposals.
if (pos > 1) {
int struct_pos = pos;
try {
//While we aren't on a space, then go back and look for
// . or a -> then determine the structure variable type.
while(document.getChar(struct_pos) == ' ') {
struct_pos--;
}
if (document.getChar(struct_pos) == '.') {
isDereference = true;
pos -= struct_pos - 1;
} else if ((document.getChar(struct_pos) == '>') && (document.getChar(struct_pos - 1) == '-')) {
isDereference = true;
pos -= struct_pos - 2;
} else {
isDereference = false;
}
} catch (BadLocationException ex) {
return null;
}
}
// Get the current "word", it might be a variable or another starter
region = CWordFinder.findWord(document, pos);
if(region == null) {
return null; //Bail out on error
}
//@@@ TODO: Implement the structure member completion //@@@ TODO: Implement the structure member completion
if(isDereference) { public ICCompletionProposal[] evalProposals(IDocument document, int documentOffset, IWorkingCopy unit) {
return null;
}
try {
//frag = document.get(region.getOffset(), region.getLength());
frag = document.get(region.getOffset(), startPos - region.getOffset());
frag = frag.trim();
} catch (BadLocationException ex) {
return null; //Bail out on error
}
//If there is no fragment, then see if we are in a function currentOffset = documentOffset;
if(frag.length() == 0) { currentSourceUnit = unit;
IRegion funcregion;
String funcfrag = "";
funcregion = CWordFinder.findFunction(document, pos + 1);
if(funcregion != null) {
try {
funcfrag = document.get(funcregion.getOffset(), funcregion.getLength());
funcfrag = funcfrag.trim();
} catch(Exception ex) {
funcfrag = "";
}
if(funcfrag.length() == 0) {
return null;
} else {
//@@@ Add some marker here to indicate different path!
region = funcregion;
frag = funcfrag;
}
}
}
// Based on the frag name, build a list of completion proposals
ArrayList completions = new ArrayList(); ArrayList completions = new ArrayList();
// Look in index manager addProposalsFromModel(completions);
addProposalsFromModel(region, completions);
// Loot in the contributed completions return order ( (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]) );
addProposalsFromCompletionContributors(region, frag, completions);
return (ICCompletionProposal[]) completions.toArray(new ICCompletionProposal[0]);
} }
private void addProposalsFromCompletionContributors(IRegion region, String frag, ArrayList completions) { private void addProposalsFromCompletionContributors(String prefix, int offset, int length, List completions) {
IFunctionSummary[] summary; IFunctionSummary[] summary;
summary = CCompletionContributorManager.getDefault().getMatchingFunctions(frag); summary = CCompletionContributorManager.getDefault().getMatchingFunctions(prefix);
if(summary == null) { if(summary == null) {
return; return;
} }
@ -439,8 +306,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
CCompletionProposal proposal; CCompletionProposal proposal;
proposal = new CCompletionProposal(fname, proposal = new CCompletionProposal(fname,
region.getOffset(), offset,
region.getLength(), length,
CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION), CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION),
fproto.getPrototypeString(true), fproto.getPrototypeString(true),
2); 2);
@ -472,7 +339,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
} }
private void addProposalsFromModel (IRegion region, ArrayList completions) { private void addProposalsFromModel (List completions) {
if (currentSourceUnit == null) if (currentSourceUnit == null)
return; return;
@ -481,12 +348,15 @@ public class CCompletionProcessor implements IContentAssistProcessor {
resultCollector.clearCompletions(); resultCollector.clearCompletions();
//invoke the completion engine //invoke the completion engine
IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset, completions); IASTCompletionNode completionNode = completionEngine.complete(currentSourceUnit, currentOffset);
if(completionNode == null) if(completionNode == null)
return; return;
String prefix = completionNode.getCompletionPrefix(); String prefix = completionNode.getCompletionPrefix();
int offset = currentOffset - prefix.length();
int length = prefix.length();
String searchPrefix = prefix + "*"; String searchPrefix = prefix + "*";
// figure out the search scope // figure out the search scope
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE); boolean fileScope = store.getBoolean(ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE);
@ -496,8 +366,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
if ((projectScope) || (projectScopeAndDependency)){ if ((projectScope) || (projectScopeAndDependency)){
List elementsFound = new LinkedList(); List elementsFound = new LinkedList();
resultCollector.clearCompletions();
//////////////////////
ICElement[] projectScopeElement = new ICElement[1]; ICElement[] projectScopeElement = new ICElement[1];
projectScopeElement[0] = (ICElement)currentSourceUnit.getCProject(); projectScopeElement[0] = (ICElement)currentSourceUnit.getCProject();
@ -515,26 +383,14 @@ public class CCompletionProcessor implements IContentAssistProcessor {
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true); searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, searchResultCollector, true);
elementsFound.addAll(searchResultCollector.getSearchResults()); elementsFound.addAll(searchResultCollector.getSearchResults());
sendResultsToCollector(elementsFound.iterator(), region.getOffset(), region.getLength(), prefix ); sendResultsToCollector(elementsFound.iterator(), offset, length, prefix );
} }
else{
/* //Try to get the file
IResource actualFile = currentSourceUnit.getUnderlyingResource();
IProject project = currentSourceUnit.getCProject().getProject();
ArrayList dependencies = new ArrayList();
if (actualFile != null){
//Get file's dependencies
try {
IndexManager indexMan = CCorePlugin.getDefault().getCoreModel().getIndexManager();
indexMan.performConcurrentJob(new DependencyQueryJob(project, (IFile)actualFile, indexMan, dependencies), ICSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null, null);
} catch (Exception e) {
}
}
//Create CFileSearchScope
scope = SearchEngine.createCFileSearchScope((IFile) actualFile, dependencies);
*/ }
completions.addAll(resultCollector.getCompletions()); completions.addAll(resultCollector.getCompletions());
// Loot in the contributed completions
addProposalsFromCompletionContributors(prefix, offset, length, completions);
} }
private void sendResultsToCollector(Iterator results , int completionStart, int completionLength, String prefix){ private void sendResultsToCollector(Iterator results , int completionStart, int completionLength, String prefix){

View file

@ -373,5 +373,29 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
fRelevance= relevance; fRelevance= relevance;
} }
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return fDisplayString.hashCode()
+ fReplacementString.hashCode()
+ ((fAdditionalInfoString == null) ? 0 : fAdditionalInfoString.hashCode());
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object other) {
if(!(other instanceof CCompletionProposal))
return false;
if(!(fDisplayString.equals(((CCompletionProposal)other).fDisplayString)))
return false;
if(!(fReplacementString.equals(((CCompletionProposal)other).fReplacementString)))
return false;
if((fAdditionalInfoString != null) && (((CCompletionProposal)other).fAdditionalInfoString != null) && (!(fAdditionalInfoString.equals(((CCompletionProposal)other).fAdditionalInfoString))))
return false;
return true;
}
} }

View file

@ -42,8 +42,10 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTMethod; import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupException; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult; import org.eclipse.cdt.core.parser.ast.IASTNode.LookupResult;
import org.eclipse.cdt.internal.core.CharOperation; import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.model.IWorkingCopy; import org.eclipse.cdt.internal.core.model.IWorkingCopy;
@ -63,7 +65,6 @@ import org.eclipse.jface.preference.IPreferenceStore;
* *
*/ */
public class CompletionEngine implements RelevanceConstants{ public class CompletionEngine implements RelevanceConstants{
List completions = new ArrayList();
ICompletionRequestor requestor; ICompletionRequestor requestor;
int completionStart = 0; int completionStart = 0;
int completionLength = 0; int completionLength = 0;
@ -88,7 +89,6 @@ public class CompletionEngine implements RelevanceConstants{
private static final String exceptionKeyword = "..."; private static final String exceptionKeyword = "...";
public CompletionEngine(ICompletionRequestor completionRequestor){ public CompletionEngine(ICompletionRequestor completionRequestor){
completions.clear();
requestor = completionRequestor; requestor = completionRequestor;
} }
@ -204,7 +204,8 @@ public class CompletionEngine implements RelevanceConstants{
int relevance = computeRelevance(ICElement.C_METHOD, prefix, method.getName()); int relevance = computeRelevance(ICElement.C_METHOD, prefix, method.getName());
String parameterString = ASTUtil.getParametersString(ASTUtil.getFunctionParameterTypes(method)); String parameterString = ASTUtil.getParametersString(ASTUtil.getFunctionParameterTypes(method));
requestor.acceptMethod(method.getName(), requestor.acceptMethod(method.getName(),
ASTUtil.getType(method.getReturnType()), parameterString, parameterString,
ASTUtil.getType(method.getReturnType()),
method.getVisiblity(), completionStart, completionLength, relevance); method.getVisiblity(), completionStart, completionLength, relevance);
} }
else if(node instanceof IASTFunction){ else if(node instanceof IASTFunction){
@ -212,7 +213,8 @@ public class CompletionEngine implements RelevanceConstants{
int relevance = computeRelevance(ICElement.C_FUNCTION, prefix, function.getName()); int relevance = computeRelevance(ICElement.C_FUNCTION, prefix, function.getName());
String parameterString = ASTUtil.getParametersString(ASTUtil.getFunctionParameterTypes(function)); String parameterString = ASTUtil.getParametersString(ASTUtil.getFunctionParameterTypes(function));
requestor.acceptFunction(function.getName(), requestor.acceptFunction(function.getName(),
ASTUtil.getType(function.getReturnType()), parameterString, parameterString,
ASTUtil.getType(function.getReturnType()),
completionStart, completionLength, relevance); completionStart, completionLength, relevance);
} }
else if(node instanceof IASTClassSpecifier){ else if(node instanceof IASTClassSpecifier){
@ -292,61 +294,60 @@ public class CompletionEngine implements RelevanceConstants{
} }
return result; return result;
} }
private LookupResult lookup(IASTScope searchNode, String prefix, LookupKind[] kinds, IASTNode context){
try {
LookupResult result = searchNode.lookup (prefix, kinds, context);
return result ;
} catch (IASTNode.LookupException ilk ){
// do we want to do something here?
ilk.printStackTrace();
return null;
}
}
private void completionOnMemberReference(IASTCompletionNode completionNode){ private void completionOnMemberReference(IASTCompletionNode completionNode){
// Completing after a dot // Completing after a dot
// 1. Get the search scope node // 1. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
LookupResult result = null; LookupResult result = null;
// 2. lookup fields & add to completion proposals // lookup fields and methods with the right visibility
try IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[2];
{ kinds[0] = IASTNode.LookupKind.FIELDS;
result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.FIELDS, completionNode.getCompletionContext()); kinds[1] = IASTNode.LookupKind.METHODS;
addToCompletions (result); result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
} addToCompletions (result);
catch( IASTNode.LookupException ilk )
{
}
try
{
// 3. looup methods & add to completion proposals
result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS, completionNode.getCompletionContext());
addToCompletions (result);
}
catch( IASTNode.LookupException ilk )
{
}
try {
// 4. lookup nested structures & add to completion proposals
result = searchNode.lookup (completionNode.getCompletionPrefix(), IASTNode.LookupKind.STRUCTURES, completionNode.getCompletionContext());
addToCompletions (result);
} catch (LookupException e) {
}
} }
private void completionOnScopedReference(IASTCompletionNode completionNode){
// 1. Get the search scope node
// the search node is the name before the qualification
IASTScope searchNode = completionNode.getCompletionScope();
// here we have to look for anything that could be referenced within this scope
// 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[4];
kinds[0] = IASTNode.LookupKind.VARIABLES;
kinds[1] = IASTNode.LookupKind.STRUCTURES;
kinds[2] = IASTNode.LookupKind.ENUMERATIONS;
kinds[3] = IASTNode.LookupKind.NAMESPACES;
LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result);
// TODO
// lookup static members (field / methods) in type
}
private void completionOnTypeReference(IASTCompletionNode completionNode){ private void completionOnTypeReference(IASTCompletionNode completionNode){
// completing on a type // completing on a type
// 1. Get the search scope node // 1. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// if the prefix is not empty // if the prefix is not empty
if(completionNode.getCompletionPrefix().length() > 0 ) { if(completionNode.getCompletionPrefix().length() > 0 ) {
// 2. Lookup all types that could be used here // 2. Lookup all types that could be used here
LookupResult result; LookupResult result;
try { IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[2];
result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.STRUCTURES, completionNode.getCompletionContext()); kinds[0] = IASTNode.LookupKind.STRUCTURES;
addToCompletions(result); kinds[1] = IASTNode.LookupKind.ENUMERATIONS;
} catch (LookupException e) { result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
} addToCompletions(result);
// 3. Lookup keywords
// basic types should be in the keyword list
List keywords = lookupKeyword(completionNode.getCompletionPrefix(), BASIC_TYPES_KEYWORDS);
addKeywordsToCompletions(keywords.iterator());
} else // prefix is empty, we can not look for everything } else // prefix is empty, we can not look for everything
{ {
@ -357,18 +358,17 @@ public class CompletionEngine implements RelevanceConstants{
// 1. basic completion on all types // 1. basic completion on all types
completionOnTypeReference(completionNode); completionOnTypeReference(completionNode);
// 2. Get the search scope node // 2. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// 3. lookup methods // TODO
// 3. provide a template for constructor/ destructor
// 4. lookup methods
// we are at a field declaration place, the user could be trying to override a function. // we are at a field declaration place, the user could be trying to override a function.
// We have to lookup functions that could be overridden here. // We have to lookup functions that could be overridden here.
LookupResult result; // LookupResult result;
try { // IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.METHODS, completionNode.getCompletionContext()); // kinds[0] = IASTNode.LookupKind.METHODS;
addToCompletions(result); // result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
} catch (LookupException e) { // addToCompletions(result);
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
private void completionOnVariableType(IASTCompletionNode completionNode){ private void completionOnVariableType(IASTCompletionNode completionNode){
@ -378,79 +378,49 @@ public class CompletionEngine implements RelevanceConstants{
private void completionOnSingleNameReference(IASTCompletionNode completionNode){ private void completionOnSingleNameReference(IASTCompletionNode completionNode){
// 1. Get the search scope node // 1. Get the search scope node
// the search node is the code scope inwhich completion is requested // the search node is the code scope inwhich completion is requested
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// if prefix is not empty // if prefix is not empty
if (completionNode.getCompletionPrefix().length() > 0){ if (completionNode.getCompletionPrefix().length() > 0){
// here we have to look for anything that could be referenced within this scope // here we have to look for anything that could be referenced within this scope
// 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces // 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces
try IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[7];
{ kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.ALL, completionNode.getCompletionContext()); kinds[1] = IASTNode.LookupKind.FIELDS;
addToCompletions(result); kinds[2] = IASTNode.LookupKind.VARIABLES;
} kinds[3] = IASTNode.LookupKind.STRUCTURES;
catch( LookupException ilk ) kinds[4] = IASTNode.LookupKind.ENUMERATIONS;
{ kinds[5] = IASTNode.LookupKind.METHODS;
kinds[6] = IASTNode.LookupKind.FUNCTIONS;
} LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result);
} else // prefix is empty } else // prefix is empty
{ {
// 1. look only for local variables IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[3];
try kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
{ kinds[1] = IASTNode.LookupKind.FIELDS;
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.LOCAL_VARIABLES, completionNode.getCompletionContext()); kinds[2] = IASTNode.LookupKind.METHODS;
addToCompletions(result); LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
}
catch( LookupException ilk )
{
}
// 2. and what can be accessed through the "this" pointer
// TODO : complete the lookup call
}
}
private void completionOnScopedReference(IASTCompletionNode completionNode){
// 1. Get the search scope node
// the search node is the name before the qualification
IASTNode searchNode = completionNode.getCompletionScope();
// here we have to look for anything that could be referenced within this scope
// 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces
try
{
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.ALL, completionNode.getCompletionContext());
addToCompletions(result); addToCompletions(result);
} }
catch( LookupException ilk )
{
}
} }
private void completionOnClassReference(IASTCompletionNode completionNode){ private void completionOnClassReference(IASTCompletionNode completionNode){
// 1. Get the search scope node // 1. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// only look for classes // only look for classes
try IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
{ kinds[0] = IASTNode.LookupKind.CLASSES;
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.CLASSES, completionNode.getCompletionContext()); LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result); addToCompletions(result);
}
catch( LookupException ilk )
{
}
} }
private void completionOnNamespaceReference(IASTCompletionNode completionNode){ private void completionOnNamespaceReference(IASTCompletionNode completionNode){
// 1. Get the search scope node // 1. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// only look for classes // only look for namespaces
try IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
{ kinds[0] = IASTNode.LookupKind.NAMESPACES;
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.NAMESPACES, completionNode.getCompletionContext()); LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result); addToCompletions(result);
}
catch( LookupException ilk )
{
}
} }
private void completionOnExceptionReference(IASTCompletionNode completionNode){ private void completionOnExceptionReference(IASTCompletionNode completionNode){
// here we have to look for all types // here we have to look for all types
@ -462,32 +432,23 @@ public class CompletionEngine implements RelevanceConstants{
} }
private void completionOnMacroReference(IASTCompletionNode completionNode){ private void completionOnMacroReference(IASTCompletionNode completionNode){
// 1. Get the search scope node // 1. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// only look for macros // only look for macros
try IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
{ kinds[0] = IASTNode.LookupKind.MACROS;
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.MACROS, completionNode.getCompletionContext()); LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result); addToCompletions(result);
}
catch( LookupException ilk )
{
}
} }
private void completionOnFunctionReference(IASTCompletionNode completionNode){ private void completionOnFunctionReference(IASTCompletionNode completionNode){
// TODO: complete the lookups // TODO: complete the lookups
} }
private void completionOnConstructorReference(IASTCompletionNode completionNode){ private void completionOnConstructorReference(IASTCompletionNode completionNode){
// 1. Get the search scope node // 1. Get the search scope node
IASTNode searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// only lookup constructors // only lookup constructors
try IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
{ kinds[0] = IASTNode.LookupKind.CONSTRUCTORS;
LookupResult result = searchNode.lookup(completionNode.getCompletionPrefix(), IASTNode.LookupKind.CONSTRUCTORS, completionNode.getCompletionContext()); LookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
}
catch( LookupException ilk )
{
}
} }
private void completionOnKeyword(IASTCompletionNode completionNode){ private void completionOnKeyword(IASTCompletionNode completionNode){
// lookup every type of keywords // lookup every type of keywords
@ -496,7 +457,7 @@ public class CompletionEngine implements RelevanceConstants{
addKeywordsToCompletions(result.iterator()); addKeywordsToCompletions(result.iterator());
} }
public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset, List completionList) { public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset) {
// 1- Parse the translation unit // 1- Parse the translation unit
IASTCompletionNode completionNode = parse(sourceUnit, completionOffset); IASTCompletionNode completionNode = parse(sourceUnit, completionOffset);
@ -505,69 +466,69 @@ public class CompletionEngine implements RelevanceConstants{
return null; return null;
// set the completionStart and the completionLength // set the completionStart and the completionLength
completionStart = completionOffset; completionStart = completionOffset - completionNode.getCompletionPrefix().length();
completionLength = completionNode.getCompletionPrefix().length(); completionLength = completionNode.getCompletionPrefix().length();
CompletionKind kind = completionNode.getCompletionKind();
// 2- Check the return value // 2- Check the return value
if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.MEMBER_REFERENCE){ if(kind == IASTCompletionNode.CompletionKind.MEMBER_REFERENCE){
// completionOnMemberReference // completionOnMemberReference
completionOnMemberReference(completionNode); completionOnMemberReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SCOPED_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.SCOPED_REFERENCE){
// completionOnMemberReference // completionOnMemberReference
completionOnMemberReference(completionNode); completionOnScopedReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FIELD_TYPE){ else if(kind == IASTCompletionNode.CompletionKind.FIELD_TYPE){
// CompletionOnFieldType // CompletionOnFieldType
completionOnFieldType(completionNode); completionOnFieldType(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.VARIABLE_TYPE){ else if(kind == IASTCompletionNode.CompletionKind.VARIABLE_TYPE) {
// CompletionOnVariableType // CompletionOnVariableType
completionOnTypeReference(completionNode);
}
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.ARGUMENT_TYPE){
// CompletionOnArgumentType
completionOnVariableType(completionNode); completionOnVariableType(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.ARGUMENT_TYPE){
// CompletionOnArgumentType
completionOnTypeReference(completionNode);
}
else if(kind == IASTCompletionNode.CompletionKind.SINGLE_NAME_REFERENCE){
// CompletionOnSingleNameReference // CompletionOnSingleNameReference
completionOnSingleNameReference(completionNode); completionOnSingleNameReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.TYPE_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.TYPE_REFERENCE){
// CompletionOnStructureReference // CompletionOnStructureReference
completionOnTypeReference(completionNode); completionOnTypeReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.CLASS_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.CLASS_REFERENCE){
// CompletionOnClassReference // CompletionOnClassReference
completionOnClassReference(completionNode); completionOnClassReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.NAMESPACE_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.NAMESPACE_REFERENCE){
// completionOnNamespaceReference // completionOnNamespaceReference
completionOnNamespaceReference(completionNode); completionOnNamespaceReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.EXCEPTION_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.EXCEPTION_REFERENCE){
// CompletionOnExceptionReference // CompletionOnExceptionReference
completionOnExceptionReference(completionNode); completionOnExceptionReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.MACRO_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.MACRO_REFERENCE){
// CompletionOnMacroReference // CompletionOnMacroReference
completionOnMacroReference(completionNode); completionOnMacroReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.FUNCTION_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.FUNCTION_REFERENCE){
// completionOnFunctionReference // completionOnFunctionReference
completionOnFunctionReference(completionNode); completionOnFunctionReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.CONSTRUCTOR_REFERENCE){ else if(kind == IASTCompletionNode.CompletionKind.CONSTRUCTOR_REFERENCE){
// completionOnConstructorReference // completionOnConstructorReference
completionOnConstructorReference(completionNode); completionOnConstructorReference(completionNode);
} }
else if(completionNode.getCompletionKind() == IASTCompletionNode.CompletionKind.KEYWORD){ else if(kind == IASTCompletionNode.CompletionKind.KEYWORD){
// CompletionOnKeyword // CompletionOnKeyword
completionOnKeyword(completionNode); completionOnKeyword(completionNode);
} }
addKeywordsToCompletions( completionNode.getKeywords()); addKeywordsToCompletions( completionNode.getKeywords());
completionList.addAll(completions);
return completionNode; return completionNode;
} }

View file

@ -15,7 +15,7 @@ package org.eclipse.cdt.internal.ui.text.contentassist;
* *
*/ */
public interface RelevanceConstants { public interface RelevanceConstants {
final int KEYWORD_TYPE_RELEVANCE = 13; final int KEYWORD_TYPE_RELEVANCE = 30;
final int LOCAL_VARIABLE_TYPE_RELEVANCE = 12; final int LOCAL_VARIABLE_TYPE_RELEVANCE = 12;
final int FIELD_TYPE_RELEVANCE = 11; final int FIELD_TYPE_RELEVANCE = 11;
final int VARIABLE_TYPE_RELEVANCE = 10; final int VARIABLE_TYPE_RELEVANCE = 10;
@ -32,6 +32,6 @@ public interface RelevanceConstants {
final int CASE_MATCH_RELEVANCE = 10; final int CASE_MATCH_RELEVANCE = 10;
final int EXACT_NAME_MATCH_RELEVANCE = 4; final int EXACT_NAME_MATCH_RELEVANCE = 4;
final int CASE_NOT_VALID_RELEVANCE = -100;
} }

View file

@ -10,8 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
import java.util.ArrayList; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.ui.CElementImageProvider; import org.eclipse.cdt.internal.ui.CElementImageProvider;
@ -32,7 +33,7 @@ import org.eclipse.swt.graphics.Image;
* *
*/ */
public class ResultCollector extends CompletionRequestorAdaptor { public class ResultCollector extends CompletionRequestorAdaptor {
private List completions = new ArrayList(); private Set completions = new HashSet();
private ImageDescriptorRegistry registry = CUIPlugin.getImageDescriptorRegistry(); private ImageDescriptorRegistry registry = CUIPlugin.getImageDescriptorRegistry();
public ResultCollector(){ public ResultCollector(){
@ -42,7 +43,7 @@ public class ResultCollector extends CompletionRequestorAdaptor {
/** /**
* @return the completion list * @return the completion list
*/ */
public List getCompletions() { public Set getCompletions() {
return completions; return completions;
} }
public void clearCompletions() { public void clearCompletions() {