diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 801cebf645e..635bcc4da3b 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,8 @@ +2004-04-21 Andrew Niefer + fox bugs 52695 & 45372 + added parser/CompleteParseASTSymbolIteratorTest.testUsingDirectives() + added parser/CompleteParseASTSymbolIteratorTest.testUsingDeclaration() + 2004-04-21 John Camelon Removed unused testInclusions() test from ScannerTestCase. diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java index 37cd90245fe..5d7445f2d59 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTSymbolIteratorTest.java @@ -30,8 +30,9 @@ 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.IASTTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.internal.core.parser.ParserException; @@ -334,4 +335,21 @@ public class CompleteParseASTSymbolIteratorTest extends CompleteParseBaseTest { assertFalse( i.hasNext() ); } + public void testUsingDirectives() throws Exception + { + Iterator i = parse( "namespace NS { int i; } using namespace NS;" ).getDeclarations(); + + IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next(); + IASTUsingDirective using = (IASTUsingDirective) i.next(); + assertFalse( i.hasNext() ); + } + + public void testUsingDeclaration() throws Exception + { + Iterator i = parse( "namespace NS{ void f(); void f( int ); }; using NS::f;" ).getDeclarations(); + + IASTNamespaceDefinition ns = (IASTNamespaceDefinition) i.next(); + IASTUsingDeclaration using = (IASTUsingDeclaration) i.next(); + assertFalse( i.hasNext() ); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog-parser b/core/org.eclipse.cdt.core/parser/ChangeLog-parser index cfba267874e..7bffeb7a4c2 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog-parser +++ b/core/org.eclipse.cdt.core/parser/ChangeLog-parser @@ -1,3 +1,10 @@ +2004-04-21 Andrew Niefer + fixing 52695 & 45372 + - updated CompleteParseASTFactory.createUsingDirective & createUsingDeclaration + - added CompleteParseASTFactory.attachSymbolExtension( IExtensibleSymbol symbol, ASTNode astNode ) + - updated ContainerSymbol.addUsingDeclaration + - modified ISymbolASTExtension and added ExtensibleSymbolExtension.java + 2004-04-21 John Camelon Partial fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=59468 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java index 2c3dac383f2..dadb3fc08ea 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/SymbolIterator.java @@ -1,8 +1,15 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ /* * 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; @@ -13,9 +20,6 @@ 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 { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java index 06d2a14980f..b5305954979 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateDeclaration.java @@ -87,7 +87,8 @@ public class ASTTemplateDeclaration extends ASTSymbol implements IASTTemplateDec { IContainerSymbol owned = getTemplateSymbol().getTemplatedSymbol(); if( owned != null && owned.getASTExtension() != null ){ - return owned.getASTExtension().getPrimaryDeclaration(); + ASTNode node = owned.getASTExtension().getPrimaryDeclaration(); + return ( node instanceof IASTDeclaration ) ? (IASTDeclaration)node : null; } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java index ada3c3fac7c..8dea73bc924 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTTemplateSpecialization.java @@ -33,8 +33,10 @@ public class ASTTemplateSpecialization extends ASTTemplateDeclaration implements public IASTDeclaration getOwnedDeclaration() { - if( owned != null && owned.getASTExtension() != null ) - return owned.getASTExtension().getPrimaryDeclaration(); + if( owned != null && owned.getASTExtension() != null ){ + ASTNode node = owned.getASTExtension().getPrimaryDeclaration(); + return ( node instanceof IASTDeclaration ) ? (IASTDeclaration)node : null; + } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java index b15ce6682a6..2fde29a715f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/CompleteParseASTFactory.java @@ -75,10 +75,12 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter.ParamKind; import org.eclipse.cdt.core.parser.extension.IASTFactoryExtension; import org.eclipse.cdt.internal.core.parser.ast.BaseASTFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; +import org.eclipse.cdt.internal.core.parser.pst.ExtensibleSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.ForewardDeclaredSymbolExtension; import org.eclipse.cdt.internal.core.parser.pst.IContainerSymbol; import org.eclipse.cdt.internal.core.parser.pst.IDeferredTemplateInstance; import org.eclipse.cdt.internal.core.parser.pst.IDerivableContainerSymbol; +import org.eclipse.cdt.internal.core.parser.pst.IExtensibleSymbol; 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; @@ -469,7 +471,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto handleProblem( pste.createProblemID(), duple.toString(), startingOffset, endingOffset, startingLine ); } - return new ASTUsingDirective( scopeToSymbol(scope), usingDirective, startingOffset, startingLine, endingOffset, endingLine, references ); + ASTUsingDirective using = new ASTUsingDirective( scopeToSymbol(scope), usingDirective, startingOffset, startingLine, endingOffset, endingLine, references ); + attachSymbolExtension( usingDirective, using ); + + return using; } @@ -547,9 +552,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto addReference( references, reference ); } } - - return new ASTUsingDeclaration( scope, name.getLastToken().getImage(), - endResult.getReferencedSymbols(), isTypeName, startingOffset, startingLine, endingOffset, endingLine, references ); + ASTUsingDeclaration using = new ASTUsingDeclaration( scope, name.getLastToken().getImage(), + endResult.getReferencedSymbols(), isTypeName, startingOffset, startingLine, endingOffset, endingLine, references ); + attachSymbolExtension( endResult, using ); + + return using; } /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.ast.IASTFactory#createASMDefinition(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, int, int) @@ -626,6 +633,11 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return compilationUnit; } + protected void attachSymbolExtension( IExtensibleSymbol symbol, ASTNode astNode ) + { + ISymbolASTExtension extension = new ExtensibleSymbolExtension( symbol, astNode ); + symbol.setASTExtension( extension ); + } protected void attachSymbolExtension( ISymbol symbol, @@ -902,7 +914,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto return new ASTEnumeratorReference( offset, referenceElementName, (IASTEnumerator)symbol.getASTExtension().getPrimaryDeclaration() ); else if(( symbol.getType() == TypeInfo.t_function ) || (symbol.getType() == TypeInfo.t_constructor)) { - ASTSymbol referenced = symbol.getASTExtension().getPrimaryDeclaration(); + ASTNode referenced = symbol.getASTExtension().getPrimaryDeclaration(); if( referenced instanceof IASTMethod ) return new ASTMethodReference( offset, referenceElementName, (IASTMethod)referenced ); else @@ -936,7 +948,7 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto } else { - ASTSymbol s = symbol.getASTExtension().getPrimaryDeclaration(); + ASTNode s = symbol.getASTExtension().getPrimaryDeclaration(); if(s instanceof IASTVariable) return new ASTVariableReference( offset, referenceElementName, (IASTVariable)s); else if (s instanceof IASTParameterDeclaration) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java index 582a3535e3c..75876e28800 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/AbstractSymbolExtension.java @@ -10,6 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.pst; +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNode; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; /** @@ -38,7 +39,11 @@ public abstract class AbstractSymbolExtension implements ISymbolASTExtension return symbol; } - public ASTSymbol getPrimaryDeclaration() + public IExtensibleSymbol getExtensibleSymbol(){ + return symbol; + } + + public ASTNode getPrimaryDeclaration() { return primaryDeclaration; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java index a5419d1e661..d5994762353 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ContainerSymbol.java @@ -394,8 +394,15 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { List usingDecs = new LinkedList(); List usingRefs = new LinkedList(); + UsingDeclarationSymbol usingDeclaration = new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs ); + boolean addedUsingToContained = false; + while( symbol != null ){ if( ParserSymbolTable.okToAddUsingDeclaration( symbol, this ) ){ + if( ! addedUsingToContained ){ + getContents().add( usingDeclaration ); + addedUsingToContained = true; + } clone = (ISymbol) symbol.clone(); //7.3.3-9 addSymbol( clone ); } else { @@ -412,7 +419,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { } } - return new UsingDeclarationSymbol( getSymbolTable(), usingRefs, usingDecs ); + return usingDeclaration; } /* (non-Javadoc) @@ -992,6 +999,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { next = symbol.getTypeSymbol(); return true; } + } else if( extensible instanceof IUsingDeclarationSymbol ){ + IUsingDeclarationSymbol using = (IUsingDeclarationSymbol) extensible; + alreadyReturned.addAll( using.getDeclaredSymbols() ); } next = extensible; return true; @@ -1018,6 +1028,9 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol { alreadyReturned.add( symbol.getTypeSymbol() ); return symbol.getTypeSymbol(); } + } else if( extensible instanceof IUsingDeclarationSymbol ){ + IUsingDeclarationSymbol using = (IUsingDeclarationSymbol) extensible; + alreadyReturned.addAll( using.getDeclaredSymbols() ); } return extensible; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java new file mode 100644 index 00000000000..b128fbf3fca --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ExtensibleSymbolExtension.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ +/* + * Created on Apr 21, 2004 + */ +package org.eclipse.cdt.internal.core.parser.pst; + +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.IASTNode; +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNode; +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; + +/** + * @author aniefer + */ +public class ExtensibleSymbolExtension implements ISymbolASTExtension { + protected final IExtensibleSymbol extensibleSymbol; + protected final ASTNode primaryDeclaration; + + public ExtensibleSymbolExtension( IExtensibleSymbol symbol, IASTNode node ){ + primaryDeclaration = (ASTNode) node; + extensibleSymbol = symbol; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getPrimaryDeclaration() + */ + public ASTNode getPrimaryDeclaration() { + return primaryDeclaration; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#getAllDefinitions() + */ + public Iterator getAllDefinitions() { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolASTExtension#addDefinition(org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol) + */ + public void addDefinition(ASTSymbol definition) throws ExtensionException { + // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.pst.ISymbolOwner#getSymbol() + */ + public ISymbol getSymbol() { + if( extensibleSymbol instanceof ISymbol ) + return (ISymbol) extensibleSymbol; + else + return null; + } + + public IExtensibleSymbol getExtensibleSymbol(){ + return extensibleSymbol; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java index 9555a4d633d..ccbe6099b5a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/ISymbolASTExtension.java @@ -10,8 +10,10 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser.pst; + import java.util.Iterator; +import org.eclipse.cdt.internal.core.parser.ast.complete.ASTNode; import org.eclipse.cdt.internal.core.parser.ast.complete.ASTSymbol; /** @@ -25,7 +27,8 @@ public interface ISymbolASTExtension extends ISymbolOwner } - public ASTSymbol getPrimaryDeclaration(); + public ASTNode getPrimaryDeclaration(); + public IExtensibleSymbol getExtensibleSymbol(); public Iterator getAllDefinitions(); public void addDefinition( ASTSymbol definition ) throws ExtensionException; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java index 7886bd0711d..dc91468dcf4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/pst/UsingDeclarationSymbol.java @@ -1,8 +1,15 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Corp. - Rational Software - initial implementation + ******************************************************************************/ /* * Created on Feb 18, 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; @@ -11,9 +18,6 @@ import java.util.List; /** * @author aniefer - * - * To change the template for this generated type comment go to - * Window - Preferences - Java - Code Generation - Code and Comments */ public class UsingDeclarationSymbol extends ExtensibleSymbol implements IUsingDeclarationSymbol {