Improved robustness of global scope handling.
authorSergey Prigogin <eclipse.sprigogin@gmail.com>
Mon, 8 Jun 2015 19:44:29 +0000 (12:44 -0700)
committerSergey Prigogin <eclipse.sprigogin@gmail.com>
Tue, 9 Jun 2015 18:58:47 +0000 (11:58 -0700)
Change-Id: Id0222766e8c5e258f866f9a4c8b3307a06bdf4c7

34 files changed:
core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/Bug246129.java
core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/ClassTests.java
core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/AbstractCPPClassSpecializationScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClosureType.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUnknownTypeScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/LookupData.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/SemanticUtil.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CompositeCCompositeScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPClassSpecializationScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPEnumScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMGlobalScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassSpecializationScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPEnumScope.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java
core/org.eclipse.cdt.core/pom.xml
core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTManager.java
core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameClassProcessor.java
lrparser/org.eclipse.cdt.core.lrparser/old/org/eclipse/cdt/internal/core/dom/lrparser/c99/bindings/C99Scope.java

index 3de57ae..d12bf9a 100644 (file)
@@ -29,8 +29,6 @@ import java.io.StringReader;
 import java.util.Arrays;
 import java.util.HashSet;
 
-import junit.framework.TestSuite;
-
 import org.eclipse.cdt.core.dom.IName;
 import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
@@ -153,6 +151,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
 import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
 import org.eclipse.cdt.internal.core.parser.ParserException;
 
+import junit.framework.TestSuite;
+
 public class AST2CPPTests extends AST2TestBase {
 
        public AST2CPPTests() {
@@ -3408,16 +3408,16 @@ public class AST2CPPTests extends AST2TestBase {
                ICPPVariable v2 = (ICPPVariable) col.getName(3).resolveBinding();
 
                String[] s = v1.getQualifiedName();
-               assertEquals(s[0], "v1");
+               assertEquals("v1", s[0]);
                assertFalse(v1.isGloballyQualified());
 
                s = v2.getQualifiedName();
-               assertEquals(s[0], "v2");
+               assertEquals("v2", s[0]);
                assertFalse(v2.isGloballyQualified());
 
                ICPPBlockScope scope = (ICPPBlockScope) v2.getScope();
-               IBinding[] bs = scope.find("v1");
-               assertEquals(bs.length, 1);
+               IBinding[] bs = scope.find("v1", tu);
+               assertEquals(1, bs.length);
                assertSame(bs[0], v1);
        }
 
@@ -3437,17 +3437,17 @@ public class AST2CPPTests extends AST2TestBase {
                ICPPMethod f = (ICPPMethod) col.getName(7).resolveBinding();
 
                IScope scope = f.getFunctionScope();
-               IBinding[] bs = scope.find("a");
-               assertEquals(bs.length, 1);
+               IBinding[] bs = scope.find("a", tu);
+               assertEquals(1, bs.length);
                assertSame(bs[0], a);
 
-               bs = scope.find("~B");
-               assertEquals(bs.length, 1);
+               bs = scope.find("~B", tu);
+               assertEquals(1, bs.length);
                assertTrue(bs[0] instanceof ICPPMethod);
                assertTrue(bs[0].getName().equals("~B"));
 
-               bs = scope.find("A");
-               assertEquals(bs.length, 1);
+               bs = scope.find("A", tu);
+               assertEquals(1, bs.length);
                assertSame(bs[0], A);
        }
 
@@ -3470,16 +3470,16 @@ public class AST2CPPTests extends AST2TestBase {
 
                IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(5).getParent().getParent();
                IScope scope = ((IASTCompoundStatement) def.getBody()).getScope();
-               IBinding[] bs = scope.find("f");
+               IBinding[] bs = scope.find("f", tu);
                assertEquals(3, bs.length);
                assertSame(bs[0], f3);
                assertSame(bs[1], f1);
                assertSame(bs[2], f2);
 
                String[] s = ((ICPPBinding)  bs[1]).getQualifiedName();
-               assertEquals(s.length, 2);
-               assertEquals(s[0], "A");
-               assertEquals(s[1], "f");
+               assertEquals(2, s.length);
+               assertEquals("A", s[0]);
+               assertEquals("f", s[1]);
                assertTrue(((ICPPBinding)  bs[1]).isGloballyQualified());
        }
 
@@ -3508,7 +3508,7 @@ public class AST2CPPTests extends AST2TestBase {
 
                IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(8).getParent().getParent();
                IScope scope = ((IASTCompoundStatement) def.getBody()).getScope();
-               IBinding[] bs = scope.find("f");
+               IBinding[] bs = scope.find("f", tu);
                assertEquals(3, bs.length);
                assertSame(bs[0], f);
                assertSame(bs[1], f1);
@@ -3533,21 +3533,21 @@ public class AST2CPPTests extends AST2TestBase {
                IFunction f1 = (IFunction) col.getName(6).resolveBinding();
                IScope classScope= f1.getScope();
                assertTrue(classScope instanceof ICPPClassScope);
-               IBinding[] bindings = classScope.find("bf");
+               IBinding[] bindings = classScope.find("bf", tu);
                ICPPMethod method= extractSingleMethod(bindings);
-               assertEquals(method.getQualifiedName()[0], "B");
+               assertEquals("B", method.getQualifiedName()[0]);
 
-               bindings= classScope.find("f");
+               bindings= classScope.find("f", tu);
                method= extractSingleMethod(bindings);
-               assertEquals(method.getQualifiedName()[0], "A");
+               assertEquals("A", method.getQualifiedName()[0]);
 
-               bindings= classScope.find("B");
+               bindings= classScope.find("B", tu);
                ICPPClassType classType= extractSingleClass(bindings);
-               assertEquals(classType.getQualifiedName()[0], "B");
+               assertEquals("B", classType.getQualifiedName()[0]);
 
-               bindings= classScope.find("A");
+               bindings= classScope.find("A", tu);
                classType= extractSingleClass(bindings);
-               assertEquals(classType.getQualifiedName()[0], "A");
+               assertEquals("A", classType.getQualifiedName()[0]);
        }
 
        // class A {
@@ -3571,39 +3571,39 @@ public class AST2CPPTests extends AST2TestBase {
                ICPPMethod fb = (ICPPMethod) col.getName(6).resolveBinding();
 
                Object[] result = B.getDeclaredFields();
-               assertEquals(result.length, 1);
+               assertEquals(1, result.length);
                assertSame(result[0], b);
 
                result = B.getFields();
-               assertEquals(result.length, 2);
+               assertEquals(2, result.length);
                assertSame(result[0], b);
                assertSame(result[1], a);
 
                result = B.getDeclaredMethods();
-               assertEquals(result.length, 1);
+               assertEquals(1, result.length);
                assertSame(result[0], fb);
 
                result = B.getAllDeclaredMethods();
-               assertEquals(result.length, 2);
+               assertEquals(2, result.length);
                assertSame(result[0], fb);
                assertSame(result[1], fa);
 
                ICPPMethod[] B_implicit = ((ICPPClassScope) B.getCompositeScope()).getImplicitMethods();
-               assertEquals(B_implicit.length, 4);
+               assertEquals(4, B_implicit.length);
                assertTrue(B_implicit[0].getName().equals("B"));
                assertTrue(B_implicit[1].getName().equals("B"));
                assertTrue(B_implicit[2].getName().equals("operator ="));
                assertTrue(B_implicit[3].getName().equals("~B"));
 
                ICPPMethod[] A_implicit = ((ICPPClassScope) A.getCompositeScope()).getImplicitMethods();
-               assertEquals(A_implicit.length, 4);
+               assertEquals(4, A_implicit.length);
                assertTrue(A_implicit[0].getName().equals("A"));
                assertTrue(A_implicit[1].getName().equals("A"));
                assertTrue(A_implicit[2].getName().equals("operator ="));
                assertTrue(A_implicit[3].getName().equals("~A"));
 
                result = B.getMethods();
-               assertEquals(result.length, 10);
+               assertEquals(10, result.length);
                assertSame(result[0], fb);
                assertSame(result[1], B_implicit[0]);
                assertSame(result[2], B_implicit[1]);
@@ -3617,8 +3617,7 @@ public class AST2CPPTests extends AST2TestBase {
        }
 
        public void testBug87424() throws Exception {
-               IASTTranslationUnit tu = parse(
-                               "int * __restrict x;", CPP, true);
+               IASTTranslationUnit tu = parse("int * __restrict x;", CPP, true);
                NameCollector col = new NameCollector();
                tu.accept(col);
 
@@ -3638,8 +3637,7 @@ public class AST2CPPTests extends AST2TestBase {
        }
 
        public void testBug87705() throws Exception {
-               IASTTranslationUnit tu = parse(
-                               "class A { friend class B::C; };", CPP, true);
+               IASTTranslationUnit tu = parse("class A { friend class B::C; };", CPP, true);
                NameCollector col = new NameCollector();
                tu.accept(col);
 
@@ -3659,8 +3657,7 @@ public class AST2CPPTests extends AST2TestBase {
        }
 
        public void testBug88501_1() throws Exception {
-               IASTTranslationUnit tu = parse(
-                               "void f(); void f(int); struct f;", CPP);
+               IASTTranslationUnit tu = parse("void f(); void f(int); struct f;", CPP);
                NameCollector col = new NameCollector();
                tu.accept(col);
 
@@ -3679,7 +3676,6 @@ public class AST2CPPTests extends AST2TestBase {
        // IProblemBinding p = (IProblemBinding) col.getName(1).resolveBinding();
        // assertEquals(p.getID(), IProblemBinding.SEMANTIC_INVALID_REDEFINITION);
        // }
-
        public void testBug8342_2() throws Exception {
                IASTTranslationUnit tu = parse("extern int a; extern char a;", CPP);
                NameCollector col = new NameCollector();
@@ -3770,7 +3766,7 @@ public class AST2CPPTests extends AST2TestBase {
                IFunction f2 = (IFunction) col.getName(3).resolveBinding();
 
                IScope scope = tu.getScope();
-               IBinding[] bs = scope.find("f");
+               IBinding[] bs = scope.find("f", tu);
                assertEquals(bs.length, 2);
                assertSame(bs[0], f1);
                assertSame(bs[1], f2);
index dc1c57f..fdd1a79 100644 (file)
@@ -20,8 +20,6 @@ import static org.eclipse.cdt.core.parser.ParserLanguage.CPP;
 
 import java.io.IOException;
 
-import junit.framework.TestSuite;
-
 import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
 import org.eclipse.cdt.core.dom.ast.ASTVisitor;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
@@ -132,6 +130,8 @@ import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
 import org.eclipse.cdt.internal.core.model.ASTStringUtil;
 import org.eclipse.cdt.internal.core.parser.ParserException;
 
+import junit.framework.TestSuite;
+
 /**
  * Test cases on the AST.
  */
@@ -3080,8 +3080,7 @@ public class AST2Tests extends AST2TestBase {
        }
 
        public void testBug90253() throws Exception {
-               IASTTranslationUnit tu = parse(
-                               "void f(int par) { int v1; };", C); //$NON-NLS-1$
+               IASTTranslationUnit tu = parse("void f(int par) { int v1; };", C); //$NON-NLS-1$
                NameCollector col = new NameCollector();
                tu.accept(col);
 
@@ -3092,11 +3091,11 @@ public class AST2Tests extends AST2TestBase {
                IASTFunctionDefinition fdef= getDeclaration(tu, 0);
                IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope();
 
-               IBinding[] bs = scope.find("par"); //$NON-NLS-1$
+               IBinding[] bs = scope.find("par", tu); //$NON-NLS-1$
                assertEquals(1, bs.length);
                assertSame(bs[0], p);
 
-               bs = scope.find("v1"); //$NON-NLS-1$
+               bs = scope.find("v1", tu); //$NON-NLS-1$
                assertEquals(bs.length, 1);
                assertSame(bs[0], v1);
        }
@@ -3123,7 +3122,7 @@ public class AST2Tests extends AST2TestBase {
                IASTFunctionDefinition fdef= getDeclaration(tu, 2);
                IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope();
 
-               IBinding[] bs = scope.find("S"); //$NON-NLS-1$
+               IBinding[] bs = scope.find("S", tu); //$NON-NLS-1$
 
                assertNotNull(S2);
                assertEquals(bs.length, 3);
index d3d6044..e251865 100644 (file)
@@ -6,15 +6,13 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    Markus Schorn - initial API and implementation
- *******************************************************************************/ 
+ *     Markus Schorn - initial API and implementation
+ *******************************************************************************/
 package org.eclipse.cdt.internal.index.tests;
 
 import java.io.File;
 import java.io.FileWriter;
 
-import junit.framework.TestSuite;
-
 import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
 import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@@ -36,6 +34,8 @@ import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
 
+import junit.framework.TestSuite;
+
 public class Bug246129 extends IndexTestBase {
 
        public static TestSuite suite() {
@@ -45,29 +45,18 @@ public class Bug246129 extends IndexTestBase {
        }
 
        private ICProject fProject;
-
-       private IFile fSource; 
-       
+       private IFile fSource;
        private IFolder fWrapperIncludeFolder;
-
        private IFolder fIncludeFolder;
-       
        private File fTmpDir;
-       
        private File fExternalWrapperIncludeFolder;
-
        private File fExternalWrapperHeader;
-       
        private File fExternalIncludeFolder;
-       
        private File fExternalHeader;
-       
        private File fExternalExtFolder;
-       
        IIndex fIndex;
-       
        boolean fFalseFriendsAccepted;
-       
+
        public Bug246129(String name) {
                super(name);
        }
@@ -76,26 +65,22 @@ public class Bug246129 extends IndexTestBase {
        protected void setUp() throws Exception {
                super.setUp();
                if (fProject == null) {
-
                        // Populate workspace
                        fProject = createProject(true, "resources/indexTests/bug246129");
-                       
+
                        fSource = fProject.getProject().getFile("source.cpp");
-                       
-                       fWrapperIncludeFolder = fProject.getProject().getFolder(
-                                       "wrapper_include");
-                       
+
+                       fWrapperIncludeFolder = fProject.getProject().getFolder("wrapper_include");
+
                        fIncludeFolder = fProject.getProject().getFolder("include");
 
                        // Create header files external to the workspace.
                        fTmpDir = CProjectHelper.freshDir();
-                       
-                       fExternalWrapperIncludeFolder = new File(fTmpDir,
-                                       "wrapper_include");
+
+                       fExternalWrapperIncludeFolder = new File(fTmpDir, "wrapper_include");
                        fExternalWrapperIncludeFolder.mkdir();
-                       
-                       fExternalWrapperHeader = new File(
-                                       fExternalWrapperIncludeFolder, "external_type.h");
+
+                       fExternalWrapperHeader = new File(fExternalWrapperIncludeFolder, "external_type.h");
                        fExternalWrapperHeader.createNewFile();
                        FileWriter writer = new FileWriter(fExternalWrapperHeader);
                        writer.write("#ifndef EXTERNAL_WRAPPER_TYPE_H_\n");
@@ -105,15 +90,14 @@ public class Bug246129 extends IndexTestBase {
                        writer.write("};\n");
                        writer.write("#endif\n");
                        writer.close();
-                       
+
                        fExternalIncludeFolder = new File(fTmpDir, "include");
                        fExternalIncludeFolder.mkdir();
-                       
+
                        fExternalExtFolder = new File(fExternalIncludeFolder, "ext");
                        fExternalExtFolder.mkdir();
 
-                       fExternalHeader = new File(fExternalIncludeFolder,
-                                       "external_type.h");
+                       fExternalHeader = new File(fExternalIncludeFolder, "external_type.h");
                        fExternalHeader.createNewFile();
                        writer = new FileWriter(fExternalHeader);
                        writer.write("#ifndef EXTERNAL_TYPE_H_\n");
@@ -125,12 +109,10 @@ public class Bug246129 extends IndexTestBase {
 
                        // The indexer needs non-empty build info in order to index
                        // source files if index-all-files is turned off.
-                       IPathEntry[] entries = new IPathEntry[] { CoreModel
-                                       .newIncludeEntry(fProject.getPath(), null,
-                                                       fWrapperIncludeFolder.getLocation()),
-                                       CoreModel.newIncludeEntry(fProject.getPath(), null,
-                                                       fIncludeFolder.getLocation()) };
-                       
+                       IPathEntry[] entries = new IPathEntry[] {
+                                       CoreModel.newIncludeEntry(fProject.getPath(), null, fWrapperIncludeFolder.getLocation()),
+                                       CoreModel.newIncludeEntry(fProject.getPath(), null,     fIncludeFolder.getLocation()) };
+
                        fProject.setRawPathEntries(entries, npm());
 
                        // However, the scanner info provider used by the unit tests
@@ -144,12 +126,10 @@ public class Bug246129 extends IndexTestBase {
                        IndexerPreferences.set(fProject.getProject(),
                                        IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false");
 
-                       File falseFriendDirectory = new File(fWrapperIncludeFolder
-                                       .getLocation().toOSString()
-                                       + "/ext/..");
+                       File falseFriendDirectory = new File(fWrapperIncludeFolder.getLocation().toOSString() + "/ext/..");
 
                        fFalseFriendsAccepted = falseFriendDirectory.exists();
-                       
+
                        CCorePlugin.getIndexManager().reindex(fProject);
                        waitForIndexer(fProject);
                        fIndex = CCorePlugin.getIndexManager().getIndex(fProject);
@@ -160,27 +140,23 @@ public class Bug246129 extends IndexTestBase {
        protected void tearDown() throws Exception {
                fExternalWrapperHeader.delete();
                fExternalWrapperIncludeFolder.delete();
-               
+
                fExternalHeader.delete();
                fExternalExtFolder.delete();
                fExternalIncludeFolder.delete();
 
                fTmpDir.delete();
-               
+
                super.tearDown();
        }
 
        private void assertSymbolInIndex(String symbolName) throws Exception {
-               IIndexBinding[] bindings = fIndex.findBindings(
-                               symbolName
-                               .toCharArray(), false, IndexFilter.ALL, npm());
-               assertTrue(bindings.length > 0);
+               IIndexBinding[] bindings = fIndex.findBindings(symbolName.toCharArray(), false, IndexFilter.ALL, npm());
+               assertTrue(bindings.length != 0);
        }
-       
-       public void testIndex() throws Exception {
 
+       public void testIndex() throws Exception {
                try {
-
                        fIndex.acquireReadLock();
                        IIndexFile[] indexFiles = fIndex.getAllFiles();
 
@@ -191,10 +167,9 @@ public class Bug246129 extends IndexTestBase {
                        } else {
                                assertEquals(5, indexFiles.length);
                        }
-                       
+
                        // The wrapper classes are found regardless whether false friends
-                       // are
-                       // accepted or not.
+                       // are accepted or not.
                        assertSymbolInIndex("Wrapper");
                        assertSymbolInIndex("ExternalWrapper");
 
@@ -204,18 +179,16 @@ public class Bug246129 extends IndexTestBase {
                                assertSymbolInIndex("Type");
                                assertSymbolInIndex("ExternalType");
                        }
-                       
+
                        // Check that all paths are normalized.
                        for (IIndexFile indexFile : indexFiles) {
-
                                IIndexInclude[] includes = indexFile.getIncludes();
-                               
+
                                for (IIndexInclude i : includes) {
                                        IIndexFileLocation location = i.getIncludesLocation();
                                        assertNotNull(location);
-                                       
-                                       assertFalse(location.getURI().toASCIIString()
-                                                       .contains(".."));
+
+                                       assertFalse(location.getURI().toASCIIString().contains(".."));
 
                                        String fullPath = location.getFullPath();
                                        if (fullPath != null) {
@@ -223,41 +196,38 @@ public class Bug246129 extends IndexTestBase {
                                        }
                                }
                        }
-                       
                } finally {
                        fIndex.releaseReadLock();
                }
        }
-       
-       private void assertSymbolInAst(IScope scope, String symbolName)
-                       throws Exception {
-               IBinding[] bindings = scope.find(symbolName);
+
+       private void assertSymbolInAst(IScope scope, String symbolName, IASTTranslationUnit ast) throws Exception {
+               IBinding[] bindings = scope.find(symbolName, ast);
                assertTrue(bindings.length > 0);
        }
-       
+
        public void testAst() throws Exception {
-               ITranslationUnit tu = CoreModel.getDefault().createTranslationUnitFrom(
-                               fProject, fSource.getLocation());
+               ITranslationUnit tu =
+                               CoreModel.getDefault().createTranslationUnitFrom(fProject, fSource.getLocation());
 
                IASTTranslationUnit ast = tu.getAST();
-               
+
                // The wrapper classes are found regardless whether false friends
                // are
                // accepted or not.
                IScope topLevel = ast.getScope();
-               assertSymbolInAst(topLevel, "Wrapper");
-               assertSymbolInAst(topLevel, "ExternalWrapper");
+               assertSymbolInAst(topLevel, "Wrapper", ast);
+               assertSymbolInAst(topLevel, "ExternalWrapper", ast);
 
                // The Type class is only known on platforms with a File
                // implementation sorting out the false friends.
                if (!fFalseFriendsAccepted) {
-                       assertSymbolInAst(topLevel, "Type");
-                       assertSymbolInAst(topLevel, "ExternalType");
+                       assertSymbolInAst(topLevel, "Type", ast);
+                       assertSymbolInAst(topLevel, "ExternalType", ast);
                }
 
                // Check that all paths are normalized.
-               IASTPreprocessorIncludeStatement[] includes = ast
-                               .getIncludeDirectives();                
+               IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
                for (IASTPreprocessorIncludeStatement i : includes) {
                        String includedPath = i.getPath();
 
index 8be5291..7331c94 100644 (file)
@@ -15,8 +15,6 @@ package org.eclipse.cdt.internal.pdom.tests;
 
 import java.util.regex.Pattern;
 
-import junit.framework.Test;
-
 import org.eclipse.cdt.core.dom.IName;
 import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
 import org.eclipse.cdt.core.dom.ast.IBinding;
@@ -36,12 +34,12 @@ import org.eclipse.cdt.internal.core.CCoreInternals;
 import org.eclipse.cdt.internal.core.pdom.PDOM;
 import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
 
+import junit.framework.Test;
+
 /**
  * @author Doug Schaefer
- *
  */
 public class ClassTests extends PDOMTestBase {
-
        protected PDOM pdom;
 
        public static Test suite() {
@@ -61,11 +59,11 @@ public class ClassTests extends PDOMTestBase {
        protected void tearDown() throws Exception {
                pdom.releaseReadLock();
        }
-       
+
        public void test1() throws Exception {
                IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), true, IndexFilter.ALL, npm());
                assertEquals(1, Bs.length);
-               ICPPClassType B = (ICPPClassType)Bs[0];
+               ICPPClassType B = (ICPPClassType) Bs[0];
                ICPPMethod[] Bmethods = B.getAllDeclaredMethods();
                assertEquals(4, Bmethods.length);
                assertNotNull(findMethod(Bmethods, "B"));
@@ -78,7 +76,7 @@ public class ClassTests extends PDOMTestBase {
                IASTFileLocation loc = Bf_refs[0].getFileLocation();
                assertEquals(offset("class.cpp", "b.f()") + 2, loc.getNodeOffset());
        }
-       
+
        private ICPPMethod findMethod(ICPPMethod[] bmethods, String name) {
                for (ICPPMethod method : bmethods) {
                        if (method.getName().equals(name)) {
@@ -99,30 +97,30 @@ public class ClassTests extends PDOMTestBase {
                IField[] fields = NestedB.getFields();
                assertEquals(1, fields.length);
                IField NestedB_x = fields[0];
-               
+
                IName[] refs = pdom.findNames(NestedB, IIndex.FIND_REFERENCES);
                assertEquals(1, refs.length);
                IASTFileLocation loc = refs[0].getFileLocation();
                assertEquals(offset("nested.cpp", "::NestedB") + 2, loc.getNodeOffset());
-               
+
                refs = pdom.findNames(NestedB_x, IIndex.FIND_REFERENCES);
                assertEquals(1, refs.length);
                loc = refs[0].getFileLocation();
                assertEquals(offset("nested.cpp", "x.x") + 2, loc.getNodeOffset());
        }
-       
+
        public void test147903() throws Exception {
                IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), false, IndexFilter.ALL, npm());
                assertEquals(1, bindings.length);
-               ICPPNamespaceScope ns = ((ICPPNamespace)bindings[0]).getNamespaceScope();
-               bindings = ns.find("testRef");
+               ICPPNamespaceScope ns = ((ICPPNamespace) bindings[0]).getNamespaceScope();
+               bindings = ns.find("testRef", null);
                assertEquals(1, bindings.length);
                IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES);
 //             for (int i = 0; i < refs.length; ++i)
 //                     System.out.println(refs[i].getFileLocation().getNodeOffset());
                assertEquals(5, refs.length);
        }
-       
+
        /* Test friend relationships between classes */
        public void testFriend() throws Exception {
                IBinding[] bindings = pdom.findBindings(Pattern.compile("ClassA"), true, IndexFilter.ALL_DECLARED, npm());
@@ -140,40 +138,40 @@ public class ClassTests extends PDOMTestBase {
                IBinding[] friends = classA.getFriends();
                assertEquals(1, friends.length);
                assertEquals(classC, friends[0]); //ClassC is a friend class of ClassA
-               
+
                friends = classC.getFriends();
                assertEquals(1, friends.length);
                assertEquals(funcB, friends[0]); //functionB is a friend of ClassC
        }
-       
+
        public void noTest_testConstructor() throws Exception {
                // the source does not define Class1, so it is no surprise that the test is failing.
-               //TODO PDOM doesn't have information on constructor
+               // TODO PDOM doesn't have information on constructor
                IBinding[] bindings = pdom.findBindings(Pattern.compile("Class1"), false, IndexFilter.ALL, npm());
                assertEquals(2, bindings.length);
                assertTrue(bindings[0] instanceof ICPPClassType);
                assertTrue(bindings[1] instanceof ICPPMethod);
-               
+
                IName[] decls = pdom.findNames(bindings[1], IIndex.FIND_DECLARATIONS_DEFINITIONS);
                assertEquals(2, decls.length);
                IASTFileLocation loc = decls[0].getFileLocation();
-               assertEquals(offset("constructor.cpp","Class1(int num);"), loc.getNodeOffset()); //character offset     
-               
+               assertEquals(offset("constructor.cpp","Class1(int num);"), loc.getNodeOffset()); //character offset
+
                loc = decls[1].getFileLocation();
                assertEquals(offset("constructor.cpp","Class1::Class1") + 8, loc.getNodeOffset()); //character offset
-               
+
                /* Member initialization */
                bindings = pdom.findBindings(Pattern.compile("number"), false, IndexFilter.ALL, npm());
                assertEquals(1, bindings.length);
-               
+
                IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES);
                assertEquals(1, refs.length);
                loc = refs[0].getFileLocation();
-               assertEquals(offset("constructor.cpp","number(num)"), loc.getNodeOffset()); //character offset  
-               
+               assertEquals(offset("constructor.cpp", "number(num)"), loc.getNodeOffset()); //character offset
+
                assertEquals(bindings[0], ((PDOMName)refs[0]).getBinding());
        }
-       
+
        public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentA() throws Exception {
                IndexFilter JUST_CONSTRUCTORS= new IndexFilter() {
                        @Override
@@ -185,7 +183,7 @@ public class ClassTests extends PDOMTestBase {
                // expecting C(int) and C(const C &)
                assertEquals(2, bindings.length);
        }
-       
+
        public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentB() throws Exception {
                IndexFilter JUST_CONSTRUCTORS= new IndexFilter() {
                        @Override
@@ -197,40 +195,40 @@ public class ClassTests extends PDOMTestBase {
                // expecting just D(D &)
                assertEquals(1, bindings.length);
        }
-       
+
        public void testClassScope_bug185408() throws Exception {
                char[][] name= {"B".toCharArray(), "bf".toCharArray()};
                IBinding[] bindings= pdom.findBindings(name, IndexFilter.ALL, npm());
                assertEquals(1, bindings.length);
                IScope classScope= bindings[0].getScope();
-               
+
                assertTrue(classScope instanceof ICPPClassScope);
-               bindings= classScope.find("bf");
+               bindings= classScope.find("bf", null);
                ICPPMethod method= extractSingleMethod(bindings);
-               assertEquals(method.getQualifiedName()[0], "B");
+               assertEquals("B", method.getQualifiedName()[0]);
 
-               bindings= classScope.find("f");
+               bindings= classScope.find("f", null);
                method= extractSingleMethod(bindings);
-               assertEquals(method.getQualifiedName()[0], "A");
+               assertEquals("A", method.getQualifiedName()[0]);
 
-               bindings= classScope.find("B");
+               bindings= classScope.find("B", null);
                ICPPClassType classType= extractSingleClass(bindings);
-               assertEquals(classType.getQualifiedName()[0], "B");
+               assertEquals("B", classType.getQualifiedName()[0]);
 
-               bindings= classScope.find("A");
+               bindings= classScope.find("A", null);
                classType= extractSingleClass(bindings);
-               assertEquals(classType.getQualifiedName()[0], "A");
+               assertEquals("A", classType.getQualifiedName()[0]);
        }
 
        private ICPPMethod extractSingleMethod(IBinding[] bindings) {
                assertEquals(1, bindings.length);
-               assertTrue(bindings[0] instanceof ICPPMethod);
+               assertInstance(bindings[0], ICPPMethod.class);
                return (ICPPMethod) bindings[0];
        }
-       
+
        private ICPPClassType extractSingleClass(IBinding[] bindings) {
                assertEquals(1, bindings.length);
-               assertTrue(bindings[0] instanceof ICPPClassType);
+               assertInstance(bindings[0], ICPPClassType.class);
                return (ICPPClassType) bindings[0];
        }
 
index 5ad9605..11216c0 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
-Bundle-Version: 5.10.0.qualifier
+Bundle-Version: 5.11.0.qualifier
 Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
index efe962f..6694bf1 100644 (file)
@@ -9,6 +9,7 @@
  *     IBM - Initial API and implementation
  *     Markus Schorn (Wind River Systems)
  *     Bryan Wilkinson (QNX)
+ *     Sergey Prigogin (Google)
  *******************************************************************************/
 package org.eclipse.cdt.core.dom.ast;
 
@@ -19,7 +20,7 @@ import org.eclipse.cdt.core.index.IIndexFileSet;
 /**
  * Scopes can be used to look-up names. With the exception of template-scopes the scopes
  * can be arranged in a hierarchy.
- * 
+ *
  * @noextend This interface is not intended to be extended by clients.
  * @noimplement This interface is not intended to be implemented by clients.
  */
@@ -31,46 +32,53 @@ public interface IScope {
        EScopeKind getKind();
 
        /**
-     * Returns the IName for this scope, may be {@code null} 
+     * Returns the IName for this scope, may be {@code null}.
+     *
      * @return The name of this scope.
      */
     public IName getScopeName();
-    
+
        /**
         * Returns the first enclosing non-template scope, or {@code null} if this is the global scope.
         */
        public IScope getParent() throws DOMException;
 
        /**
-        * This is the general lookup entry point. It returns the list of valid bindings for a given
-        * name.  The lookup proceeds as an unqualified lookup.  Constructors are not considered during
-        * this lookup and won't be returned. No attempt is made to resolve potential ambiguities or
+        * This is the general lookup entry point. It returns the list of valid bindings for a given name in this
+        * scope and its enclosing scopes. The name is treated as unqualified. Constructors are not considered
+        * during this lookup and won't be returned. No attempt is made to resolve potential ambiguities or
         * perform access checking.
-        * 
+        *
         * @param name the name of the bindings
-        * @return An array of bindings.
+        * @param tu the translation unit determining the context for the lookup
+        * @return An array of bindings
+        * @since 5.11
         */
+       public IBinding[] find(String name, IASTTranslationUnit tu);
+
+       /**
+        * @deprecated Use {{@link #find(String, IASTTranslationUnit)}
+        */
+       @Deprecated
        public IBinding[] find(String name);
-       
+
        /**
-        * Returns the binding in this scope that the given name would resolve to. Could
-        * return null if there is no matching binding in this scope, if the binding has not
-        * yet been cached in this scope, or if resolve is {@code false} and the appropriate binding 
-        * has not yet been resolved.
-        * 
+        * Returns the binding in this scope that the given name would resolve to. Could return {@code null}
+        * if there is no matching binding in this scope, if the binding has not yet been cached in this scope,
+        * or if resolve is {@code false} and the appropriate binding has not yet been resolved.
+        *
         * @param name the name of the binding
         * @param resolve whether or not to resolve the matching binding if it has not been so already
         * @return the binding in this scope that matches the name, or {@code null}
         */
        public IBinding getBinding(IASTName name, boolean resolve);
-       
+
        /**
-        * Returns the binding in this scope that the given name would resolve to. Could
-        * return null if there is no matching binding in this scope, if the binding has not
-        * yet been cached in this scope, or if resolve is {@code false} and the appropriate binding 
-        * has not yet been resolved. Accepts file local bindings from the index for the files
-        * in the given set, only.
-        * 
+        * Returns the binding in this scope that the given name would resolve to. Could return {@code null}
+        * if there is no matching binding in this scope, if the binding has not yet been cached in this scope,
+        * or if resolve is {@code false} and the appropriate binding has not yet been resolved. Accepts file
+        * local bindings from the index for the files in the given set, only.
+        *
         * @param name the name of the binding
         * @param resolve whether or not to resolve the matching binding if it has not been so already
         * @param acceptLocalBindings a set of files for which to accept local bindings
@@ -88,9 +96,9 @@ public interface IScope {
         * @deprecated Use {@link #getBindings(ScopeLookupData)} instead
         */
        @Deprecated
-       public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings);
+       public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
+                       IIndexFileSet acceptLocalBindings);
 
-       
        /**
         * @since 5.5
         * @noextend This class is not intended to be subclassed by clients.
@@ -103,7 +111,7 @@ public interface IScope {
                private boolean fResolve= true;
                private boolean fPrefixLookup;
                private boolean fIgnorePointOfDeclaration;
-               
+
                public ScopeLookupData(IASTName name, boolean resolve, boolean prefixLookup) {
                        if (name == null)
                                throw new IllegalArgumentException();
@@ -129,6 +137,17 @@ public interface IScope {
                        }
                }
 
+               /**
+                * @since 5.11
+                */
+               public ScopeLookupData(char[] name, IASTTranslationUnit tu) {
+                       fLookupPoint= null;
+                       fLookupPointIsName= false;
+                       fLookupKey= name;
+                       fIgnorePointOfDeclaration= true;
+                       fTu= tu;
+               }
+
                public final void setPrefixLookup(boolean prefixLookup) {
                        fPrefixLookup = prefixLookup;
                }
@@ -183,11 +202,10 @@ public interface IScope {
        }
 
        /**
-        * Returns the bindings in this scope that the given name or prefix could resolve to. Could
-        * return null if there is no matching bindings in this scope, if the bindings have not
-        * yet been cached in this scope, or if resolve == false and the appropriate bindings 
-        * have not yet been resolved.
-        * 
+        * Returns the bindings in this scope that the given name or prefix could resolve to. Could return
+        * {@code null} if there is no matching bindings in this scope, if the bindings have not yet been cached
+        * in this scope, or if resolve is {@code false} and the appropriate bindings have not yet been resolved.
+        *
         * @return the bindings in this scope that match the name or prefix, or {@code null}
         * @since 5.5
         */
index dd84825..bdf087a 100644 (file)
@@ -175,6 +175,11 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
     }
 
     @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+        return IBinding.EMPTY_BINDING_ARRAY;
+    }
+
+    @Override
        public IBinding[] find(String name) {
         return IBinding.EMPTY_BINDING_ARRAY;
     }
index de23fe1..d57bd3d 100644 (file)
@@ -165,6 +165,11 @@ public class CScope implements ICScope, IASTInternalScope {
     }
     
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               return find(name);
+       }
+
+       @Override
        public IBinding[] find(String name) {
                return CVisitor.findBindings(this, name);
        }
index 33ee56d..55165f8 100644 (file)
@@ -685,7 +685,7 @@ public class CVisitor extends ASTQueries {
        
        static IType getPtrDiffType(IASTBinaryExpression expr) {
                IScope scope = getContainingScope(expr);
-               IBinding[] bs = scope.find(PTRDIFF_T);
+               IBinding[] bs = scope.find(PTRDIFF_T, expr.getTranslationUnit());
                for (IBinding b : bs) {
                        if (b instanceof IType) {
                                if (!(b instanceof ICInternalBinding) || 
@@ -701,7 +701,7 @@ public class CVisitor extends ASTQueries {
        static IType get_SIZE_T(IASTExpression expr) {
                IASTTranslationUnit tu= expr.getTranslationUnit();
                if (tu != null) {
-                       IBinding[] bs = tu.getScope().find(SIZE_T);
+                       IBinding[] bs = tu.getScope().find(SIZE_T, expr.getTranslationUnit());
                        for (IBinding b : bs) {
                                if (b instanceof IType) {
                                        if (!(b instanceof ICInternalBinding) || 
@@ -1650,7 +1650,7 @@ public class CVisitor extends ASTQueries {
            }
         
         // label names
-        List<ILabel> b3 = new ArrayList<ILabel>();
+        List<ILabel> b3 = new ArrayList<>();
         do {
             char[] n = name.toCharArray();
             if (scope instanceof ICFunctionScope) {
index 6015a27..f780fc6 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IProblemBinding;
 import org.eclipse.cdt.core.dom.ast.IScope;
@@ -338,6 +339,11 @@ public class AbstractCPPClassSpecializationScope implements ICPPClassSpecializat
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+           return find(name);
+       }
+
+       @Override
        public IBinding[] find(String name) {
                return CPPSemantics.findBindings(this, name, false);
        }
index 432cfad..b966aef 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
 import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IASTTypeId;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IProblemBinding;
@@ -430,6 +431,11 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               return find(name);
+       }
+
+       @Override
        public IBinding[] find(String name) {
            char[] n = name.toCharArray();
            ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
index edd4261..92cfafd 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
 import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
 import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IASTTypeId;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IField;
@@ -386,7 +387,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
                }
 
                private IBinding[] getPrefixBindings(char[] name) {
-                       List<IBinding> result= new ArrayList<IBinding>();
+                       List<IBinding> result= new ArrayList<>();
                        IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(name);
                        for (ICPPMethod m : getMethods()) {
                                if (!(m instanceof ICPPConstructor)) {
@@ -399,6 +400,11 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
                }
 
                @Override
+               public IBinding[] find(String name, IASTTranslationUnit tu) {
+                       return find(name);
+               }
+
+               @Override
                public IBinding[] find(String name) {
                        return getBindings(name.toCharArray());
                }
@@ -427,8 +433,8 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
                @Override
                public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
                                IIndexFileSet acceptLocalBindings) {
-                                       return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
-                               }
+                       return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
+               }
 
                @Override
                public IBinding[] getBindings(ScopeLookupData lookup) {
index e60854c..b47c7b2 100644 (file)
@@ -337,6 +337,11 @@ abstract public class CPPScope implements ICPPASTInternalScope {
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+           return find(name);
+       }
+
+       @Override
        public IBinding[] find(String name) {
            return CPPSemantics.findBindings(this, name, false);
        }
index e85e81c..bfceb58 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
 import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IScope;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
@@ -97,6 +98,11 @@ public class CPPScopeMapper {
                }
 
                @Override
+               public IBinding[] find(String name, IASTTranslationUnit tu) {
+                       return fScope.find(name, tu);
+               }
+
+               @Override @Deprecated
                public IBinding[] find(String name) {
                        return fScope.find(name);
                }
index 155bb20..b4e8f00 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IScope;
 import org.eclipse.cdt.core.dom.ast.IType;
@@ -79,6 +80,11 @@ public class CPPUnknownTypeScope implements ICPPInternalUnknownScope {
     }
 
     @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+        return IBinding.EMPTY_BINDING_ARRAY;
+    }
+
+    @Override
        public IBinding[] find(String name) {
         return IBinding.EMPTY_BINDING_ARRAY;
     }
index 116dd13..cfae877 100644 (file)
@@ -229,7 +229,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.TypeS
 import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.Rank;
-import org.eclipse.cdt.internal.core.index.IIndexScope;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 
@@ -734,7 +733,8 @@ public class CPPSemantics {
                        if (parent != null)
                                parent= parent.getParent();                       // the loop
                        if (parent instanceof ICPPASTRangeBasedForStatement) {
-                               IBinding[] std= parent.getTranslationUnit().getScope().find(CPPVisitor.STD);
+                               IASTTranslationUnit tu = parent.getTranslationUnit();
+                                       IBinding[] std= tu.getScope().find(CPPVisitor.STD, tu);
                                for (IBinding binding : std) {
                                        if (binding instanceof ICPPNamespace) {
                                                namespaces.add(((ICPPNamespace) binding).getNamespaceScope());
@@ -815,9 +815,7 @@ public class CPPSemantics {
                if (binding == null)
                        return null;
         IScope scope = binding.getScope();
-        if (tu != null) {
-               scope= tu.mapToASTScope(scope);
-        }
+        scope = SemanticUtil.mapToAST(scope, tu);
         while (scope != null && !(scope instanceof ICPPNamespaceScope)) {
             scope = getParentScope(scope, tu);
         }
@@ -997,10 +995,7 @@ public class CPPSemantics {
                                }
                        }
                        ICPPScope scope= useTemplScope ? nextTmplScope : nextScope;
-                       CPPASTTranslationUnit tu = data.getTranslationUnit();
-                       if (tu != null) {
-                               scope= (ICPPScope) tu.mapToASTScope((scope));
-                       }
+                       scope = (ICPPScope) SemanticUtil.mapToAST(scope, data.getTranslationUnit());
 
                        if (!data.usingDirectivesOnly && !(data.ignoreMembers && scope instanceof ICPPClassScope)) {
                                mergeResults(data, getBindingsFromScope(scope, data), true);
@@ -1367,16 +1362,14 @@ public class CPPSemantics {
                return ((ICPPASTTemplateDeclaration) parent).getScope();
        }
 
-       static ICPPScope getParentScope(IScope scope, ICPPASTTranslationUnit unit) throws DOMException {
+       static ICPPScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
                IScope parentScope= scope.getParent();
                // The index cannot return the translation unit as parent scope.
-               if (unit instanceof CPPASTTranslationUnit) {
-                       if (parentScope == null
-                                       && (scope instanceof IIndexScope || scope instanceof ICPPClassSpecializationScope)) {
-                               parentScope = unit.getScope();
-                       } else {
-                               parentScope = ((CPPASTTranslationUnit) unit).mapToASTScope(parentScope);
-                       }
+               if (parentScope == null && scope instanceof ICPPClassSpecializationScope
+                               && unit instanceof CPPASTTranslationUnit) {
+                       parentScope = unit.getScope();
+               } else {
+                       parentScope = SemanticUtil.mapToAST(parentScope, unit);
                }
                return (ICPPScope) parentScope;
        }
@@ -3586,6 +3579,11 @@ public class CPPSemantics {
        return type instanceof ICPPClassType || type instanceof IEnumeration || type instanceof ICPPUnknownType;
     }
 
+    public static IBinding[] findBindingsInScope(IScope scope, String name, IASTTranslationUnit tu) {
+       LookupData data = new LookupData(name.toCharArray(), null, tu);
+               return standardLookup(data, scope);
+       }
+
     public static IBinding[] findBindings(IScope scope, String name, boolean qualified) {
                return findBindings(scope, name.toCharArray(), qualified, null);
        }
index 4f3c31e..999c4d4 100644 (file)
@@ -220,7 +220,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
-import org.eclipse.cdt.internal.core.index.IIndexScope;
 
 /**
  * Collection of methods to extract information from a C++ translation unit.
@@ -542,15 +541,15 @@ public class CPPVisitor extends ASTQueries {
                }
 
                if (mustBeSimple) {
-                       // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
-                       // the declaration
+                       // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype
+                       // scope that contains the declaration.
                        while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) {
-                               scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
+                               scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit());
                        }
                }
                if (scope instanceof ICPPClassScope && isFriend && !qualified) {
                        while (scope instanceof ICPPClassScope) {
-                               scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
+                               scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit());
                        }
                }
                if (scope != null) {
@@ -820,7 +819,7 @@ public class CPPVisitor extends ASTQueries {
                        if (isFriendDecl) {
                                try {
                                        while (scope.getKind() == EScopeKind.eClassType) {
-                                               scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
+                                               scope = CPPSemantics.getParentScope(scope, name.getTranslationUnit());
                                        }
                                } catch (DOMException e1) {
                                }
@@ -2369,7 +2368,7 @@ public class CPPVisitor extends ASTQueries {
                if (node == null)
                        return null;
                ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit();
-               IBinding[] std= ast.getScope().find(STD);
+               IBinding[] std= ast.getScope().find(STD, ast);
                for (IBinding binding : std) {
                        if (binding instanceof ICPPNamespace) {
                                final ICPPNamespaceScope scope = ((ICPPNamespace) binding).getNamespaceScope();
@@ -2499,16 +2498,6 @@ public class CPPVisitor extends ASTQueries {
            return ns;
        }
 
-       private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
-               IScope parentScope= scope.getParent();
-               // Replace the global scope from index with the global scope of the translation unit.
-               if ((parentScope == null || parentScope.getKind() == EScopeKind.eGlobal) &&
-                               scope instanceof IIndexScope && unit != null) {
-                       parentScope= unit.getScope();
-               }
-               return parentScope;
-       }
-
        public static boolean isExternC(IASTNode node) {
                while (node != null) {
                        node= node.getParent();
index 694dab7..ef38bc8 100644 (file)
@@ -40,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
 import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
 import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IScope;
 import org.eclipse.cdt.core.dom.ast.IScope.ScopeLookupData;
@@ -135,6 +136,11 @@ public class LookupData extends ScopeLookupData {
                fTemplateArguments= templateArgs;
        }
        
+       public LookupData(char[] name, ICPPTemplateArgument[] templateArgs, IASTTranslationUnit tu) {
+               super(name, tu);
+               fTemplateArguments= templateArgs;
+       }
+
        @Override
        public CPPASTTranslationUnit getTranslationUnit() {
                return (CPPASTTranslationUnit) super.getTranslationUnit();
index af32edb..55b7bdc 100644 (file)
@@ -27,7 +27,9 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier
 import java.util.HashSet;
 import java.util.Set;
 
+import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
 import org.eclipse.cdt.core.dom.ast.IASTExpression;
 import org.eclipse.cdt.core.dom.ast.IASTInitializer;
@@ -81,6 +83,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateTypeArgument;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
 
 /**
  * Collection of static methods operating on C++ bindings.
@@ -540,10 +543,15 @@ public class SemanticUtil {
        }
 
        public static IScope mapToAST(IScope scope, IASTNode point) {
-               if (point != null) {
-                       IASTTranslationUnit ast = point.getTranslationUnit();
-                       if (ast instanceof ASTTranslationUnit) {
-                               return ((ASTTranslationUnit) ast).mapToASTScope(scope);
+               if (scope instanceof IIndexScope) {
+                       if (point != null) {
+                               IASTTranslationUnit ast = point.getTranslationUnit();
+                               if (ast instanceof ASTTranslationUnit) {
+                                       return ((ASTTranslationUnit) ast).mapToASTScope(scope);
+                               }
+                       } else if (scope.getKind() == EScopeKind.eGlobal) {
+                               CCorePlugin.log(new Exception(
+                                               "The point argument was not provided. Returning the global index scope.")); //$NON-NLS-1$
                        }
                }
                return scope;
index d3adefd..34d9371 100644 (file)
@@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.index.composite.c;
 
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.ICompositeType;
 import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
@@ -55,6 +56,12 @@ class CompositeCCompositeScope extends CompositeScope implements ICCompositeType
        }
        
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               IBinding[] preresult = ((ICompositeType) rbinding).getCompositeScope().find(name, tu);
+               return processUncertainBindings(preresult);     
+       }
+       
+       @Override @Deprecated
        public IBinding[] find(String name) {
                IBinding[] preresult = ((ICompositeType) rbinding).getCompositeScope().find(name);
                return processUncertainBindings(preresult);     
index 6da2ec8..f44014a 100644 (file)
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
 
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@@ -77,6 +78,12 @@ class CompositeCPPClassScope extends CompositeScope implements ICPPClassScope {
        }
        
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               IBinding[] preresult = ((ICPPClassType) rbinding).getCompositeScope().find(name, tu);
+               return processUncertainBindings(preresult);     
+       }
+       
+       @Override @Deprecated
        public IBinding[] find(String name) {
                IBinding[] preresult = ((ICPPClassType) rbinding).getCompositeScope().find(name);
                return processUncertainBindings(preresult);     
index b00a7b5..5bf953f 100644 (file)
@@ -16,6 +16,7 @@ import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
@@ -81,6 +82,12 @@ public class CompositeCPPClassSpecializationScope extends CompositeScope impleme
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               createDelegate();
+               return fDelegate.find(name, tu);
+       }
+
+       @Override @Deprecated
        public IBinding[] find(String name) {
                createDelegate();
                return fDelegate.find(name);
index 929dfdc..9886727 100644 (file)
@@ -6,12 +6,13 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- *    Markus Schorn - initial API and implementation
+ *     Markus Schorn - initial API and implementation
  *******************************************************************************/ 
 package org.eclipse.cdt.internal.core.index.composite.cpp;
 
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
@@ -44,16 +45,22 @@ class CompositeCPPEnumScope extends CompositeScope implements ICPPEnumScope {
 
        @Override
        public IBinding[] getBindings(ScopeLookupData lookup) {
-               IBinding[] bindings = ((ICPPEnumeration)rbinding).asScope().getBindings(lookup);
+               IBinding[] bindings = ((ICPPEnumeration) rbinding).asScope().getBindings(lookup);
                return processUncertainBindings(bindings);
        }
-       
+
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               IBinding[] preresult = ((ICPPEnumeration) rbinding).asScope().find(name, tu);
+               return processUncertainBindings(preresult);     
+       }
+
+       @Override @Deprecated
        public IBinding[] find(String name) {
-               IBinding[] preresult = ((ICPPEnumeration)rbinding).asScope().find(name);
+               IBinding[] preresult = ((ICPPEnumeration) rbinding).asScope().find(name);
                return processUncertainBindings(preresult);     
        }
-       
+
        @Override
        public IIndexBinding getScopeBinding() {
                return cf.getCompositeBinding(rbinding);
index 693a0ea..9b4a5e4 100644 (file)
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.composite.cpp;
 
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
@@ -74,6 +75,17 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
        }
        
        @Override
+       final public IBinding[] find(String name, IASTTranslationUnit tu) {
+               IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
+               for (int i= 0; i < namespaces.length; i++) {
+                       IBinding[] raw = namespaces[i].getNamespaceScope().find(name, tu);
+                       preresult[i] = new IIndexFragmentBinding[raw.length];
+                       System.arraycopy(raw, 0, preresult[i], 0, raw.length);
+               }
+               return cf.getCompositeBindings(preresult);
+       }
+
+       @Override @Deprecated
        final public IBinding[] find(String name) {
                IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
                for (int i= 0; i < namespaces.length; i++) {
index 0e88195..218835e 100644 (file)
  *******************************************************************************/
 package org.eclipse.cdt.internal.core.pdom.dom;
 
+import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.index.IIndexBinding;
 import org.eclipse.cdt.core.index.IIndexFileSet;
@@ -28,34 +30,46 @@ public abstract class PDOMGlobalScope implements IIndexScope {
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               logInvalidCallError();
+               return IBinding.EMPTY_BINDING_ARRAY;
+       }
+
+       @Override
        public IBinding[] find(String name) {
-               throw new UnsupportedOperationException();
+               logInvalidCallError();
+               return IBinding.EMPTY_BINDING_ARRAY;
        }
 
        @Override
        public IBinding getBinding(IASTName name, boolean resolve) {
-               throw new UnsupportedOperationException();
+               logInvalidCallError();
+               return null;
        }
 
        @Override
        public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) {
-               throw new UnsupportedOperationException();
+               logInvalidCallError();
+               return null;
        }
 
        @Override
        public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
-               throw new UnsupportedOperationException();
+               logInvalidCallError();
+               return IBinding.EMPTY_BINDING_ARRAY;
        }
 
        @Override
        public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
                        IIndexFileSet acceptLocalBindings) {
-               throw new UnsupportedOperationException();
+               logInvalidCallError();
+               return IBinding.EMPTY_BINDING_ARRAY;
        }
 
        @Override
        public IBinding[] getBindings(ScopeLookupData lookup) {
-               throw new UnsupportedOperationException();
+               logInvalidCallError();
+               return IBinding.EMPTY_BINDING_ARRAY;
        }
 
        @Override
@@ -77,4 +91,9 @@ public abstract class PDOMGlobalScope implements IIndexScope {
        public String toString() {
                return "<global scope>"; //$NON-NLS-1$
        }
+
+       private void logInvalidCallError() {
+               CCorePlugin.log(new UnsupportedOperationException(
+                               "Global index scope has to be mapped to the global scope of a particular translation unit.")); //$NON-NLS-1$
+       }
 }
index c8f5c39..551a29c 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
 import org.eclipse.cdt.core.dom.IPDOMVisitor;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.ICompositeType;
 import org.eclipse.cdt.core.dom.ast.IField;
@@ -292,6 +293,11 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
        }
        
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               return getBindings(name.toCharArray());
+       }
+
+       @Override @Deprecated
        public IBinding[] find(String name) {
                return getBindings(name.toCharArray());
        }
index a83c806..50b071b 100644 (file)
@@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
 import org.eclipse.cdt.core.dom.IPDOMVisitor;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.ICompositeType;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
@@ -258,6 +259,11 @@ class PDOMCPPClassScope implements ICPPClassScope, IIndexScope {
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+           return CPPSemantics.findBindingsInScope(this, name, tu);
+       }
+
+       @Override @Deprecated
        public IBinding[] find(String name) {
                return CPPSemantics.findBindings(this, name, false);
        }
index 58c503d..43bad77 100644 (file)
 package org.eclipse.cdt.internal.core.pdom.dom.cpp;
 
 import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
 import org.eclipse.cdt.core.index.IIndexBinding;
 import org.eclipse.cdt.core.index.IIndexName;
 import org.eclipse.cdt.internal.core.dom.parser.cpp.AbstractCPPClassSpecializationScope;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
 import org.eclipse.cdt.internal.core.index.IIndexScope;
 
 /**
@@ -43,4 +46,9 @@ public class PDOMCPPClassSpecializationScope extends AbstractCPPClassSpecializat
        public IIndexName getScopeName() {
                return null;
        }
+
+       @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+           return CPPSemantics.findBindingsInScope(this, name, tu);
+       }
 }
index ce4159f..4ba004e 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.IPDOMVisitor;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IEnumerator;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
@@ -105,6 +106,11 @@ class PDOMCPPEnumScope implements ICPPEnumScope, IIndexScope {
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+           return CPPSemantics.findBindingsInScope(this, name, tu);
+       }
+
+       @Override @Deprecated
        public IBinding[] find(String name) {
                return CPPSemantics.findBindings(this, name, false);
        }
index 8038384..9e785d9 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.cdt.core.CCorePlugin;
 import org.eclipse.cdt.core.dom.IPDOMVisitor;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
 import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
@@ -167,6 +168,11 @@ class PDOMCPPNamespace extends PDOMCPPBinding
        }
 
        @Override
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               return find(name);
+       }
+
+       @Override
        public IBinding[] find(String name) {
                try {
                        BindingCollector visitor = new BindingCollector(getLinkage(), name.toCharArray(),
index 4311569..44f0ce3 100644 (file)
@@ -11,7 +11,7 @@
     <relativePath>../../pom.xml</relativePath>
   </parent>
 
-  <version>5.10.0-SNAPSHOT</version>
+  <version>5.11.0-SNAPSHOT</version>
   <artifactId>org.eclipse.cdt.core</artifactId>
   <packaging>eclipse-plugin</packaging>
 </project>
index f894373..01d4b4d 100644 (file)
@@ -691,10 +691,10 @@ public class ASTManager implements IDisposable {
         }
     }
 
-    public static IBinding[] findInScope(final IScope scope, String name, boolean removeGlobalsWhenClassScope)
-               throws DOMException {
+    public static IBinding[] findInScope(final IScope scope, String name, IASTTranslationUnit tu,
+               boolean removeGlobalsWhenClassScope) throws DOMException {
         IBinding[] result= null;
-        result = scope.find(name);
+        result = scope.find(name, tu);
         if (result == null || result.length == 0) {
             return result;
         }
@@ -706,7 +706,7 @@ public class ASTManager implements IDisposable {
             for (int i = 0; i < result.length; i++) {
                 IBinding binding = result[i];
                 IScope bscope= binding.getScope();
-                if (! (bscope instanceof ICPPClassScope || bscope instanceof ICCompositeTypeScope)) {
+                if (!(bscope instanceof ICPPClassScope || bscope instanceof ICCompositeTypeScope)) {
                     result[i]= null;
                 } else {
                     count++;
@@ -1197,7 +1197,7 @@ public class ASTManager implements IDisposable {
                 if (scope != null) {
                     IBinding[] conflicting= null;
                     try {
-                        conflicting= findInScope(scope, fRenameTo, true);
+                        conflicting= findInScope(scope, fRenameTo, name.getTranslationUnit(), true);
                     } catch (Exception e) {
                        CUIPlugin.log(e);
                     }
@@ -1445,7 +1445,7 @@ public class ASTManager implements IDisposable {
                 try {
                     oldBindingsScope = oldBinding.getScope();
                     if (oldBindingsScope != null) {
-                        newBindingsAboverOrEqual = ASTManager.findInScope(oldBindingsScope, fRenameTo, false);
+                        newBindingsAboverOrEqual = ASTManager.findInScope(oldBindingsScope, fRenameTo, null, false);
                     }
                 } catch (DOMException e) {
                     handleDOMException(tu, e, status);
index 54e67bc..32794bc 100644 (file)
@@ -96,10 +96,10 @@ public class CRenameClassProcessor extends CRenameTypeProcessor {
                        if (ctors != null) {
                            ArrayUtil.addAll(bindings, ctors);
                        }
-                       
+
                        IScope scope= ctype.getCompositeScope();
                        if (scope != null) {
-                           IBinding[] dtors= scope.find("~" + argument.getName()); //$NON-NLS-1$
+                           IBinding[] dtors= scope.find("~" + argument.getName(), argument.getTranslationUnit()); //$NON-NLS-1$
                            if (dtors != null) {
                                ArrayUtil.addAll(bindings, dtors);
                            }
index 6a39a24..a000639 100644 (file)
@@ -14,6 +14,7 @@ import org.eclipse.cdt.core.dom.IName;
 import org.eclipse.cdt.core.dom.ast.EScopeKind;
 import org.eclipse.cdt.core.dom.ast.IASTName;
 import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
 import org.eclipse.cdt.core.dom.ast.IBinding;
 import org.eclipse.cdt.core.dom.ast.IScope;
 import org.eclipse.cdt.core.index.IIndexFileSet;
@@ -25,9 +26,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope;
  */
 @SuppressWarnings({"restriction","unused"})
 public class C99Scope implements IC99Scope, IASTInternalScope {
-
-       
-       
        private IScope parent;
        private IASTNode physicalNode;
        private IName scopeName;
@@ -72,9 +70,13 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
                this.scopeName = scopeName;
        }
        
-       
        @Override
-       public IBinding[] find( String name) {
+       public IBinding[] find(String name, IASTTranslationUnit tu) {
+               throw new UnsupportedOperationException();
+       }
+
+       @Override @Deprecated
+       public IBinding[] find(String name) {
                throw new UnsupportedOperationException();
        }
 
@@ -87,9 +89,6 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
        public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
                throw new UnsupportedOperationException();
        }
-
-       
-       
        
        @Override
        public void addBinding(IBinding binding) {
@@ -110,9 +109,7 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
        }
 
        @Override
-       public IBinding getBinding(IASTName name, boolean resolve,
-                       IIndexFileSet acceptLocalBindings) {
-               // TODO Auto-generated method stub
+       public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) {
                return null;
        }
 
@@ -123,15 +120,11 @@ public class C99Scope implements IC99Scope, IASTInternalScope {
        @Deprecated
        public IBinding[] getBindings(IASTName name, boolean resolve,
                        boolean prefixLookup, IIndexFileSet acceptLocalBindings) {
-                               return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
-                       }
+               return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
+       }
 
        @Override
        public IBinding[] getBindings(ScopeLookupData lookup) {
-               // TODO Auto-generated method stub
-               return null;
+               return IBinding.EMPTY_BINDING_ARRAY;
        }
-
-       
-
 }