[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Content Assist work in Symbol Table
|
Support the content assist lookup kind LookupKind.THIS, where the lookup
looks in the class of the this pointer.
Fix a bug where the forward declared functions/methods appeared twice in
the content assist results .
Added ContextualParseTest::testCompletionLookup_LookupKindTHIS
tested on windows
-Andrew
Index: parser/ChangeLog-parser
===================================================================
retrieving revision 1.13
diff -u -r1.13 ChangeLog-parser
--- parser/ChangeLog-parser 6 Jan 2004 15:26:41 -0000 1.13
+++ parser/ChangeLog-parser 6 Jan 2004 21:31:32 -0000
@@ -1,3 +1,7 @@
+2004-01-06 Andrew Niefer
+ For Content Assist, support lookup using LookupKind.THIS (lookup in the class of the this pointer )
+ Fix bug where forward declared method/functions appeared twice in the content assist lookup results.
+
2004-01-06 John Camelon
Renamed IToken::tELIPSE to IToken::tELLIPSIS
Partially fixed Bug 43110 : Parser support needed for functions with ellipses
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java
===================================================================
retrieving revision 1.3
diff -u -r1.3 ASTNode.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java 22 Dec 2003 21:12:56 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTNode.java 6 Jan 2004 21:31:35 -0000
@@ -19,6 +19,7 @@
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension;
import org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner;
+import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
import org.eclipse.cdt.internal.core.parser.pst.TypeFilter;
@@ -52,19 +53,34 @@
throw new LookupException();
}
- 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] );
+ boolean lookInThis = false;
+
+ TypeFilter filter = new TypeFilter();
+ if( kind != null ){
+ for( int i = 0; i < kind.length; i++ ){
+ filter.addAcceptedType( kind[i] );
+ if( kind[i] == LookupKind.THIS ){
+ lookInThis = true;
+ if( kind.length == 1 ){
+ filter.addAcceptedType( LookupKind.ALL );
+ }
+ } else {
+ filter.addAcceptedType( kind[i] );
+ }
}
} else {
- filter = new TypeFilter();
+ filter.addAcceptedType( LookupKind.ALL );
}
List lookupResults = null;
try {
- if( qualification != null ){
+ if( lookInThis ){
+ ISymbol thisPointer = thisContainer.lookup( ParserSymbolTable.THIS );
+ ISymbol thisClass = ( thisPointer != null ) ? thisPointer.getTypeSymbol() : null;
+ if( thisClass != null && thisClass instanceof IContainerSymbol ){
+ lookupResults = ((IContainerSymbol) thisClass).prefixLookup( filter, prefix, true );
+ }
+ } else if( qualification != null ){
lookupResults = qualification.prefixLookup( filter, prefix, true );
} else {
lookupResults = thisContainer.prefixLookup( filter, prefix, false );
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
===================================================================
retrieving revision 1.5
diff -u -r1.5 ContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java 17 Dec 2003 20:51:39 -0000 1.5
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java 6 Jan 2004 21:31:36 -0000
@@ -381,9 +381,9 @@
ISymbol foundSymbol = null;
LookupData data = new LookupData( name, TypeInfo.t_namespace, getTemplateInstance() );
- data.filter.addFilteredType( TypeInfo.t_class );
- data.filter.addFilteredType( TypeInfo.t_struct );
- data.filter.addFilteredType( TypeInfo.t_union );
+ data.filter.addAcceptedType( TypeInfo.t_class );
+ data.filter.addAcceptedType( TypeInfo.t_struct );
+ data.filter.addAcceptedType( TypeInfo.t_union );
data.foundItems = ParserSymbolTable.lookupInContained( data, inSymbol );
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
retrieving revision 1.31
diff -u -r1.31 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 17 Dec 2003 20:51:39 -0000 1.31
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 6 Jan 2004 21:31:37 -0000
@@ -388,7 +388,7 @@
Iterator iter = ( object instanceof List ) ? ((List)object).iterator() : null;
ISymbol symbol = ( iter != null ) ? (ISymbol) iter.next() : (ISymbol) object;
- List functionList = new LinkedList();
+ Set functionSet = new HashSet();
ISymbol obj = null;
IContainerSymbol cls = null;
@@ -400,7 +400,11 @@
foundSymbol = symbol;
if( foundSymbol.isType( TypeInfo.t_function ) ){
- functionList.add( foundSymbol );
+ if( foundSymbol.isForwardDeclaration() && foundSymbol.getTypeSymbol() != null ){
+ foundSymbol = foundSymbol.getTypeSymbol();
+ }
+
+ functionSet.add( foundSymbol );
} else {
//if this is a class-name, other stuff hides it
if( foundSymbol.isType( TypeInfo.t_class, TypeInfo.t_enumeration ) ){
@@ -448,7 +452,7 @@
}
}
- int numFunctions = functionList.size();
+ int numFunctions = functionSet.size();
boolean ambiguous = false;
@@ -457,8 +461,8 @@
if( obj != null && cls.getContainingSymbol() != obj.getContainingSymbol()){
ambiguous = true;
}
- if( functionList != null ){
- Iterator fnIter = functionList.iterator();
+ if( !functionSet.isEmpty() ){
+ Iterator fnIter = functionSet.iterator();
IParameterizedSymbol fn = null;
for( int i = numFunctions; i > 0; i-- ){
fn = (IParameterizedSymbol) fnIter.next();
@@ -477,7 +481,7 @@
return obj;
}
} else if( numFunctions > 0 ) {
- return functionList;
+ return new LinkedList( functionSet );
}
if( ambiguous ){
Index: parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java
===================================================================
retrieving revision 1.3
diff -u -r1.3 TypeFilter.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java 16 Dec 2003 15:18:15 -0000 1.3
+++ parser/org/eclipse/cdt/internal/core/parser/pst/TypeFilter.java 6 Jan 2004 21:31:37 -0000
@@ -22,7 +22,6 @@
public class TypeFilter {
public TypeFilter(){
- acceptedTypes.add( TypeInfo.t_any );
}
public TypeFilter( Set types ){
@@ -35,15 +34,15 @@
public TypeFilter( LookupKind kind ){
acceptedKinds.add( kind );
- populatedFilteredTypes( kind );
+ populatedAcceptedTypes( kind );
}
- public void addFilteredType( TypeInfo.eType type ){
+ public void addAcceptedType( TypeInfo.eType type ){
acceptedTypes.add( type );
}
- public void addFilteredType( LookupKind kind ) {
- populatedFilteredTypes( kind );
+ public void addAcceptedType( LookupKind kind ) {
+ populatedAcceptedTypes( kind );
acceptedKinds.add( kind );
}
@@ -95,7 +94,7 @@
/**
* @param lookupKind
*/
- private void populatedFilteredTypes(LookupKind kind) {
+ private void populatedAcceptedTypes(LookupKind kind) {
if ( kind == LookupKind.ALL ) { acceptedTypes.add( TypeInfo.t_any ); }
else if ( kind == LookupKind.STRUCTURES ) { acceptedTypes.add( TypeInfo.t_class );
acceptedTypes.add( TypeInfo.t_struct );
Index: ChangeLog
===================================================================
retrieving revision 1.160
diff -u -r1.160 ChangeLog
--- ChangeLog 6 Jan 2004 15:26:48 -0000 1.160
+++ ChangeLog 6 Jan 2004 21:29:10 -0000
@@ -1,3 +1,6 @@
+2004-01-06 Andrew Niefer
+ Added ContextualParseTest::testCompletionLookup_LookupKindTHIS
+
2004-01-06 John Camelon
Added CompleteParseASTTest::testBug43110() and QuickParseASTTests::testBug43110().
Index: parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java
===================================================================
retrieving revision 1.6
diff -u -r1.6 ContextualParseTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java 17 Dec 2003 20:51:30 -0000 1.6
+++ parser/org/eclipse/cdt/core/parser/tests/ContextualParseTest.java 6 Jan 2004 21:29:12 -0000
@@ -371,4 +371,54 @@
assertEquals( aLocal.getName(), "aLocal" );
assertEquals( aParameter.getName(), "aParameter" );
}
+
+ public void testCompletionLookup_LookupKindTHIS() throws Exception{
+ StringWriter writer = new StringWriter();
+ writer.write( "int aGlobalVar;" );
+ writer.write( "namespace NS { " );
+ writer.write( " int aNamespaceFunction(){}" );
+ writer.write( " class Base { " );
+ writer.write( " protected: int aBaseField;" );
+ writer.write( " };" );
+ writer.write( " class Derived : public Base {" );
+ writer.write( " int aMethod();" );
+ writer.write( " };" );
+ writer.write( "}" );
+ writer.write( "int NS::Derived::aMethod(){");
+ writer.write( " int aLocal;" );
+ writer.write( " a ");
+
+ String code = writer.toString();
+ int index = code.indexOf( " a " );
+
+ IASTCompletionNode node = parse( code, index + 2 );
+
+ assertNotNull( node );
+
+ assertEquals( node.getCompletionPrefix(), "a" );
+ assertTrue( node.getCompletionScope() instanceof IASTMethod );
+
+ LookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
+ new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS },
+ node.getCompletionContext() );
+
+ assertEquals( result.getResultsSize(), 2 );
+
+ Iterator iter = result.getNodes();
+ IASTMethod method = (IASTMethod) iter.next();
+ IASTField field = (IASTField) iter.next();
+ assertFalse( iter.hasNext() );
+ assertEquals( method.getName(), "aMethod" );
+ assertEquals( field.getName(), "aBaseField" );
+
+ result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
+ new IASTNode.LookupKind[] { IASTNode.LookupKind.THIS, IASTNode.LookupKind.METHODS },
+ node.getCompletionContext() );
+
+ assertEquals( result.getResultsSize(), 1 );
+ iter = result.getNodes();
+ method = (IASTMethod) iter.next();
+ assertFalse( iter.hasNext() );
+ assertEquals( method.getName(), "aMethod" );
+ }
}