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

bug 52695: IASTClassSpecifier.getDeclarations returns an empty iterator

This commit is contained in:
Andrew Niefer 2004-03-01 21:18:11 +00:00
parent d557516718
commit 0f74ca46c3
18 changed files with 2099 additions and 1574 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,335 @@
/*
* Created on Feb 25, 2004
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.NullLogService;
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest {
public CompleteParseASTSymbolIteratorTest(String a)
{
super(a);
}
public static class CompilationUnitCallback extends NullSourceElementRequestor implements ISourceElementRequestor {
IASTCompilationUnit compilationUnit;
public void enterCompilationUnit(IASTCompilationUnit compUnit)
{
compilationUnit = compUnit;
}
public IASTCompilationUnit getCompilationUnit(){
return compilationUnit;
}
}
protected CompilationUnitCallback callback;
protected IASTScope parse(String code, boolean throwOnError, ParserLanguage language) throws ParserException, ParserFactoryError
{
callback = new CompilationUnitCallback();
IParser parser = ParserFactory.createParser(
ParserFactory.createScanner( new StringReader( code ), "test-code", new ScannerInfo(),
ParserMode.COMPLETE_PARSE, language, callback, new NullLogService() ), callback, ParserMode.COMPLETE_PARSE, language, null
);
if( ! parser.parse() && throwOnError ) throw new ParserException( "FAILURE");
return callback.getCompilationUnit();
}
protected Iterator getDeclarations(IASTScope scope)
{
//don't want to use this
assertTrue( false );
return null;
}
public void testEmptyCompilationUnit() throws Exception
{
IASTScope compilationUnit = parse( "// no real code ");
assertNotNull( compilationUnit );
assertFalse( compilationUnit.getDeclarations().hasNext() );
try{
compilationUnit.getDeclarations().next();
assertTrue( false );
} catch( NoSuchElementException e ){
}
}
public void testSimpleNamespace() throws Exception
{
Iterator declarations = parse( "namespace A { }").getDeclarations();
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
assertEquals( namespaceDefinition.getName(), "A" );
assertFalse( namespaceDefinition.getDeclarations().hasNext() );
try{
declarations.remove();
assertTrue( false );
} catch( UnsupportedOperationException e ){
}
}
public void testMultipleNamespaceDefinitions() throws Exception
{
Iterator declarations = parse( "namespace A { } namespace A { }").getDeclarations();
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
assertEquals( namespaceDefinition.getName(), "A" );
assertFalse( declarations.hasNext() );
}
public void testNestedNamespaceDefinitions() throws Exception
{
Iterator declarations = parse( "namespace A { namespace B { } }").getDeclarations();
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
assertEquals( namespaceDefinition.getName(), "A" );
assertFalse( declarations.hasNext() );
Iterator subDeclarations = namespaceDefinition.getDeclarations();
IASTNamespaceDefinition subDeclaration = (IASTNamespaceDefinition)subDeclarations.next();
assertEquals( subDeclaration.getName(), "B" );
assertFalse( subDeclarations.hasNext() );
}
public void testEmptyClassDeclaration() throws Exception
{
Iterator declarations = parse( "class A { };").getDeclarations();
IASTClassSpecifier classSpec = (IASTClassSpecifier)declarations.next();
assertEquals( classSpec.getName(), "A");
assertFalse( classSpec.getDeclarations().hasNext() );
assertFalse( declarations.hasNext() );
}
public void testNestedSubclass() throws Exception
{
Iterator declarations = parse( "namespace N { class A { }; } class B : protected virtual N::A { };").getDeclarations();
IASTNamespaceDefinition namespaceDefinition = (IASTNamespaceDefinition)declarations.next();
Iterator nsDecls = namespaceDefinition.getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)nsDecls.next();
assertFalse( nsDecls.hasNext() );
IASTClassSpecifier classB = (IASTClassSpecifier)declarations.next();
Iterator baseClauses = classB.getBaseClauses();
IASTBaseSpecifier baseClass = (IASTBaseSpecifier)baseClauses.next();
assertEquals( classA, baseClass.getParentClassSpecifier() );
}
public void testSimpleVariable() throws Exception
{
Iterator declarations = parse( "int x;").getDeclarations();
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
assertFalse( declarations.hasNext() );
}
public void testSimpleClassReferenceVariable() throws Exception
{
Iterator declarations = parse( "class A { } a; A x;").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
assertFalse( classA.getDeclarations().hasNext() );
IASTVariable a = (IASTVariable)declarations.next();
assertEquals( a.getName(), "a");
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
assertFalse( declarations.hasNext() );
}
public void testMultipleDeclaratorsVariable() throws Exception
{
Iterator declarations = parse( "class A { }; A x, y, z;").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
IASTVariable v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "x");
v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "y");
v = (IASTVariable)declarations.next();
assertEquals( v.getName(), "z");
assertEquals( ((IASTSimpleTypeSpecifier)v.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), classA );
assertFalse( declarations.hasNext() );
}
public void testSimpleField() throws Exception
{
Iterator declarations = parse( "class A { double x; };").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
Iterator fields = classA.getDeclarations();
IASTField f = (IASTField)fields.next();
assertEquals( f.getName(), "x" );
assertFalse( fields.hasNext() );
assertFalse( declarations.hasNext() );
}
public void testSimpleFunction() throws Exception
{
Iterator declarations = parse( "void foo( void );").getDeclarations();
IASTFunction function = (IASTFunction)declarations.next();
assertEquals( function.getName(), "foo" );
assertFalse( declarations.hasNext() );
}
public void testSimpleMethod() throws Exception
{
Iterator declarations = parse( "class A { void foo(); };").getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)declarations.next();
IASTMethod method = (IASTMethod) classA.getDeclarations().next();
assertEquals( method.getName(), "foo" );
}
public void testLinkageSpec() throws Exception
{
Iterator declarations = parse( "extern \"C\" { int foo(); }").getDeclarations();
//7.5-4 A linkage specification does not establish a scope
IASTFunction f = (IASTFunction)declarations.next();
assertEquals( f.getName(),"foo");
assertFalse( declarations.hasNext() );
}
public void testSimpleTypedef() throws Exception
{
Iterator iter = parse( "typedef int myInt;\n myInt var;").getDeclarations();
IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)iter.next();
assertEquals( typedef.getName(), "myInt");
assertEquals( ((IASTSimpleTypeSpecifier)typedef.getAbstractDeclarator().getTypeSpecifier()).getType(), IASTSimpleTypeSpecifier.Type.INT );
IASTVariable v = (IASTVariable)iter.next();
assertEquals( v.getName(), "var");
assertFalse( iter.hasNext() );
}
public void testOverride() throws Exception
{
Iterator i = parse( "void foo();\n void foo( int );\n").getDeclarations();
IASTFunction f1 = (IASTFunction)i.next();
IASTFunction f2 = (IASTFunction)i.next();
assertFalse( i.hasNext() );
}
public void testEnumerations() throws Exception
{
Iterator declarations = parse( "namespace A { enum E { e1, e2, e3 }; E varE;}").getDeclarations();
IASTNamespaceDefinition namespaceA = (IASTNamespaceDefinition)declarations.next();
Iterator namespaceMembers = namespaceA.getDeclarations();
IASTEnumerationSpecifier enumE = (IASTEnumerationSpecifier)namespaceMembers.next();
assertEquals( enumE.getName(), "E");
assertQualifiedName( enumE.getFullyQualifiedName(), new String [] { "A", "E" } );
Iterator enumerators = enumE.getEnumerators();
IASTEnumerator enumerator_e1 = (IASTEnumerator)enumerators.next();
IASTEnumerator enumerator_e2 = (IASTEnumerator)enumerators.next();
IASTEnumerator enumerator_e3 = (IASTEnumerator)enumerators.next();
assertFalse( enumerators.hasNext() );
assertEquals( enumerator_e1.getName(), "e1");
assertEquals( enumerator_e2.getName(), "e2");
assertEquals( enumerator_e3.getName(), "e3");
IASTVariable varE = (IASTVariable)namespaceMembers.next();
assertEquals( ((IASTSimpleTypeSpecifier)varE.getAbstractDeclaration().getTypeSpecifier()).getTypeSpecifier(), enumE );
assertFalse( namespaceMembers.hasNext() );
assertFalse( declarations.hasNext() );
}
public void testMethodDefinitions() throws Exception
{
Iterator i = parse( " class A { void f(); }; void A::f(){ }" ).getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier) i.next();
assertFalse( i.hasNext() );
i = classA.getDeclarations();
IASTMethod f = (IASTMethod)i.next();
assertFalse( i.hasNext() );
}
public void testConstructorsDestructors() throws Exception
{
Iterator i = parse( "class A { A(); ~A(); }; A::A(){} A::~A(){}" ).getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier) i.next();
assertFalse( i.hasNext() );
i = classA.getDeclarations();
assertTrue( i.hasNext() );
IASTMethod constructor = (IASTMethod) i.next();
assertTrue( constructor.getName().equals( "A" ) );
IASTMethod destructor = (IASTMethod) i.next();
assertTrue( destructor.getName().equals( "~A" ) );
assertFalse( i.hasNext() );
}
}

View file

@ -40,6 +40,7 @@ public class ParserTestSuite extends TestCase {
suite.addTestSuite( CompleteParseASTTest.class );
suite.addTestSuite( SelectionParseTest.class );
suite.addTestSuite( CompleteParseASTExpressionTest.class );
suite.addTestSuite( CompleteParseASTSymbolIteratorTest.class );
return suite;
}
}

View file

@ -1,3 +1,10 @@
2004-03-01 Andrew Niefer
bug 52695 : ast.complete.IASTClassSpecifier#getDeclarations returns an empty iterator
- take ASTNode.SymbolIterator and move it to org.eclipse.cdt.internal.core.parser.ast
- hook up ASTScope.getDeclarations to IContainerSymbol.getContentsIterator() using SymbolIterator
- create ExtensibleSymbol to implement IExtensibleSymbol and derive BasicSymbol, UsingDeclarationSymbol and UsingDirectiveSymbol from it.
2004-02-26 Andrew Niefer
mark strings that don't need to be externalized for translation

View file

@ -0,0 +1,74 @@
/*
* Created on Feb 25, 2004
*
* 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;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class SymbolIterator implements Iterator {
Iterator interalIterator;
IExtensibleSymbol next = null;
public SymbolIterator( Iterator iter ){
interalIterator = iter;
}
/* (non-Javadoc)
* @see java.util.Iterator#hasNext()
*/
public boolean hasNext(){
if( next != null )
return true;
while( interalIterator.hasNext() ){
IExtensibleSymbol symbol = (IExtensibleSymbol) interalIterator.next();
if( symbol.getASTExtension() != null ){
next = symbol;
return true;
}
}
return false;
}
/* (non-Javadoc)
* @see java.util.Iterator#next()
*/
public Object next(){
IExtensibleSymbol temp = next;
if( next != null ){
next = null;
return temp.getASTExtension().getPrimaryDeclaration();
}
while( interalIterator.hasNext() ){
temp = (IExtensibleSymbol) interalIterator.next();
if( temp.getASTExtension() != null ){
return temp.getASTExtension().getPrimaryDeclaration();
}
}
throw new NoSuchElementException();
}
/* (non-Javadoc)
* @see java.util.Iterator#remove()
*/
public void remove(){
throw new UnsupportedOperationException();
}
}

View file

@ -268,7 +268,13 @@ public class ASTClassSpecifier extends ASTScope implements IASTClassSpecifier
public Iterator getDeclarations()
{
return declarations.iterator();
//If a callback (ie StructuralParseCallback) populates the declarations list
//then return that iterator, otherwise use the ASTScope implementation which
//gets one from the symbol table.
if( !declarations.isEmpty() ){
return declarations.iterator();
}
return super.getDeclarations();
}
public void addDeclaration(IASTDeclaration declaration)

View file

@ -73,8 +73,15 @@ public class ASTCompilationUnit
public Iterator getDeclarations()
{
return declarations.iterator();
//If a callback (ie StructuralParseCallback) populates the declarations list
//then return that iterator, otherwise use the ASTScope implementation which
//gets one from the symbol table.
if( !declarations.isEmpty() )
return declarations.iterator();
return super.getDeclarations();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);

View file

@ -167,12 +167,19 @@ public class ASTNamespaceDefinition
public Iterator getDeclarations()
{
return declarations.iterator();
//If a callback (ie StructuralParseCallback) populates the declarations list
//then return that iterator, otherwise use the ASTScope implementation which
//gets one from the symbol table.
if( !declarations.isEmpty() )
return declarations.iterator();
return super.getDeclarations();
}
public void addDeclaration(IASTDeclaration declaration)
{
declarations.add(declaration);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTOffsetableElement#getStartingLine()
*/

View file

@ -17,9 +17,10 @@ import java.util.ListIterator;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol;
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;
@ -55,7 +56,7 @@ public class ASTNode implements IASTNode {
}
ISymbolOwner owner = (ISymbolOwner) this;
ISymbol symbol = owner.getSymbol();
IExtensibleSymbol symbol = owner.getSymbol();
if( symbol == null || !(symbol instanceof IContainerSymbol) ){
throw new LookupError();
}
@ -132,28 +133,4 @@ public class ASTNode implements IASTNode {
public Iterator getNodes() { return iterator; }
public int getResultsSize() { return resultsNumber; }
}
private class SymbolIterator implements Iterator{
Iterator interalIterator;
public SymbolIterator( Iterator iter ){
interalIterator = iter;
}
public boolean hasNext() {
return interalIterator.hasNext();
}
public Object next() {
ISymbol nextSymbol = (ISymbol) interalIterator.next();
ISymbolASTExtension extension = (nextSymbol != null ) ? nextSymbol.getASTExtension() : null;
return (extension != null ) ? extension.getPrimaryDeclaration() : null;
}
public void remove() {
interalIterator.remove();
}
}
}

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.ast.SymbolIterator;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
import org.eclipse.cdt.internal.core.parser.pst.ISymbol;
@ -41,6 +42,10 @@ public abstract class ASTScope extends ASTSymbol implements IASTScope
*/
public Iterator getDeclarations()
{
IContainerSymbol symbol = getContainerSymbol();
if( symbol != null ){
return new SymbolIterator( symbol.getContentsIterator() );
}
return null;
}

View file

@ -19,48 +19,28 @@ import java.util.Map;
public class BasicSymbol implements Cloneable, ISymbol
public class BasicSymbol extends ExtensibleSymbol implements ISymbol
{
private final ParserSymbolTable _table;
public BasicSymbol( ParserSymbolTable table, String name ){
super();
this._table = table;
super( table );
_name = name;
_typeInfo = new TypeInfo();
}
public BasicSymbol( ParserSymbolTable table, String name, ISymbolASTExtension obj ){
super();
this._table = table;
super( table, obj );
_name = name;
_object = obj;
_typeInfo = new TypeInfo();
}
public BasicSymbol( ParserSymbolTable table, String name, TypeInfo.eType typeInfo )
{
super();
this._table = table;
super( table );
_name = name;
_typeInfo = new TypeInfo( typeInfo, 0, null );
}
public ParserSymbolTable getSymbolTable(){
return _table;
}
public Object clone(){
BasicSymbol copy = null;
try{
copy = (BasicSymbol)super.clone();
} catch ( CloneNotSupportedException e ){
//should not happen
return null;
}
copy._object = null;
return copy;
}
public ISymbol instantiate( ITemplateSymbol template, Map argMap ) throws ParserSymbolTableException{
if( !isTemplateMember() && !getContainingSymbol().isTemplateMember() ){
return null;
@ -75,12 +55,9 @@ public class BasicSymbol implements Cloneable, ISymbol
public String getName() { return _name; }
public void setName(String name) { _name = name; }
public ISymbolASTExtension getASTExtension() { return _object; }
public void setASTExtension( ISymbolASTExtension obj ) { _object = obj; }
public IContainerSymbol getContainingSymbol() { return _containingScope; }
public void setContainingSymbol( IContainerSymbol scope ){
_containingScope = scope;
super.setContainingSymbol( scope );
_depth = scope.getDepth() + 1;
}
@ -196,9 +173,7 @@ public class BasicSymbol implements Cloneable, ISymbol
}
private String _name; //our name
private ISymbolASTExtension _object; //the object associated with us
private TypeInfo _typeInfo; //our type info
private IContainerSymbol _containingScope; //the scope that contains us
private int _depth; //how far down the scope stack we are
private boolean _isInvisible = false; //used by friend declarations (11.4-9)

View file

@ -22,6 +22,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.cdt.core.parser.ParserMode;
@ -895,9 +897,80 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
}
public Iterator getContentsIterator(){
return getContents().iterator();
//return getContents().iterator();
return new ContentsIterator( getContents().iterator() );
}
protected class ContentsIterator implements Iterator {
final Iterator internalIterator;
Set alreadyReturned = new HashSet();
public ContentsIterator( Iterator iter ){
internalIterator = iter;
}
IExtensibleSymbol next = null;
public boolean hasNext() {
if( next != null ){
return true;
}
if( !internalIterator.hasNext() )
return false;
while( internalIterator.hasNext() ){
IExtensibleSymbol extensible = (IExtensibleSymbol) internalIterator.next();
if( !alreadyReturned.contains( extensible ) ){
if( extensible instanceof ISymbol ){
ISymbol symbol = (ISymbol) extensible;
if( symbol.isForwardDeclaration() && symbol.getTypeSymbol() != null &&
symbol.getTypeSymbol().getContainingSymbol() == ContainerSymbol.this )
{
alreadyReturned.add( symbol.getTypeSymbol() );
next = symbol.getTypeSymbol();
return true;
}
}
next = extensible;
return true;
}
}
return false;
}
public Object next() {
IExtensibleSymbol extensible = next;
if( next != null ){
next = null;
return extensible;
}
while( internalIterator.hasNext() ){
extensible = (IExtensibleSymbol) internalIterator.next();
if( !alreadyReturned.contains( extensible ) ){
if( extensible instanceof ISymbol ){
ISymbol symbol = (ISymbol) extensible;
if( symbol.isForwardDeclaration() && symbol.getTypeSymbol() != null &&
symbol.getTypeSymbol().getContainingSymbol() == ContainerSymbol.this )
{
alreadyReturned.add( symbol.getTypeSymbol() );
return symbol.getTypeSymbol();
}
}
return extensible;
}
}
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException();
}
protected void removeSymbol(){
internalIterator.remove();
}
}
static private class AddSymbolCommand extends Command{
AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){
_symbol = newDecl;
@ -928,11 +1001,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//this is an inefficient way of doing this, we can modify the interfaces if the undo starts
//being used often.
Iterator iter = _context.getContentsIterator();
ContentsIterator iter = (ContentsIterator) _context.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _symbol ){
iter.remove();
iter.removeSymbol();
break;
}
}
@ -952,11 +1025,11 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
//this is an inefficient way of doing this, we can modify the interfaces if the undo starts
//being used often.
Iterator iter = _decl.getContentsIterator();
ContentsIterator iter = (ContentsIterator) _decl.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _directive ){
iter.remove();
iter.removeSymbol();
break;
}
}

View file

@ -394,11 +394,11 @@ public class DerivableContainerSymbol extends ContainerSymbol implements IDeriva
}
}
iter = _context.getContentsIterator();
ContentsIterator contents = (ContentsIterator) _context.getContentsIterator();
while( iter.hasNext() ){
IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
if( ext == _constructor ){
iter.remove();
contents.removeSymbol();
break;
}
}

View file

@ -0,0 +1,73 @@
/*
* Created on Feb 25, 2004
*
* 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.pst;
/**
* @author aniefer
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ExtensibleSymbol implements Cloneable, IExtensibleSymbol {
public ExtensibleSymbol( ParserSymbolTable table ){
_table = table;
}
public ExtensibleSymbol( ParserSymbolTable table, ISymbolASTExtension obj ){
_table = table;
_object = obj;
}
public Object clone(){
ExtensibleSymbol copy = null;
try{
copy = (ExtensibleSymbol)super.clone();
} catch ( CloneNotSupportedException e ){
//should not happen
return null;
}
return copy;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#getSymbolTable()
*/
public ParserSymbolTable getSymbolTable(){
return _table;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#getASTExtension()
*/
public ISymbolASTExtension getASTExtension() {
return _object;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#setASTExtension(org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension)
*/
public void setASTExtension( ISymbolASTExtension obj ) {
_object = obj;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol#getContainingSymbol()
*/
public IContainerSymbol getContainingSymbol() {
return _containingScope;
}
public void setContainingSymbol( IContainerSymbol scope ){
_containingScope = scope;
}
private final ParserSymbolTable _table;
private ISymbolASTExtension _object; //the object associated with us
private IContainerSymbol _containingScope; //the scope that contains us
}

View file

@ -32,4 +32,8 @@ public interface IExtensibleSymbol {
* @param obj
*/
public void setASTExtension( ISymbolASTExtension obj );
public IContainerSymbol getContainingSymbol();
public void setContainingSymbol( IContainerSymbol scope );
}

View file

@ -50,11 +50,6 @@ public class TemplateSymbol extends ParameterizedSymbol implements ITemplateSymb
Iterator iter = getContentsIterator();
if( iter.hasNext() ){
IContainerSymbol contained = (IContainerSymbol) iter.next();
if( contained.isForwardDeclaration() && contained.getTypeSymbol() != null ){
ISymbol symbol = contained.getTypeSymbol();
if( symbol.getContainingSymbol() == this )
return (IContainerSymbol) symbol;
}
return contained;
}
return null;

View file

@ -15,25 +15,17 @@ import java.util.List;
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class UsingDeclarationSymbol implements IUsingDeclarationSymbol {
public class UsingDeclarationSymbol extends ExtensibleSymbol implements IUsingDeclarationSymbol {
public UsingDeclarationSymbol( ParserSymbolTable table, List referenced, List declared ){
super( table );
referencedSymbol = referenced;
declaredSymbol = declared;
symbolTable = table;
}
public List getReferencedSymbols() { return referencedSymbol; }
public List getDeclaredSymbols() { return declaredSymbol; }
public ISymbolASTExtension getASTExtension() { return extension; }
public void setASTExtension( ISymbolASTExtension ext ) { extension = ext; }
public ParserSymbolTable getSymbolTable() { return symbolTable; }
private ISymbolASTExtension extension;
private final List referencedSymbol;
private final List declaredSymbol;
private final ParserSymbolTable symbolTable;
}

View file

@ -11,25 +11,16 @@
package org.eclipse.cdt.internal.core.parser.pst;
public class UsingDirectiveSymbol implements IUsingDirectiveSymbol{
private final ParserSymbolTable symbolTable;
public class UsingDirectiveSymbol extends ExtensibleSymbol implements IUsingDirectiveSymbol{
public UsingDirectiveSymbol( ParserSymbolTable table, IContainerSymbol ns ){
super( table );
namespace = ns;
symbolTable = table;
}
public IContainerSymbol getNamespace(){
return namespace;
}
public ISymbolASTExtension getASTExtension() { return extension; }
public void setASTExtension( ISymbolASTExtension ext ) { extension = ext; }
private ISymbolASTExtension extension;
private final IContainerSymbol namespace;
public ParserSymbolTable getSymbolTable() {
return symbolTable;
}
}