mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Andrew Niefer
CORE 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 . TESTS Added ContextualParseTest::testCompletionLookup_LookupKindTHIS
This commit is contained in:
parent
24e017a04a
commit
7a48cc3a16
7 changed files with 98 additions and 22 deletions
|
@ -1,3 +1,6 @@
|
|||
2004-01-06 Andrew Niefer
|
||||
Added ContextualParseTest::testCompletionLookup_LookupKindTHIS
|
||||
|
||||
2004-01-06 John Camelon
|
||||
Added CompleteParseASTTest::testBug43110() and QuickParseASTTests::testBug43110().
|
||||
|
||||
|
|
|
@ -371,4 +371,54 @@ public class ContextualParseTest extends CompleteParseBaseTest {
|
|||
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" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
|
|||
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 @@ public class ASTNode implements IASTNode {
|
|||
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 );
|
||||
|
|
|
@ -381,9 +381,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
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 );
|
||||
|
||||
|
|
|
@ -388,7 +388,7 @@ public class ParserSymbolTable {
|
|||
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 @@ public class ParserSymbolTable {
|
|||
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 @@ public class ParserSymbolTable {
|
|||
}
|
||||
}
|
||||
|
||||
int numFunctions = functionList.size();
|
||||
int numFunctions = functionSet.size();
|
||||
|
||||
boolean ambiguous = false;
|
||||
|
||||
|
@ -457,8 +461,8 @@ public class ParserSymbolTable {
|
|||
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 @@ public class ParserSymbolTable {
|
|||
return obj;
|
||||
}
|
||||
} else if( numFunctions > 0 ) {
|
||||
return functionList;
|
||||
return new LinkedList( functionSet );
|
||||
}
|
||||
|
||||
if( ambiguous ){
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
|
|||
public class TypeFilter {
|
||||
|
||||
public TypeFilter(){
|
||||
acceptedTypes.add( TypeInfo.t_any );
|
||||
}
|
||||
|
||||
public TypeFilter( Set types ){
|
||||
|
@ -35,15 +34,15 @@ public class TypeFilter {
|
|||
|
||||
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 @@ public class TypeFilter {
|
|||
/**
|
||||
* @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 );
|
||||
|
|
Loading…
Add table
Reference in a new issue