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

Patch for Andrew Niefer.

Core:
- fix class cast exception in the symbol table while traversing the 
inheritance of a class.
- filter the results of the prefix lookup for content assist so that those 
symbol without attached AST nodes aren removed so that the iterator does 
not later return a null.

Tests:
- added CompletionParseTests.testBug51260
This commit is contained in:
John Camelon 2004-02-09 16:32:43 +00:00
parent 2937f68a8c
commit 728eeb85f8
5 changed files with 69 additions and 10 deletions

View file

@ -5,6 +5,9 @@
Moved testErrorHandling_1() from failed tests to CompleteParseASTTest. Moved testErrorHandling_1() from failed tests to CompleteParseASTTest.
Moved testBug44340() from failed tests to CompleteParseASTTest. Moved testBug44340() from failed tests to CompleteParseASTTest.
2004-02-06 Andrew Niefer
Added CompletionParseTest.testBug51260
2004-02-04 John Camelon 2004-02-04 John Camelon
Added preliminary SelectionParseTests to test SELECTION_PARSE clients. Added preliminary SelectionParseTests to test SELECTION_PARSE clients.
Added SelectionParseTests to ParserTestSuite. Added SelectionParseTests to ParserTestSuite.

View file

@ -601,4 +601,42 @@ public class CompletionParseTest extends CompleteParseBaseTest {
IASTField field = (IASTField) result.getNodes().next(); IASTField field = (IASTField) result.getNodes().next();
assertEquals( field.getName(), "aPrivate" ); assertEquals( field.getName(), "aPrivate" );
} }
public void testBug51260() throws Exception{
StringWriter writer = new StringWriter();
writer.write( " class A { public: void a(); }; " );
writer.write( " class B : public virtual A { public: void b(); };" );
writer.write( " class C : public virtual A { public: void c(); };" );
writer.write( " class D : public B, C { public: void d(); };" );
writer.write( " void A::a(){} ");
writer.write( " void B::b(){} ");
writer.write( " void C::c(){} ");
writer.write( " void D::d(){ SP }" );
String code = writer.toString();
int index = code.indexOf( "SP" );
IASTCompletionNode node = parse( code, index );
ILookupResult result = node.getCompletionScope().lookup( node.getCompletionPrefix(),
new IASTNode.LookupKind[]{ IASTNode.LookupKind.THIS },
node.getCompletionContext() );
assertEquals( result.getResultsSize(), 4 );
Iterator iter = result.getNodes();
IASTMethod d = (IASTMethod) iter.next();
IASTMethod b = (IASTMethod) iter.next();
IASTMethod a = (IASTMethod) iter.next();
IASTMethod c = (IASTMethod) iter.next();
assertFalse( iter.hasNext() );
assertEquals( a.getName(), "a" );
assertEquals( b.getName(), "b" );
assertEquals( c.getName(), "c" );
assertEquals( d.getName(), "d" );
}
} }

View file

@ -3,6 +3,10 @@
Fixed Bug 44340 - Inline functions fail to resolve references Fixed Bug 44340 - Inline functions fail to resolve references
Fixed Bug 51243 - Content Assist in an empty document causes a NPE Fixed Bug 51243 - Content Assist in an empty document causes a NPE
2004-02-06 Andrew Niefer
fixed bug51260 - Content Assist: Completion inside a class method silently fails with a ClassCastException
filter symbols without attached AST nodes out of the completion results so the iterator doesn't sometimes return null.
2004-02-04 John Camelon 2004-02-04 John Camelon
Added preliminary (crude) bSelectionParser IParser implementation for SELECTION_PARSE clients. Added preliminary (crude) bSelectionParser IParser implementation for SELECTION_PARSE clients.

View file

@ -99,10 +99,14 @@ public class ASTNode implements IASTNode {
if(lookupResults == null) if(lookupResults == null)
return null; return null;
//filter out things that are not visible and things that don't have AST nodes attached
ListIterator iter = lookupResults.listIterator(); ListIterator iter = lookupResults.listIterator();
while( iter.hasNext() ){ while( iter.hasNext() ){
ISymbol s = (ISymbol) iter.next(); ISymbol s = (ISymbol) iter.next();
if( !thisContainer.isVisible( s, qualification ) ){ if( !thisContainer.isVisible( s, qualification ) ||
s.getASTExtension() == null ||
s.getASTExtension().getPrimaryDeclaration() == null )
{
iter.remove(); iter.remove();
} }
} }

View file

@ -611,16 +611,26 @@ public class ParserSymbolTable {
while( iter.hasNext() ){ while( iter.hasNext() ){
key = iter.next(); key = iter.next();
if( symbol.containsKey( key ) ){ if( symbol.containsKey( key ) ){
ISymbol sym = (ISymbol) symbol.get( key ); Object obj = symbol.get( key );
if( !checkAmbiguity( sym, temp.get( key ) ) ){ Iterator objIter = ( obj instanceof List ) ? ((List)obj).iterator() : null;
if( data.mode == LookupMode.PREFIX ){ ISymbol sym = (ISymbol) (( objIter != null && objIter.hasNext() ) ? objIter.next() : obj);
if( data.ambiguities == null ){ while( sym != null ){
data.ambiguities = new HashSet(); if( !checkAmbiguity( sym, temp.get( key ) ) ){
} if( data.mode == LookupMode.PREFIX ){
data.ambiguities.add( sym.getName() ); if( data.ambiguities == null ){
data.ambiguities = new HashSet();
}
data.ambiguities.add( sym.getName() );
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous );
}
}
if( objIter != null && objIter.hasNext() ){
sym = (ISymbol) objIter.next();
} else { } else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_Ambiguous ); sym = null;
} }
} }
} else { } else {
symbol.put( key, temp.get( key ) ); symbol.put( key, temp.get( key ) );