[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] IContainerSymbol contents Iterator
|
This patch implements an iterator on all the contents of IContainerSymbol.
This is a first step to an iterator on the IAST nodes
Core:
Created IExtensibleSymbol, which is a new base class for the
symbol interfaces
Created IUsingDirectiveSymbol and UsingDirectiveSymbol
Modified ASTUsingDirective to use IUsingDirectiveSymbol
Modified CompleteParseASTFactory.createUsingDirective
Added IContainerSymbol.getContentsIterator()
Implemented getContentsIterator in ContainerSymbol
Core.tests:
Modified CompleteParseASTTest.testUsingClauses
Added ParserSymbolTableTest.testIterator_1 & testIterator_2
Tested on windows & linux
-Andrew
Index: parser/ChangeLog-parser
===================================================================
retrieving revision 1.21
diff -u -r1.21 ChangeLog-parser
--- parser/ChangeLog-parser 16 Jan 2004 05:09:01 -0000 1.21
+++ parser/ChangeLog-parser 16 Jan 2004 22:29:33 -0000
@@ -1,3 +1,11 @@
+2004-01-16 Andrew Niefer
+ Created IExtensibleSymbol, which is a new base class for the symbol interfaces
+ Created IUsingDirectiveSymbol and UsingDirectiveSymbol
+ Modified ASTUsingDirective to use IUsingDirectiveSymbol
+ Modified CompleteParseASTFactory.createUsingDirective
+ Added IContainerSymbol.getContentsIterator()
+ Implemented getContentsIterator in ContainerSymbol
+
2004-01-16 John Camelon
Changed IASTNode.LookupException to IASTNode.LookupError.
Updated IASTElaboratedTypeSpecifier to remove redundant extends relationships.
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java
===================================================================
retrieving revision 1.8
diff -u -r1.8 ASTUsingDirective.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java 15 Jan 2004 13:37:53 -0000 1.8
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTUsingDirective.java 16 Jan 2004 22:29:36 -0000
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -17,6 +17,7 @@
import org.eclipse.cdt.core.parser.ast.IASTUsingDirective;
import org.eclipse.cdt.internal.core.parser.ast.Offsets;
import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol;
+import org.eclipse.cdt.internal.core.parser.pst.IUsingDirectiveSymbol;
/**
* @author jcamelon
@@ -24,7 +25,7 @@
*/
public class ASTUsingDirective extends ASTAnonymousDeclaration implements IASTUsingDirective
{
- private final IASTNamespaceDefinition namespace;
+ private final IUsingDirectiveSymbol using;
private Offsets offsets = new Offsets();
private final ASTReferenceStore referenceDelegate;
/**
@@ -32,10 +33,12 @@
* @param startingOffset
* @param endingOffset
*/
- public ASTUsingDirective(IContainerSymbol ownerSymbol, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int endingOffset, List references )
+ //public ASTUsingDirective(IContainerSymbol ownerSymbol, IASTNamespaceDefinition namespaceDefinition, int startingOffset, int endingOffset, List references )
+ public ASTUsingDirective(IContainerSymbol ownerSymbol, IUsingDirectiveSymbol usingDirective, int startingOffset, int endingOffset, List references )
{
super( ownerSymbol );
- namespace = namespaceDefinition;
+ //namespace = namespaceDefinition;
+ using = usingDirective;
setStartingOffset(startingOffset);
setEndingOffset(endingOffset);
referenceDelegate = new ASTReferenceStore( references );
@@ -46,7 +49,8 @@
*/
public String getNamespaceName()
{
- String [] fqn = namespace.getFullyQualifiedName();
+ IASTNamespaceDefinition namespace = getNamespaceDefinition();
+ String [] fqn = namespace.getFullyQualifiedName();
StringBuffer buffer = new StringBuffer();
for( int i = 0; i < fqn.length; ++i )
{
@@ -118,7 +122,9 @@
*/
public IASTNamespaceDefinition getNamespaceDefinition()
{
- return namespace;
+ IContainerSymbol namespaceSymbol = using.getNamespace();
+
+ return (IASTNamespaceDefinition)namespaceSymbol.getASTExtension().getPrimaryDeclaration();
}
}
Index: parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java
===================================================================
retrieving revision 1.66
diff -u -r1.66 CompleteParseASTFactory.java
--- parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 15 Jan 2004 23:06:36 -0000 1.66
+++ parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java 16 Jan 2004 22:29:37 -0000
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -76,6 +76,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.IUsingDirectiveSymbol;
import org.eclipse.cdt.internal.core.parser.pst.NamespaceSymbolExtension;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTable;
import org.eclipse.cdt.internal.core.parser.pst.ParserSymbolTableException;
@@ -326,13 +327,14 @@
ISymbol symbol = lookupQualifiedName(
scopeToSymbol( scope), duple, references, true );
+ IUsingDirectiveSymbol usingDirective = null;
try {
- ((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol );
+ usingDirective = ((ASTScope)scope).getContainerSymbol().addUsingDirective( (IContainerSymbol)symbol );
} catch (ParserSymbolTableException pste) {
throw new ASTSemanticException();
}
- IASTUsingDirective astUD = new ASTUsingDirective( scopeToSymbol(scope), ((IASTNamespaceDefinition)symbol.getASTExtension().getPrimaryDeclaration()), startingOffset, endingOffset, references );
+ IASTUsingDirective astUD = new ASTUsingDirective( scopeToSymbol(scope), usingDirective, startingOffset, endingOffset, references );
return astUD;
}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java
===================================================================
retrieving revision 1.8
diff -u -r1.8 ContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java 15 Jan 2004 23:06:36 -0000 1.8
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java 16 Jan 2004 22:29:38 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
+ * Copyright (c) 2003,2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -139,6 +139,8 @@
obj.setIsTemplateMember( isTemplateMember() || getType() == TypeInfo.t_template );
+ getContents().add( obj );
+
Command command = new AddSymbolCommand( obj, containing );
getSymbolTable().pushCommand( command );
}
@@ -163,7 +165,7 @@
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol#addUsingDirective(org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol)
*/
- public void addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{
+ public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException{
if( namespace.getType() != TypeInfo.t_namespace ){
throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidUsing );
}
@@ -180,10 +182,15 @@
List usingDirectives = getUsingDirectives();
- usingDirectives.add( namespace );
+ IUsingDirectiveSymbol usingDirective = new UsingDirectiveSymbol( getSymbolTable(), namespace );
+ usingDirectives.add( usingDirective );
+
+ getContents().add( usingDirective );
- Command command = new AddUsingDirectiveCommand( this, namespace );
+ Command command = new AddUsingDirectiveCommand( this, usingDirective );
getSymbolTable().pushCommand( command );
+
+ return usingDirective;
}
/* (non-Javadoc)
@@ -749,6 +756,17 @@
return instance;
}
+ protected List getContents(){
+ if(_contents == null ){
+ _contents = new LinkedList();
+ }
+ return _contents;
+ }
+
+ public Iterator getContentsIterator(){
+ return getContents().iterator();
+ }
+
static private class AddSymbolCommand extends Command{
AddSymbolCommand( ISymbol newDecl, IContainerSymbol context ){
_symbol = newDecl;
@@ -776,27 +794,46 @@
} else if( obj instanceof BasicSymbol ){
_context.getContainedSymbols().remove( _symbol.getName() );
}
-// if( _removeThis && _symbol instanceof IParameterizedSymbol ){
-// ((IParameterizedSymbol)_symbol).getContainedSymbols().remove( ParserSymbolTable.THIS );
-// }
+
+ //this is an inefficient way of doing this, we can modify the interfaces if the undo starts
+ //being used often.
+ Iterator iter = _context.getContentsIterator();
+ while( iter.hasNext() ){
+ IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
+ if( ext == _symbol ){
+ iter.remove();
+ break;
+ }
+ }
}
- private ISymbol _symbol;
- private IContainerSymbol _context;
+ private final ISymbol _symbol;
+ private final IContainerSymbol _context;
}
static private class AddUsingDirectiveCommand extends Command{
- public AddUsingDirectiveCommand( IContainerSymbol container, IContainerSymbol namespace ){
+ public AddUsingDirectiveCommand( IContainerSymbol container, IUsingDirectiveSymbol directive ){
_decl = container;
- _namespace = namespace;
+ _directive = directive;
}
public void undoIt(){
- _decl.getUsingDirectives().remove( _namespace );
+ _decl.getUsingDirectives().remove( _directive );
+
+ //this is an inefficient way of doing this, we can modify the interfaces if the undo starts
+ //being used often.
+ Iterator iter = _decl.getContentsIterator();
+ while( iter.hasNext() ){
+ IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
+ if( ext == _directive ){
+ iter.remove();
+ break;
+ }
+ }
}
- private IContainerSymbol _decl;
- private IContainerSymbol _namespace;
+ private final IContainerSymbol _decl;
+ private final IUsingDirectiveSymbol _directive;
}
-
+
static protected class SymbolTableComparator implements Comparator{
public int compare( Object o1, Object o2 ){
int result = ((String) o1).compareToIgnoreCase( (String) o2 );
@@ -810,7 +847,8 @@
return ( obj instanceof SymbolTableComparator );
}
}
-
+
+ private LinkedList _contents; //ordered list of all contents of this symbol
private LinkedList _usingDirectives; //collection of nominated namespaces
private Map _containedSymbols; //declarations contained by us.
Index: parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java
===================================================================
retrieving revision 1.4
diff -u -r1.4 DerivableContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java 8 Jan 2004 16:57:48 -0000 1.4
+++ parser/org/eclipse/cdt/internal/core/parser/pst/DerivableContainerSymbol.java 16 Jan 2004 22:29:39 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -14,9 +14,9 @@
package org.eclipse.cdt.internal.core.parser.pst;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
import org.eclipse.cdt.core.parser.ParserLanguage;
@@ -120,6 +120,8 @@
constructor.setContainingSymbol( this );
addThis( constructor );
+ getContents().add( constructor );
+
Command command = new AddConstructorCommand( constructor, this );
getSymbolTable().pushCommand( command );
}
@@ -335,7 +337,7 @@
}
public void undoIt(){
List constructors = _context.getConstructors();
- ListIterator iter = constructors.listIterator();
+ Iterator iter = constructors.listIterator();
int size = constructors.size();
IParameterizedSymbol item = null;
@@ -346,10 +348,19 @@
break;
}
}
+
+ iter = _context.getContentsIterator();
+ while( iter.hasNext() ){
+ IExtensibleSymbol ext = (IExtensibleSymbol) iter.next();
+ if( ext == _constructor ){
+ iter.remove();
+ break;
+ }
+ }
}
- private IParameterizedSymbol _constructor;
- private IDerivableContainerSymbol _context;
+ private final IParameterizedSymbol _constructor;
+ private final IDerivableContainerSymbol _context;
}
public class ParentWrapper implements IDerivableContainerSymbol.IParentSymbol
Index: parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java
===================================================================
retrieving revision 1.10
diff -u -r1.10 IContainerSymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java 10 Dec 2003 00:07:26 -0000 1.10
+++ parser/org/eclipse/cdt/internal/core/parser/pst/IContainerSymbol.java 16 Jan 2004 22:29:39 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@
*/
package org.eclipse.cdt.internal.core.parser.pst;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -32,7 +33,7 @@
public boolean hasUsingDirectives();
public List getUsingDirectives();
- public void addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException;
+ public IUsingDirectiveSymbol addUsingDirective( IContainerSymbol namespace ) throws ParserSymbolTableException;
public ISymbol addUsingDeclaration( String name ) throws ParserSymbolTableException;
public ISymbol addUsingDeclaration( String name, IContainerSymbol declContext ) throws ParserSymbolTableException;
@@ -55,4 +56,6 @@
public TemplateInstance instantiate( List arguments ) throws ParserSymbolTableException;
public boolean isVisible( ISymbol symbol, IContainerSymbol qualifyingSymbol );
+
+ public Iterator getContentsIterator();
}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java
===================================================================
retrieving revision 1.10
diff -u -r1.10 ISymbol.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java 17 Dec 2003 20:51:39 -0000 1.10
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ISymbol.java 16 Jan 2004 22:29:39 -0000
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * Copyright (c) 2002,2003, 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -17,15 +17,11 @@
* @author jcamelon
*
*/
-public interface ISymbol extends Cloneable {
+public interface ISymbol extends Cloneable, IExtensibleSymbol {
- public ParserSymbolTable getSymbolTable();
-
public Object clone();
- public ISymbolASTExtension getASTExtension();
- public void setASTExtension( ISymbolASTExtension obj );
-
+ public void setName(String name);
public String getName();
public IContainerSymbol getContainingSymbol();
@@ -56,9 +52,4 @@
public int getDepth();
public boolean getIsInvisible();
public void setIsInvisible( boolean invisible );
-
- /**
- * @param name
- */
- public void setName(String name);
}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java
===================================================================
retrieving revision 1.35
diff -u -r1.35 ParserSymbolTable.java
--- parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 15 Jan 2004 23:06:36 -0000 1.35
+++ parser/org/eclipse/cdt/internal/core/parser/pst/ParserSymbolTable.java 16 Jan 2004 22:29:40 -0000
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * Copyright (c) 2002,2003,2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -243,7 +243,7 @@
//only consider the transitive using directives if we are an unqualified
//lookup, or we didn't find the name in decl
- if( (!data.qualified || !foundSomething || data.mode == LookupMode.PREFIX ) && temp.getUsingDirectives() != null ){
+ if( (!data.qualified || !foundSomething || data.mode == LookupMode.PREFIX ) && temp.hasUsingDirectives() ){
//name wasn't found, add transitive using directives for later consideration
transitiveDirectives.addAll( temp.getUsingDirectives() );
}
@@ -1091,7 +1091,7 @@
Iterator iter = directives.iterator();
for( int i = size; i > 0; i-- ){
- temp = (IContainerSymbol) iter.next();
+ temp = ((IUsingDirectiveSymbol) iter.next()).getNamespace();
//namespaces are searched at most once
if( !data.visited.contains( temp ) ){
Index: parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java
diff -N parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/pst/IExtensibleSymbol.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,35 @@
+/**********************************************************************
+ * Copyright (c) 2004 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+
+package org.eclipse.cdt.internal.core.parser.pst;
+
+/**
+ * @author aniefer
+ */
+public interface IExtensibleSymbol {
+ /**
+ * get the instance of ParserSymbolTable with wich this symbol is associated
+ * @return ParserSymbolTable
+ */
+ public ParserSymbolTable getSymbolTable();
+
+ /**
+ * get the ISymbolASTExtension attached to this symbol
+ * @return ISymbolASTExtension
+ */
+ public ISymbolASTExtension getASTExtension();
+
+ /**
+ * attach an ISymbolASTExtension to this symbol
+ * @param obj
+ */
+ public void setASTExtension( ISymbolASTExtension obj );
+}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java
diff -N parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/pst/IUsingDirectiveSymbol.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,16 @@
+/**********************************************************************
+ * Copyright (c) 2004 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.internal.core.parser.pst;
+
+
+public interface IUsingDirectiveSymbol extends IExtensibleSymbol{
+ public IContainerSymbol getNamespace();
+}
Index: parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java
diff -N parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/parser/pst/UsingDirectiveSymbol.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,35 @@
+/**********************************************************************
+ * Copyright (c) 2004 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.internal.core.parser.pst;
+
+
+public class UsingDirectiveSymbol implements IUsingDirectiveSymbol{
+ private final ParserSymbolTable symbolTable;
+
+ public UsingDirectiveSymbol( ParserSymbolTable table, IContainerSymbol ns ){
+ 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;
+ }
+}
Index: ChangeLog
===================================================================
retrieving revision 1.168
diff -u -r1.168 ChangeLog
--- ChangeLog 16 Jan 2004 20:18:52 -0000 1.168
+++ ChangeLog 16 Jan 2004 22:32:56 -0000
@@ -1,3 +1,7 @@
+2004-01-16 Andrew Niefer
+ Modified CompleteParseASTTest.testUsingClauses
+ Added ParserSymbolTableTest.testIterator_1 & testIterator_2
+
2004-01-16 Hoda Amer
Modified CModelElementsTest to test for enumerator constant expression
Bug#47552
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
retrieving revision 1.49
diff -u -r1.49 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 15 Jan 2004 23:06:50 -0000 1.49
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java 16 Jan 2004 22:32:59 -0000
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * Copyright (c) 2002,2003,2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -194,6 +194,7 @@
assertQualifiedName( fieldY.getFullyQualifiedName(), new String [] { "A", "B", "C", "y" } );
IASTUsingDirective directive = (IASTUsingDirective)declarations.next();
assertEquals( directive.getNamespaceDefinition(), namespaceB );
+ assertEquals( directive.getNamespaceName(), "A::B" );
IASTUsingDeclaration declaration = (IASTUsingDeclaration)declarations.next();
assertEquals( declaration.getUsingType(), variableX );
declaration = (IASTUsingDeclaration)declarations.next();
Index: parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java
===================================================================
retrieving revision 1.31
diff -u -r1.31 ParserSymbolTableTest.java
--- parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java 15 Jan 2004 23:06:50 -0000 1.31
+++ parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java 16 Jan 2004 22:33:00 -0000
@@ -37,6 +37,7 @@
import org.eclipse.cdt.internal.core.parser.pst.IParameterizedSymbol;
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.IUsingDirectiveSymbol;
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.StandardSymbolExtension;
@@ -3433,6 +3434,126 @@
ISymbol look = table.getCompilationUnit().unqualifiedFunctionLookup( "foo", params );
assertEquals( foo1, look );
+ }
+
+ /**
+ * int global;
+ * class A {
+ * A();
+ * int var;
+ * void foo();
+ * };
+ *
+ */
+ public void testIterator_1() throws Exception{
+ newTable();
+
+ ISymbol global = table.newSymbol( "global", TypeInfo.t_int );
+ table.getCompilationUnit().addSymbol( global );
+
+ IDerivableContainerSymbol cls = table.newDerivableContainerSymbol( "A", TypeInfo.t_class );
+
+ table.getCompilationUnit().addSymbol( cls );
+
+ IParameterizedSymbol constructor = table.newParameterizedSymbol( "A", TypeInfo.t_constructor );
+ cls.addConstructor( constructor );
+
+ ISymbol var = table.newSymbol( "var", TypeInfo.t_int );
+ cls.addSymbol( var );
+
+ IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", TypeInfo.t_function );
+ cls.addSymbol( foo );
+
+
+ Iterator iter = table.getCompilationUnit().getContentsIterator();
+ assertEquals( iter.next(), global );
+ IContainerSymbol symbol = (IContainerSymbol) iter.next();
+ assertEquals( symbol, cls );
+ assertFalse( iter.hasNext() );
+
+ iter = symbol.getContentsIterator();
+ assertEquals( iter.next(), constructor );
+ assertEquals( iter.next(), var );
+ assertEquals( iter.next(), foo );
+ assertFalse( iter.hasNext() );
+ }
+
+ /**
+ * int foo();
+ * namespace A{
+ * int bar();
+ * int bar( int );
+ * };
+ * class B{
+ * void func(){
+ * using namespace A;
+ * }
+ * };
+ * @throws Exception
+ */
+ public void testIterator_2() throws Exception{
+ newTable();
+
+ IParameterizedSymbol foo = table.newParameterizedSymbol( "foo", TypeInfo.t_function );
+ table.getCompilationUnit().addSymbol( foo );
+
+ IContainerSymbol nsA = table.newContainerSymbol( "A", TypeInfo.t_namespace );
+ table.getCompilationUnit().addSymbol( nsA );
+
+ IParameterizedSymbol bar1 = table.newParameterizedSymbol( "bar", TypeInfo.t_function );
+ nsA.addSymbol( bar1 );
+
+ IParameterizedSymbol bar2 = table.newParameterizedSymbol( "bar", TypeInfo.t_function );
+ bar2.addParameter( TypeInfo.t_int, 0, null, false );
+ nsA.addSymbol( bar2 );
+
+ IDerivableContainerSymbol B = table.newDerivableContainerSymbol("B", TypeInfo.t_class);
+ table.getCompilationUnit().addSymbol( B );
+
+ B.addCopyConstructor();
+
+ IParameterizedSymbol func = table.newParameterizedSymbol( "func", TypeInfo.t_function );
+ B.addSymbol( func );
+
+ IUsingDirectiveSymbol using = func.addUsingDirective( nsA );
+
+ Iterator iter = table.getCompilationUnit().getContentsIterator();
+
+ assertEquals( iter.next(), foo );
+
+ IContainerSymbol s1 = (IContainerSymbol) iter.next();
+ assertEquals( s1, nsA );
+
+ IContainerSymbol s2 = (IContainerSymbol) iter.next();
+ assertEquals( s2, B );
+
+ assertFalse( iter.hasNext() );
+
+ iter = s1.getContentsIterator();
+ assertEquals( iter.next(), bar1 );
+ assertEquals( iter.next(), bar2 );
+ assertFalse( iter.hasNext() );
+
+ iter = s2.getContentsIterator();
+
+ //Copy constructor!!
+ ISymbol copy = (ISymbol) iter.next();
+ assertTrue( copy instanceof IParameterizedSymbol );
+ assertEquals( copy.getName(), "B" );
+ assertEquals( copy.getType(), TypeInfo.t_constructor );
+
+ assertEquals( iter.next(), func );
+ assertFalse( iter.hasNext() );
+
+ iter = func.getContentsIterator();
+ //this pointer!!
+ ISymbol th = (ISymbol) iter.next();
+ assertEquals( th.getName(), "this" );
+ assertEquals( th.getTypeSymbol(), B );
+
+ assertEquals( iter.next(), using );
+
+ assertFalse( iter.hasNext() );
}
}