From 50c791143e026c57f93447460ac02a6286a914d3 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 1 Feb 2007 14:20:43 +0000 Subject: [PATCH] Fix for 172453, inconsistencies in index API + testcases. --- .../internal/index/tests/IndexBugsTests.java | 8 +-- .../index/tests/IndexIncludeTest.java | 5 +- .../index/tests/IndexLocationTest.java | 8 ++- .../internal/index/tests/IndexSearchTest.java | 46 +++++++++++++-- .../internal/pdom/tests/CPPFunctionTests.java | 5 +- .../OverloadsWithinCommonHeaderTests.java | 4 +- .../tests/OverloadsWithinSingleTUTests.java | 17 +++--- .../pdom/tests/RaceCondition157992Test.java | 5 +- .../org/eclipse/cdt/core/index/IIndex.java | 34 ++++++++--- .../eclipse/cdt/core/index/IndexFilter.java | 14 ----- .../core/dom/parser/c/CASTIdExpression.java | 6 +- .../parser/c/CASTTypedefNameSpecifier.java | 2 +- .../dom/parser/cpp/CPPASTBaseSpecifier.java | 2 +- .../dom/parser/cpp/CPPASTIdExpression.java | 6 +- .../parser/cpp/CPPASTNamedTypeSpecifier.java | 2 +- .../parser/cpp/CPPASTUsingDeclaration.java | 2 +- .../dom/parser/cpp/CPPASTUsingDirective.java | 2 +- .../core/dom/parser/cpp/CPPScope.java | 19 +++++-- .../cdt/internal/core/index/CIndex.java | 40 ++++++------- .../cdt/internal/core/index/EmptyCIndex.java | 21 +++---- .../internal/core/index/IIndexFragment.java | 21 ++++--- .../eclipse/cdt/internal/core/pdom/PDOM.java | 57 +++++++++---------- ...ingsInBTree.java => BindingCollector.java} | 42 ++++++++++++-- .../internal/core/pdom/dom/PDOMLinkage.java | 43 +++++++------- .../core/pdom/dom/cpp/PDOMCPPNamespace.java | 43 +++++++------- .../typehierarchy/CTypeHierarchyTest.java | 12 ---- .../classwizard/NewClassWizardUtil.java | 17 +++--- 27 files changed, 276 insertions(+), 207 deletions(-) rename core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/{FindBindingsInBTree.java => BindingCollector.java} (65%) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index c0b46ccce0f..0ec218c3d9e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import java.util.regex.Pattern; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -49,7 +50,6 @@ import org.eclipse.cdt.core.testplugin.TestScannerProvider; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.internal.core.CCoreInternals; -import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -408,7 +408,7 @@ public class IndexBugsTests extends BaseTestCase { fIndex.acquireReadLock(); try { - IBinding[] bindings= fIndex.findInGlobalScope(Linkage.C_LINKAGE, "S20070201".toCharArray()); + IBinding[] bindings= fIndex.findBindings("S20070201".toCharArray(), IndexFilter.getFilter(ILinkage.C_LINKAGE_ID), NPM); assertEquals(2, bindings.length); IBinding struct, typedef; @@ -443,7 +443,7 @@ public class IndexBugsTests extends BaseTestCase { fIndex.acquireReadLock(); try { - IBinding[] bindings= fIndex.findInGlobalScope(Linkage.CPP_LINKAGE, "S20070201".toCharArray()); + IBinding[] bindings= fIndex.findBindings("S20070201".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM); assertEquals(2, bindings.length); IBinding struct, typedef; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 5b7a3ee133d..851cbbb91e6 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -140,6 +140,9 @@ public class IndexIncludeTest extends IndexTestBase { IIndexBinding[] result= fIndex.findBindings(Pattern.compile("testInclude_cpp"), true, IndexFilter.ALL, NPM); assertEquals(1, result.length); + + result= fIndex.findBindings("testInclude_cpp".toCharArray(), IndexFilter.ALL, NPM); + assertEquals(1, result.length); } finally { fIndex.releaseReadLock(); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java index ce7afb34d85..f64d32f3795 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexLocationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software Systems and others. + * Copyright (c) 2006, 2007 Symbian Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -101,6 +101,12 @@ public class IndexLocationTest extends BaseTestCase { assertEquals(1, bs1.length); assertEquals(1, bs2.length); assertEquals(1, bs3.length); + bs1 = index.findBindings("foo".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); + bs2 = index.findBindings("bar".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); + bs3 = index.findBindings("baz".toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); + assertEquals(1, bs1.length); + assertEquals(1, bs2.length); + assertEquals(1, bs3.length); IIndexName[] nms1 = index.findNames(bs1[0], IIndex.FIND_ALL_OCCURENCES); IIndexName[] nms2 = index.findNames(bs2[0], IIndex.FIND_ALL_OCCURENCES); IIndexName[] nms3 = index.findNames(bs3[0], IIndex.FIND_ALL_OCCURENCES); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java index 85ffcb2ae57..dfe7ba66a7a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -104,8 +104,10 @@ public class IndexSearchTest extends IndexTestBase { } public void testFindClassInNamespace() throws CoreException { - Pattern pcl= Pattern.compile("C160913"); - Pattern pns= Pattern.compile("ns160913"); + String scl = "C160913"; + Pattern pcl= Pattern.compile(scl); + String sns = "ns160913"; + Pattern pns= Pattern.compile(sns); IIndexBinding[] bindings; @@ -113,6 +115,10 @@ public class IndexSearchTest extends IndexTestBase { assertEquals(1, bindings.length); checkIsClass(bindings[0]); + bindings= fIndex.findBindings(scl.toCharArray(), INDEX_FILTER, NPM); + assertEquals(1, bindings.length); + checkIsClass(bindings[0]); + bindings= fIndex.findBindings(pcl, false, INDEX_FILTER, NPM); assertEquals(3, bindings.length); checkIsClass(bindings[0]); @@ -123,6 +129,10 @@ public class IndexSearchTest extends IndexTestBase { assertEquals(1, bindings.length); checkIsClass(bindings[0]); + bindings= fIndex.findBindings(new char[][]{sns.toCharArray(), scl.toCharArray()}, INDEX_FILTER, NPM); + assertEquals(1, bindings.length); + checkIsClass(bindings[0]); + bindings= fIndex.findBindings(new Pattern[]{pns, pcl}, false, INDEX_FILTER, NPM); assertEquals(2, bindings.length); checkIsClass(bindings[0]); @@ -132,6 +142,10 @@ public class IndexSearchTest extends IndexTestBase { assertEquals(1, bindings.length); checkIsClass(bindings[0]); + bindings= fIndex.findBindings(new char[][]{sns.toCharArray(), sns.toCharArray(), scl.toCharArray()}, INDEX_FILTER, NPM); + assertEquals(1, bindings.length); + checkIsClass(bindings[0]); + bindings= fIndex.findBindings(new Pattern[]{pns, pns, pcl}, false, INDEX_FILTER, NPM); assertEquals(1, bindings.length); checkIsClass(bindings[0]); @@ -140,6 +154,8 @@ public class IndexSearchTest extends IndexTestBase { public void testFindNamespaceInNamespace() throws CoreException { Pattern pcl= Pattern.compile("C160913"); Pattern pns= Pattern.compile("ns160913"); + char[] scl= pcl.pattern().toCharArray(); + char[] sns= pns.pattern().toCharArray(); IIndexBinding[] bindings; @@ -147,6 +163,10 @@ public class IndexSearchTest extends IndexTestBase { assertEquals(1, bindings.length); checkIsNamespace(bindings[0]); + bindings= fIndex.findBindings(sns, INDEX_FILTER, NPM); + assertEquals(1, bindings.length); + checkIsNamespace(bindings[0]); + bindings= fIndex.findBindings(pns, false, INDEX_FILTER, NPM); assertEquals(2, bindings.length); checkIsNamespace(bindings[0]); @@ -156,6 +176,10 @@ public class IndexSearchTest extends IndexTestBase { assertEquals(1, bindings.length); checkIsNamespace(bindings[0]); + bindings= fIndex.findBindings(new char[][]{sns, sns}, INDEX_FILTER, NPM); + assertEquals(1, bindings.length); + checkIsNamespace(bindings[0]); + bindings= fIndex.findBindings(new Pattern[]{pns, pns}, false, INDEX_FILTER, NPM); assertEquals(1, bindings.length); checkIsNamespace(bindings[0]); @@ -169,12 +193,17 @@ public class IndexSearchTest extends IndexTestBase { // the binding in the unnamed namespace is not visible in global scope. bindings= fIndex.findBindings(pcl, true, INDEX_FILTER, NPM); assertEquals(0, bindings.length); - } + + bindings= fIndex.findBindings(pcl.pattern().toCharArray(), INDEX_FILTER, NPM); + assertEquals(0, bindings.length); +} public void testFindEnumerator() throws CoreException { Pattern pEnumeration= Pattern.compile("E20061017"); Pattern pEnumerator= Pattern.compile("e20061017"); - + char[] sEnumeration= pEnumeration.pattern().toCharArray(); + char[] sEnumerator= pEnumerator.pattern().toCharArray(); + IIndexBinding[] bindings; // enumerators are found in global scope @@ -189,6 +218,9 @@ public class IndexSearchTest extends IndexTestBase { bindings= fIndex.findBindings(new Pattern[]{pEnumeration, pEnumerator}, true, INDEX_FILTER, NPM); assertEquals(0, bindings.length); + bindings= fIndex.findBindings(new char[][]{sEnumeration, sEnumerator}, INDEX_FILTER, NPM); + assertEquals(0, bindings.length); + bindings= fIndex.findBindings(new Pattern[]{pEnumeration, pEnumerator}, false, INDEX_FILTER, NPM); assertEquals(0, bindings.length); @@ -196,6 +228,10 @@ public class IndexSearchTest extends IndexTestBase { assertEquals(1, bindings.length); checkIsEnumeration(bindings[0]); + bindings= fIndex.findBindings(sEnumeration, INDEX_FILTER, NPM); + assertEquals(1, bindings.length); + checkIsEnumeration(bindings[0]); + bindings= fIndex.findBindings(pEnumeration, false, INDEX_FILTER, NPM); assertEquals(1, bindings.length); checkIsEnumeration(bindings[0]); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index 784200f7820..aef6653c7f5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation. + * Copyright (c) 2006, 2007 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -150,7 +151,7 @@ public class CPPFunctionTests extends PDOMTestBase { for (int i = 0; i < 2; i++) { ICPPFunction function = (ICPPFunction) bindings[i]; - assertEquals(1, pdom.getDeclarations(function).length); + assertEquals(1, pdom.findNames(function, IIndex.FIND_DECLARATIONS_DEFINITIONS).length); assertEquals(1, pdom.getDefinitions(function).length); IParameter[] parameters = function.getParameters(); switch (parameters.length) { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java index beb57fe1313..4544da09808 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software and others. + * Copyright (c) 2006, 2007 Symbian Software and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -52,7 +52,7 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase { public void testOverloadedInCommonHeader_ClassScope() throws CoreException { Pattern[] ManyOverloadedQuxPath = makePatternArray(new String[] {"ManyOverloaded","qux"}); - IBinding[] ManyOverloadedQux = pdom.findBindings(ManyOverloadedQuxPath, new NullProgressMonitor()); + IBinding[] ManyOverloadedQux = pdom.findBindings(ManyOverloadedQuxPath, true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(5,ManyOverloadedQux.length); // ManyOverloaded.qux() diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java index 0e74c22d4a9..ebf817dbfb0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinSingleTUTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Symbian Software and others. + * Copyright (c) 2006, 2007 Symbian Software and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; +import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -45,26 +46,26 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase { } public void testDistinctBindingsPresent() throws Exception { - IBinding[] fooBs = pdom.findBindings(Pattern.compile("foo"), new NullProgressMonitor()); + IBinding[] fooBs = pdom.findBindings(Pattern.compile("foo"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(3, fooBs.length); - IBinding[] barBs = pdom.findBindings(Pattern.compile("bar"), new NullProgressMonitor()); + IBinding[] barBs = pdom.findBindings(Pattern.compile("bar"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(8, barBs.length); - IBinding[] FooBs = pdom.findBindings(Pattern.compile("Foo"), new NullProgressMonitor()); + IBinding[] FooBs = pdom.findBindings(Pattern.compile("Foo"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(4, FooBs.length); Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"}); - IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, new NullProgressMonitor()); + IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(4, XBarBs.length); Pattern[] XFooPath = makePatternArray(new String[] {"X","Foo"}); - IBinding[] XFooPathBs = pdom.findBindings(XFooPath, new NullProgressMonitor()); + IBinding[] XFooPathBs = pdom.findBindings(XFooPath, true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, XFooPathBs.length); } public void testReferencesToGlobalBindings() throws Exception { - IBinding[] BarBs = pdom.findBindings(Pattern.compile("bar"), new NullProgressMonitor()); + IBinding[] BarBs = pdom.findBindings(Pattern.compile("bar"), false, IndexFilter.ALL, new NullProgressMonitor()); IBinding[] globalBs = getGlobalBindings(BarBs); assertEquals(4, globalBs.length); @@ -94,7 +95,7 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase { public void testReferencesToNamespacedBindings() throws Exception { Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"}); - IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, new NullProgressMonitor()); + IBinding[] XBarBs = pdom.findBindings(XBarAbsPath, false, IndexFilter.ALL, new NullProgressMonitor()); // X::bar() assertFunctionRefCount(new Class[] {}, XBarBs, 2); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java index 97ba02ddc6a..37e1f7ea1e2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/RaceCondition157992Test.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.pdom.tests; import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -33,7 +34,7 @@ public class RaceCondition157992Test extends PDOMTestBase { PDOM pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project); pdom.acquireReadLock(); - IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), new NullProgressMonitor()); + IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), true, IndexFilter.ALL, new NullProgressMonitor()); if(Bs.length==1) successes++; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java index a0d6ee8f6e5..f3f23f6922f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java @@ -15,7 +15,6 @@ package org.eclipse.cdt.core.index; import java.util.regex.Pattern; -import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.core.runtime.CoreException; @@ -225,13 +224,32 @@ public interface IIndex { public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException; /** - * Searches the global scope for all bindings of a given name and linkage. - * In case a binding exists in multiple projects, no duplicate bindings are returned. - * @param linkage the linkage to be searched - * @param name a simple (unqualified) name. - * @return an array of bindings + * Searches for all bindings in global scope with a given name. In case a binding exists in multiple projects, no duplicate bindings are returned. + * This method makes use of the BTree and is faster than the methods using patterns. + * @param names an array of names, which has to be matched by the qualified name of the bindings. + * @param filter a filter that allows for skipping parts of the index + * @param monitor a monitor to report progress + * @return an array of bindings matching the pattern + * @throws CoreException */ - public IBinding[] findInGlobalScope(ILinkage linkage, char[] name); + public IIndexBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException; + + /** + * Searches the global scope for all bindings with a given name. + * In case a binding exists in multiple projects, no duplicate bindings are returned. + * This method makes use of the BTree and is faster than the methods using patterns. + * + * This is fully equivalent to + *
+	 * findBindings(new Pattern[]{pattern}, isFullyQualified, filter, monitor);
+	 * 
+ * @param names an array of names, which has to be matched by the qualified name of the bindings. + * @param filter a filter that allows for skipping parts of the index + * @param monitor a monitor to report progress + * @return an array of bindings matching the pattern + * @throws CoreException + */ + public IIndexBinding[] findBindings(char[] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException; /** * Searches the given namespace for all bindings of a given name. @@ -249,7 +267,7 @@ public interface IIndex { * @return an array of bindings with the prefix * @throws CoreException */ - public IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException; + public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException; /** * Searches for all names that resolve to the given binding. You can limit the result to references, declarations diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java index 118174883db..3f1b0580c7a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IndexFilter.java @@ -44,20 +44,6 @@ public class IndexFilter { }; } - /** - * Get an IndexFilter that filters out bindings from linkages other than that - * specified - * @param target the linkage whose bindings should be retained - * @return an IndexFilter instance - */ - public static IndexFilter getFilter(final ILinkage target) { - return new IndexFilter() { - public boolean acceptLinkage(ILinkage linkage) { - return linkage.getID() == target.getID(); - } - }; - } - /** * Returns whether or not to include objects of the given linkage in the query. * @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java index c7f4905d8d9..cd9cf4508fe 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTIdExpression.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; @@ -22,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext; import org.eclipse.core.runtime.CoreException; @@ -88,8 +88,8 @@ public class CASTIdExpression extends CASTNode implements IASTIdExpression, IAST if (index != null) { try { b2 = index.findBindingsForPrefix( - n.toString(), - IndexFilter.getFilter(Linkage.C_LINKAGE)); + n.toCharArray(), + IndexFilter.getFilter(ILinkage.C_LINKAGE_ID)); } catch (CoreException e) { } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java index 697819c5da5..cabd2ce592d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTypedefNameSpecifier.java @@ -111,7 +111,7 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements if (index != null) { try { - IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter); + IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter); for (int i = 0; i < bindings.length; i++) { filtered.add(bindings[i]); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java index 96425c01600..1c902696970 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTBaseSpecifier.java @@ -150,7 +150,7 @@ public class CPPASTBaseSpecifier extends CPPASTNode implements if (index != null) { try { - IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter); + IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter); for (int i = 0; i < bindings.length; i++) { filtered.add(bindings[i]); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java index d1ad9278ae1..4e737172746 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTIdExpression.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTIdExpression; @@ -21,7 +22,6 @@ import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.IASTCompletionContext; import org.eclipse.core.runtime.CoreException; @@ -86,8 +86,8 @@ public class CPPASTIdExpression extends CPPASTNode implements IASTIdExpression, if (index != null) { try { b2 = index.findBindingsForPrefix( - n.toString(), - IndexFilter.getFilter(Linkage.CPP_LINKAGE)); + n.toCharArray(), + IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID)); } catch (CoreException e) { } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java index 76b5fd660f1..b520acdc869 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamedTypeSpecifier.java @@ -140,7 +140,7 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements if (index != null) { try { - IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter); + IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter); for (int i = 0; i < bindings.length; i++) { filtered.add(bindings[i]); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java index 2117015245b..a03e521f580 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDeclaration.java @@ -125,7 +125,7 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements if (index != null) { try { - IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter); + IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter); for (int i = 0; i < bindings.length; i++) { filtered.add(bindings[i]); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java index 773eafe9420..f577adf0652 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTUsingDirective.java @@ -110,7 +110,7 @@ public class CPPASTUsingDirective extends CPPASTNode implements if (index != null) { try { - IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter); + IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter); for (int i = 0; i < bindings.length; i++) { filtered.add(bindings[i]); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java index 56faf4d2ee3..fe95103848a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScope.java @@ -15,6 +15,8 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -26,18 +28,23 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.ObjectSet; -import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; /** * @author aniefer */ abstract public class CPPScope implements ICPPScope, IASTInternalScope { - public static class CPPScopeProblem extends ProblemBinding implements ICPPScope { + private static final IProgressMonitor NPM = new NullProgressMonitor(); + + public static class CPPScopeProblem extends ProblemBinding implements ICPPScope { public CPPScopeProblem( IASTNode node, int id, char[] arg ) { super( node, id, arg ); } @@ -91,8 +98,12 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope { if (index != null) { // Try looking this up in the PDOM if (physicalNode instanceof IASTTranslationUnit) { - IBinding[] bindings= index.findInGlobalScope(Linkage.CPP_LINKAGE, name.toCharArray()); - binding= CPPSemantics.resolveAmbiguities(name, bindings); + try { + IBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM); + binding= CPPSemantics.resolveAmbiguities(name, bindings); + } catch (CoreException e) { + CCorePlugin.log(e); + } } else if (physicalNode instanceof ICPPASTNamespaceDefinition) { ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java index 1bb0e938cfe..9fada0cc3e2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.regex.Pattern; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -155,7 +154,21 @@ public class CIndex implements IIndex { monitor.done(); return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]); } - + + public IIndexBinding[] findBindings(char[] name, IndexFilter filter, IProgressMonitor monitor) throws CoreException { + return findBindings(new char[][]{name}, filter, monitor); + } + + public IIndexBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException { + ArrayList result= new ArrayList(); + monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length); + for (int i = 0; !monitor.isCanceled() && i < fFragments.length; i++) { + result.addAll(Arrays.asList(fFragments[i].findBindings(names, filter, new SubProgressMonitor(monitor, 1)))); + } + monitor.done(); + return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]); + } + public IIndexName[] findNames(IBinding binding, int flags) throws CoreException { ArrayList result= new ArrayList(); for (int i = 0; i < fPrimaryFragmentCount; i++) { @@ -327,27 +340,6 @@ public class CIndex implements IIndex { return result; } - public IBinding[] findInGlobalScope(ILinkage linkage, char[] name) { - ArrayList result= new ArrayList(); - for (int i = 0; i < fFragments.length; i++) { - try { - IBinding[] part = fFragments[i].findInGlobalScope(linkage, name); - for (int j = 0; j < part.length; j++) { - IBinding binding = part[j]; - if (binding instanceof IIndexBinding) { - result.add(binding); - } - } - } catch (CoreException e) { - CCorePlugin.log(e); - } - } - if (!result.isEmpty()) { - return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]); - } - return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; - } - public IBinding[] findInNamespace(IBinding nsbinding, char[] name) { ArrayList result= new ArrayList(); for (int i = 0; i < fFragments.length; i++) { @@ -369,7 +361,7 @@ public class CIndex implements IIndex { return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; } - public IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException { + public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException { ArrayList result= new ArrayList(); for (int i = 0; i < fFragments.length; i++) { try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java index 685c2dcb791..88b64355d6a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.index; import java.util.regex.Pattern; -import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IIndex; @@ -95,19 +94,21 @@ final public class EmptyCIndex implements IIndex { return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; } - public IIndexBinding adaptBinding(IBinding binding) throws CoreException { - return null; - } - - public IBinding[] findInGlobalScope(ILinkage linkage, char[] name) { - return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; - } - public IBinding[] findInNamespace(IBinding nsbinding, char[] name) { return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; } - public IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException { + public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) { + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } + + public IIndexBinding[] findBindings(char[][] names, IndexFilter filter, + IProgressMonitor monitor) { + return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; + } + + public IIndexBinding[] findBindings(char[] names, IndexFilter filter, + IProgressMonitor monitor) { return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java index fedb7fed1ed..46653340fc6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java @@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.index; import java.util.regex.Pattern; -import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IIndex; @@ -107,7 +106,18 @@ public interface IIndexFragment { * @return an array of bindings matching the pattern * @throws CoreException */ - IIndexFragmentBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException; + IIndexFragmentBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException; + + /** + * Searches for all bindings with qualified names that seen as an array of simple names equals + * the given array of names. + * @param names an array of names the qualified name of the bindings have to match. + * @param filter a filter that allows for skipping parts of the index + * @param monitor a monitor to report progress + * @return an array of bindings matching the pattern + * @throws CoreException + */ + IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException; /** * Searches for all names that resolve to the given binding. You can limit the result to references, declarations @@ -135,11 +145,6 @@ public interface IIndexFragment { */ long getLastWriteAccess(); - /** - * Returns all bindings with the given name in the given linkage - */ - IBinding[] findInGlobalScope(ILinkage linkage, char[] name) throws CoreException; - /** * Returns all bindings with the given name in the given namespace */ @@ -148,5 +153,5 @@ public interface IIndexFragment { /** * Returns all bindings with the given prefix, accepted by the given filter */ - IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException; + IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 14b96f30373..b00b664f682 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.pdom; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.BitSet; import java.util.Collection; import java.util.HashMap; @@ -35,7 +36,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; -import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexName; @@ -49,6 +49,7 @@ import org.eclipse.cdt.internal.core.index.IIndexFragmentName; import org.eclipse.cdt.internal.core.index.IIndexProxyBinding; import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.Database; +import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector; import org.eclipse.cdt.internal.core.pdom.dom.IIndexLocationConverter; import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; @@ -204,13 +205,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return getFirstLinkageRecord() == 0; } - /** - * @deprecated use findDeclarations() instead. - */ - public IName[] getDeclarations(IBinding binding) throws CoreException { - return findNames(binding, IIndex.FIND_DECLARATIONS_DEFINITIONS); - } - /** * @deprecated use findDefinitions() instead */ @@ -328,20 +322,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } } - /** - * @deprecated - */ - public IBinding[] findBindings(Pattern pattern, IProgressMonitor monitor) throws CoreException { - return findBindings(new Pattern[] { pattern }, false, new IndexFilter(), monitor); - } - - /** - * @deprecated - */ - public IBinding[] findBindings(Pattern[] pattern, IProgressMonitor monitor) throws CoreException { - return findBindings(pattern, true, new IndexFilter(), monitor); - } - public IIndexBinding[] findBindings(Pattern pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException { return findBindings(new Pattern[] { pattern }, isFullyQualified, filter, monitor); } @@ -364,6 +344,29 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return finder.getBindings(); } + public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException { + ArrayList result= new ArrayList(); + for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { + PDOMLinkage linkage = (PDOMLinkage) iter.next(); + if (filter.acceptLinkage(linkage)) { + ArrayList bindings= new ArrayList(); + bindings.add(linkage); + for (int i=0; i < names.length; i++) { + char[] name= names[i]; + BindingCollector collector= new BindingCollector(linkage, name, filter, false); + for (Iterator in = bindings.iterator(); in.hasNext();) { + PDOMNode node= (PDOMNode) in.next(); + node.accept(collector); + } + bindings.clear(); + bindings.addAll(Arrays.asList(collector.getBindings())); + } + result.addAll(bindings); + } + } + return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]); + } + private void readLinkages() throws CoreException { // populate the linkage cache int record= getFirstLinkageRecord(); @@ -597,14 +600,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return fPath; } - public IBinding[] findInGlobalScope(ILinkage linkage, char[] name) throws CoreException { - PDOMLinkage pdomLinkage= adaptLinkage(linkage); - if (pdomLinkage != null) { - return pdomLinkage.findInGlobalScope(name); - } - return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; - } - public IBinding[] findInNamespace(IBinding nsbinding, char[] name) throws CoreException { IIndexProxyBinding ns= adaptBinding(nsbinding); if (ns instanceof ICPPNamespace) { @@ -618,7 +613,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; } - public IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException { + public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException { ArrayList result = new ArrayList(); for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { PDOMLinkage linkage = (PDOMLinkage) iter.next(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java similarity index 65% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java index 9f0c5be9980..5a9620612f4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBindingsInBTree.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 QNX Software Systems and others. + * Copyright (c) 2006, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,18 +7,25 @@ * * Contributors: * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.dom.IPDOMNode; +import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.core.runtime.CoreException; -public final class FindBindingsInBTree implements IBTreeVisitor { +/** + * Visitor to find bindings in a BTree or below a PDOMNode. Nested bindings are not visited. + * @since 4.0 + */ +public final class BindingCollector implements IBTreeVisitor, IPDOMVisitor { private final PDOMLinkage linkage; private final char[] name; private final boolean prefixLookup; @@ -29,7 +36,7 @@ public final class FindBindingsInBTree implements IBTreeVisitor { /** * Collects all bindings with given name. */ - public FindBindingsInBTree(PDOMLinkage linkage, char[] name) { + public BindingCollector(PDOMLinkage linkage, char[] name) { this(linkage, name, null, false); } @@ -37,7 +44,7 @@ public final class FindBindingsInBTree implements IBTreeVisitor { * Collects all bindings with given name, passing the filter. If prefixLookup is set to * true a binding is considered if its name starts with the given prefix. */ - public FindBindingsInBTree(PDOMLinkage linkage, char[] name, IndexFilter filter, boolean prefixLookup) { + public BindingCollector(PDOMLinkage linkage, char[] name, IndexFilter filter, boolean prefixLookup) { this.name = name; this.linkage= linkage; this.filter= filter; @@ -46,6 +53,10 @@ public final class FindBindingsInBTree implements IBTreeVisitor { public int compare(int record) throws CoreException { PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record)); + return compare(node); + } + + private int compare(PDOMNamedNode node) throws CoreException { if (prefixLookup) { return node.getDBName().comparePrefix(name); } @@ -57,13 +68,32 @@ public final class FindBindingsInBTree implements IBTreeVisitor { return true; PDOMBinding tBinding = linkage.getPDOM().getBinding(record); + if (tBinding != null) { + visit(tBinding); + } + return true; // look for more + } + + private void visit(PDOMBinding tBinding) { if (filter == null || filter.acceptBinding(tBinding)) { bindings.add(tBinding); - } - return true; // look for more + } } public IBinding[] getBindings() { return (IBinding[])bindings.toArray(new IBinding[bindings.size()]); } + + public boolean visit(IPDOMNode node) throws CoreException { + if (node instanceof PDOMBinding) { + PDOMBinding pb= (PDOMBinding) node; + if (compare(pb) == 0) { + visit(pb); + } + } + return false; // don't visit children + } + + public void leave(IPDOMNode node) throws CoreException { + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index 093ccf2e734..ef2c3713112 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -107,21 +107,25 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } public void accept(final IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); - getIndex().accept(new IBTreeVisitor() { - public int compare(int record) throws CoreException { - return 0; - } - public boolean visit(int record) throws CoreException { - PDOMBinding binding = pdom.getBinding(record); - if (binding != null) { - if (visitor.visit(binding)) - binding.accept(visitor); - visitor.leave(binding); + if (visitor instanceof IBTreeVisitor) { + getIndex().accept((IBTreeVisitor) visitor); + } + else { + getIndex().accept(new IBTreeVisitor() { + public int compare(int record) throws CoreException { + return 0; } - return true; - } - }); + public boolean visit(int record) throws CoreException { + PDOMBinding binding = pdom.getBinding(record); + if (binding != null) { + if (visitor.visit(binding)) + binding.accept(visitor); + visitor.leave(binding); + } + return true; + } + }); + } } public ILinkage getLinkage() throws CoreException { @@ -221,16 +225,9 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } public abstract int getBindingType(IBinding binding); - - public IBinding[] findInGlobalScope(char[] name) throws CoreException { - FindBindingsInBTree visitor= new FindBindingsInBTree(this, name); - getIndex().accept(visitor); - - return visitor.getBindings(); - } - public IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException { - FindBindingsInBTree visitor = new FindBindingsInBTree(this, prefix.toCharArray(), filter, true); + public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException { + BindingCollector visitor = new BindingCollector(this, prefix, filter, true); getIndex().accept(visitor); return visitor.getBindings(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java index 5948da31eeb..24e7094434c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPNamespace.java @@ -17,11 +17,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp; import java.util.ArrayList; import java.util.List; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -34,9 +30,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; -import org.eclipse.cdt.internal.core.pdom.dom.FindBindingsInBTree; +import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; @@ -71,21 +66,25 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName } public void accept(final IPDOMVisitor visitor) throws CoreException { - super.accept(visitor); - getIndex().accept(new IBTreeVisitor() { - public int compare(int record) throws CoreException { - return 0; - } - public boolean visit(int record) throws CoreException { - PDOMBinding binding = pdom.getBinding(record); - if (binding != null) { - if (visitor.visit(binding)) - binding.accept(visitor); - visitor.leave(binding); + if (visitor instanceof IBTreeVisitor) { + getIndex().accept((IBTreeVisitor) visitor); + } + else { + getIndex().accept(new IBTreeVisitor() { + public int compare(int record) throws CoreException { + return 0; } - return true; - } - }); + public boolean visit(int record) throws CoreException { + PDOMBinding binding = pdom.getBinding(record); + if (binding != null) { + if (visitor.visit(binding)) + binding.accept(visitor); + visitor.leave(binding); + } + return true; + } + }); + } } public void addChild(PDOMNode child) throws CoreException { @@ -107,7 +106,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName public IBinding[] find(String name, boolean prefixLookup) { try { - FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), null, prefixLookup); + BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup); getIndex().accept(visitor); return visitor.getBindings(); } catch (CoreException e) { @@ -118,7 +117,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName public IBinding getBinding(IASTName name, boolean resolve) throws DOMException { try { - FindBindingsInBTree visitor= new FindBindingsInBTree(getLinkageImpl(), name.toCharArray()); + BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray()); getIndex().accept(visitor); IBinding[] bindings= visitor.getBindings(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java index dc4f0a84e73..c5f284af9e2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java @@ -366,10 +366,6 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { // int a1; // int b1; // }; - // typedef struct S2 { - // int a2; - // int b2; - // } S2; // typedef struct S3 { // int a3; // int b3; @@ -388,14 +384,6 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { assertEquals(0, item.getItemCount()); checkMethodTable(new String[] {"a1", "b1"}); - editor.selectAndReveal(content.indexOf("b2"), 1); - openTypeHierarchy(editor); - tree = getHierarchyViewer().getTree(); - item= checkTreeNode(tree, 0, "S2"); - item= checkTreeNode(item, 0, "S2"); - assertEquals(0, item.getItemCount()); - checkMethodTable(new String[] {"a2", "b2"}); - editor.selectAndReveal(content.indexOf("a3"), 1); openTypeHierarchy(editor); tree = getHierarchyViewer().getTree(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java index d088adba1aa..067b5cefa60 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2006 QNX Software Systems and others. + * Copyright (c) 2005, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.ui.wizards.classwizard; import java.util.ArrayList; import java.util.List; -import java.util.regex.Pattern; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -401,13 +400,13 @@ public class NewClassWizardUtil { try { String fullyQualifiedTypeName = typeName.getFullyQualifiedName(); try { - IndexFilter filter= new IndexFilter() { - public boolean acceptLinkage(ILinkage linkage) { - return linkage.getID() == ILinkage.CPP_LINKAGE_ID; - } - }; - // mstodo revisit, the pattern must be split - IBinding[] bindings = index.findBindings(Pattern.compile(typeName.getName()), true, filter, new NullProgressMonitor()); + IndexFilter filter= IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID); + String[] nameStrs= fullyQualifiedTypeName.split("::"); //$NON-NLS-1$ + char[][] names= new char[nameStrs.length][]; + for (int i = 0; i < names.length; i++) { + names[i]= nameStrs[i].toCharArray(); + } + IBinding[] bindings = index.findBindings(names, filter, new NullProgressMonitor()); boolean sameTypeNameExists = false; boolean sameNameDifferentTypeExists = false;