mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 00:45:28 +02:00
Bug 52111 - IContainerSymbol.removeSymbol() required
This commit is contained in:
parent
4e0cc83700
commit
57d4d66372
5 changed files with 1534 additions and 1421 deletions
File diff suppressed because it is too large
Load diff
|
@ -3355,5 +3355,74 @@ public class ParserSymbolTableTest extends TestCase {
|
|||
|
||||
assertTrue( f1.hasSameParameters( f2 ) );
|
||||
}
|
||||
|
||||
public void testBug52111RemoveSymbol() throws Exception{
|
||||
newTable();
|
||||
|
||||
IDerivableContainerSymbol A = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
|
||||
table.getCompilationUnit().addSymbol( A );
|
||||
|
||||
ISymbol i = table.newSymbol( "i", TypeInfo.t_int );
|
||||
A.addSymbol( i );
|
||||
|
||||
IParameterizedSymbol f1 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
A.addSymbol( f1 );
|
||||
|
||||
IParameterizedSymbol f2 = table.newParameterizedSymbol( "f", TypeInfo.t_function );
|
||||
f2.addParameter( TypeInfo.t_int, 0, null, false );
|
||||
|
||||
A.addSymbol( f2 );
|
||||
|
||||
IDerivableContainerSymbol B = table.newDerivableContainerSymbol( "B", TypeInfo.t_class );
|
||||
B.addParent( A );
|
||||
|
||||
table.getCompilationUnit().addSymbol( B );
|
||||
|
||||
ISymbol look = B.qualifiedLookup( "i" );
|
||||
assertEquals( look, i );
|
||||
|
||||
Iterator iter = A.getContentsIterator();
|
||||
assertEquals( iter.next(), i );
|
||||
assertEquals( iter.next(), f1 );
|
||||
assertEquals( iter.next(), f2 );
|
||||
assertFalse( iter.hasNext() );
|
||||
|
||||
assertTrue( A.removeSymbol( i ) );
|
||||
|
||||
iter = A.getContentsIterator();
|
||||
assertEquals( iter.next(), f1 );
|
||||
assertEquals( iter.next(), f2 );
|
||||
assertFalse( iter.hasNext() );
|
||||
|
||||
look = B.qualifiedLookup( "i" );
|
||||
assertNull( look );
|
||||
|
||||
List params = new LinkedList();
|
||||
|
||||
look = B.qualifiedFunctionLookup( "f", params );
|
||||
assertEquals( look, f1 );
|
||||
|
||||
assertTrue( A.removeSymbol( f1 ) );
|
||||
iter = A.getContentsIterator();
|
||||
assertEquals( iter.next(), f2 );
|
||||
assertFalse( iter.hasNext() );
|
||||
|
||||
look = B.qualifiedFunctionLookup( "f", params );
|
||||
assertNull( look );
|
||||
|
||||
params.add( new TypeInfo( TypeInfo.t_int, 0, null ) );
|
||||
look = B.qualifiedFunctionLookup( "f", params );
|
||||
|
||||
assertEquals( look, f2 );
|
||||
assertTrue( A.removeSymbol( f2 ) );
|
||||
|
||||
iter = A.getContentsIterator();
|
||||
assertFalse( iter.hasNext() );
|
||||
|
||||
look = B.qualifiedFunctionLookup( "f", params );
|
||||
assertNull( look );
|
||||
|
||||
assertEquals( A.getContainedSymbols().size(), 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2004-02-17 Andrew Niefer
|
||||
bug 52111 : added IContainerSymbol.removeSymbol() which is implemented as ContainerSymbol.removeSymbol()
|
||||
|
||||
2004-02-16 Andrew Niefer
|
||||
bug 52120 document symbol table use of ParserSymbolTableException
|
||||
also clean up a couple of exceptions
|
||||
|
|
|
@ -215,6 +215,42 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
|||
getSymbolTable().pushCommand( command );
|
||||
}
|
||||
|
||||
public boolean removeSymbol( ISymbol symbol ){
|
||||
boolean removed = false;
|
||||
|
||||
Map contained = getContainedSymbols();
|
||||
|
||||
if( symbol != null && contained.containsKey( symbol.getName() ) ){
|
||||
Object obj = contained.get( symbol.getName() );
|
||||
if( obj instanceof ISymbol ){
|
||||
if( obj == symbol ){
|
||||
contained.remove( symbol.getName() );
|
||||
removed = true;
|
||||
}
|
||||
} else if ( obj instanceof List ){
|
||||
List list = (List) obj;
|
||||
if( list.remove( symbol ) ){
|
||||
if( list.size() == 1 ){
|
||||
contained.put( symbol.getName(), list.get( 0 ) );
|
||||
}
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( removed ){
|
||||
ListIterator iter = getContents().listIterator( getContents().size() );
|
||||
while( iter.hasPrevious() ){
|
||||
if( iter.previous() == symbol ){
|
||||
iter.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#hasUsingDirectives()
|
||||
*/
|
||||
|
|
|
@ -38,6 +38,8 @@ public interface IContainerSymbol extends ISymbol {
|
|||
*/
|
||||
public void addSymbol( ISymbol symbol ) throws ParserSymbolTableException;
|
||||
|
||||
public boolean removeSymbol( ISymbol symbol );
|
||||
|
||||
public boolean hasUsingDirectives();
|
||||
public List getUsingDirectives();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue