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 ba6532b8c44..7a34db5fcff 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 @@ -553,16 +553,16 @@ public class IndexBugsTests extends BaseTestCase { } }; - IBinding[] bindings= fIndex.findBindingsForPrefix(new char[] {'a'}, true, NON_FUNCTIONS); + IBinding[] bindings= fIndex.findBindingsForPrefix(new char[] {'a'}, true, NON_FUNCTIONS, null); assertEquals(3,bindings.length); - bindings= fIndex.findBindingsForPrefix(new char[] {'a'}, false, NON_FUNCTIONS); + bindings= fIndex.findBindingsForPrefix(new char[] {'a'}, false, NON_FUNCTIONS, null); assertEquals(6,bindings.length); - bindings= fIndex.findBindingsForPrefix(new char[] {'a','A'}, true, NON_FUNCTIONS); + bindings= fIndex.findBindingsForPrefix(new char[] {'a','A'}, true, NON_FUNCTIONS, null); assertEquals(1,bindings.length); - bindings= fIndex.findBindingsForPrefix(new char[] {'a','A'}, false, NON_FUNCTIONS); + bindings= fIndex.findBindingsForPrefix(new char[] {'a','A'}, false, NON_FUNCTIONS, null); assertEquals(2, bindings.length); } finally { 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 d6ef8e5ea62..630161940bf 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 @@ -39,7 +39,7 @@ import org.eclipse.core.runtime.CoreException; public class IndexSearchTest extends IndexTestBase { - private static final IndexFilter INDEX_FILTER = new IndexFilter(); + private static final IndexFilter INDEX_FILTER = IndexFilter.ALL; public static TestSuite suite() { TestSuite suite= suite(IndexSearchTest.class, "_"); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java index 745b48b47e2..d263b2d7729 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CCompositeTypeTests.java @@ -56,7 +56,7 @@ public class CCompositeTypeTests extends PDOMTestBase { //TODO PDOM does not distinguish between a struct or union in C public void _testSimpleCStructureDistinction() throws Exception { assertType(pdom, "SimpleCStructure", ICompositeType.class); - IIndexBinding[] bindings = pdom.findBindings(Pattern.compile("SimpleCStructure"), false, new IndexFilter(), new NullProgressMonitor()); + IIndexBinding[] bindings = pdom.findBindings(Pattern.compile("SimpleCStructure"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bindings.length); assertEquals(ICompositeType.k_struct, ((ICompositeType)bindings[0]).getKey()); } @@ -148,7 +148,7 @@ public class CCompositeTypeTests extends PDOMTestBase { // TODO PDOM does not distinguish between a struct or union in C public void _testCUnionDistinction() throws Exception { - IIndexBinding[] bindings = pdom.findBindings(Pattern.compile("CUnion1"), false, new IndexFilter(), new NullProgressMonitor()); + IIndexBinding[] bindings = pdom.findBindings(Pattern.compile("CUnion1"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bindings.length); assertEquals(ICompositeType.k_union, ((ICompositeType)bindings[0]).getKey()); } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java index 02b34f23845..49653ab3402 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java @@ -74,7 +74,7 @@ public class DefDeclTests extends PDOMTestBase { private IBinding findSingleBinding(String elName) throws CoreException { IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, - new IndexFilter(), new NullProgressMonitor()); + IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, binds.length); assertEquals(elName, binds[0].getName()); IBinding element = binds[0]; @@ -283,7 +283,7 @@ public class DefDeclTests extends PDOMTestBase { String num = "_t04"; String elName = "type" + num; - IBinding[] bindings = pdom.findBindings(Pattern.compile(elName), false, new IndexFilter(), new NullProgressMonitor()); + IBinding[] bindings = pdom.findBindings(Pattern.compile(elName), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(2,bindings.length); IBinding typedef = bindings[0] instanceof ITypedef ? bindings[0] : bindings[1]; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java index cbef7b4e318..b190beb3878 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/EnumerationTests.java @@ -54,7 +54,7 @@ public class EnumerationTests extends PDOMTestBase { public void testC() throws Exception { // Check bindings Pattern pattern = Pattern.compile("TestCEnum"); - IBinding[] bindings = pdom.findBindings(pattern, false, new IndexFilter(), new NullProgressMonitor()); + IBinding[] bindings = pdom.findBindings(pattern, false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bindings.length); IEnumeration enumeration = (IEnumeration)bindings[0]; assertEquals("TestCEnum", enumeration.getName()); @@ -86,7 +86,7 @@ public class EnumerationTests extends PDOMTestBase { public void testCPP() throws Exception { // Check bindings Pattern pattern = Pattern.compile("TestCPPEnum"); - IBinding[] bindings = pdom.findBindings(pattern, false, new IndexFilter(), new NullProgressMonitor()); + IBinding[] bindings = pdom.findBindings(pattern, false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bindings.length); IEnumeration enumeration = (IEnumeration)bindings[0]; assertEquals("TestCPPEnum", enumeration.getName()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java index c605eb0d13b..edcbe635f7a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java @@ -71,7 +71,7 @@ public class FilesOnReindexTests extends PDOMTestBase { IIndex index = CCorePlugin.getIndexManager().getIndex(project); assertNotNull(index.getFile(IndexLocationFactory.getWorkspaceIFL(file))); - IBinding[] bs = index.findBindings(Pattern.compile("C"), true, new IndexFilter(), new NullProgressMonitor()); + IBinding[] bs = index.findBindings(Pattern.compile("C"), true, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bs.length); IIndexBinding binding = (IIndexBinding) bs[0]; diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java index 6e301d39ceb..d3641dd3f85 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/NamespaceTests.java @@ -41,7 +41,7 @@ public class NamespaceTests extends PDOMTestBase { protected ICProject project; protected PDOM pdom; protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); - protected IndexFilter INDEX_FILTER = new IndexFilter(); + protected IndexFilter INDEX_FILTER = IndexFilter.ALL; public static Test suite() { return suite(NamespaceTests.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java index 8acc7807d90..fa07852f6ac 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMProviderTests.java @@ -111,7 +111,7 @@ public class PDOMProviderTests extends PDOMTestBase { public boolean acceptBinding(IBinding binding) { return binding instanceof ICPPClassType; } - }); + }, null); assertEquals(2, bindings.length); } @@ -185,7 +185,7 @@ public class PDOMProviderTests extends PDOMTestBase { public boolean acceptBinding(IBinding binding) { return binding instanceof ICPPClassType; } - }); + }, null); assertEquals(2, bindings.length); } @@ -198,7 +198,7 @@ public class PDOMProviderTests extends PDOMTestBase { public boolean acceptBinding(IBinding binding) { return binding instanceof ICPPClassType; } - }); + }, null); assertEquals(2, bindings.length); } @@ -211,7 +211,7 @@ public class PDOMProviderTests extends PDOMTestBase { public boolean acceptBinding(IBinding binding) { return binding instanceof ICPPClassType; } - }); + }, null); assertEquals(3, bindings.length); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java index 5e07e63620a..3f61b38cc25 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMSearchTest.java @@ -45,7 +45,7 @@ public class PDOMSearchTest extends PDOMTestBase { protected ICProject project; protected PDOM pdom; protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); - protected IndexFilter INDEX_FILTER = new IndexFilter(); + protected IndexFilter INDEX_FILTER = IndexFilter.ALL; public static Test suite() { return suite(PDOMSearchTest.class); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 742ad4a8581..be85e119918 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -115,7 +115,7 @@ public class PDOMTestBase extends BaseTestCase { for (int i = 0; i < segments.length; i++) { pattern[i] = Pattern.compile(segments[i]); } - return pdom.findBindings(pattern, true, new IndexFilter(), PROGRESS); + return pdom.findBindings(pattern, true, IndexFilter.ALL, PROGRESS); } /** diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java index e3ce3f63682..003e2c0ab39 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/TypesTests.java @@ -56,7 +56,7 @@ public class TypesTests extends PDOMTestBase { public void testC() throws Exception { // Get the binding for A::f - IBinding [] CAs = pdom.findBindings(Pattern.compile("CA"), false, new IndexFilter(), new NullProgressMonitor()); + IBinding [] CAs = pdom.findBindings(Pattern.compile("CA"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, CAs.length); ICompositeType CA = (ICompositeType)CAs[0]; IField [] CAfields = CA.getFields(); @@ -73,7 +73,7 @@ public class TypesTests extends PDOMTestBase { public void testCPP() throws Exception { // Get the binding for A::f - IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, new IndexFilter(), new NullProgressMonitor()); + IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, As.length); ICPPClassType A = (ICPPClassType)As[0]; ICPPMethod[] Amethods = A.getDeclaredMethods(); @@ -89,7 +89,7 @@ public class TypesTests extends PDOMTestBase { } public void test145351() throws Exception { - IBinding [] bindings = pdom.findBindings(Pattern.compile("spinlock_t"), false, new IndexFilter(), new NullProgressMonitor()); + IBinding [] bindings = pdom.findBindings(Pattern.compile("spinlock_t"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, bindings.length); ITypedef spinlock_t = (ITypedef)bindings[0]; IName [] refs = pdom.findNames(spinlock_t, IIndex.FIND_REFERENCES); 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 f65c6d01c74..67c7d62bcc0 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 @@ -204,7 +204,7 @@ public interface IIndex { * @param pattern the pattern the name of the binding has to match. * @param isFullyQualified if true, binding must be in global scope * @param filter a filter that allows for skipping parts of the index - * @param monitor a monitor to report progress + * @param monitor a monitor to report progress, may be null. * @return an array of bindings matching the pattern * @throws CoreException */ @@ -217,7 +217,7 @@ public interface IIndex { * @param patterns an array of patterns the names of the qualified name of the bindings have to match. * @param isFullyQualified if true, the array of pattern specifies the fully qualified name * @param filter a filter that allows for skipping parts of the index - * @param monitor a monitor to report progress + * @param monitor a monitor to report progress, may be null. * @return an array of bindings matching the pattern * @throws CoreException */ @@ -228,7 +228,7 @@ public interface IIndex { * 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 + * @param monitor a monitor to report progress, may be null. * @return an array of bindings matching the pattern * @throws CoreException */ @@ -245,7 +245,7 @@ public interface IIndex { * * @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 + * @param monitor a monitor to report progress, may be null. * @return an array of bindings matching the pattern * @throws CoreException */ @@ -256,10 +256,11 @@ public interface IIndex { * @param prefix the prefix with which all returned bindings must start * @param filescope if true, only bindings at file scope are returned * @param filter a filter that allows for skipping parts of the index + * @param monitor a monitor for progress reporting and cancellation, may be null * @return an array of bindings with the prefix * @throws CoreException */ - public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter) throws CoreException; + public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) 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 3f1b0580c7a..5def4bde9a6 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 @@ -15,6 +15,8 @@ package org.eclipse.cdt.core.index; import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.internal.core.index.DeclaredBindingsFilter; +import org.eclipse.core.runtime.CoreException; /** * Can be subclassed and used for queries in the index. @@ -27,8 +29,9 @@ import org.eclipse.cdt.core.dom.ast.IBinding; *

*/ -public class IndexFilter { - public static final IndexFilter ALL = new IndexFilter(); +abstract public class IndexFilter { + public static final IndexFilter ALL = new IndexFilter() {}; + public static final IndexFilter ALL_DECLARED = new DeclaredBindingsFilter(); /** * Get an IndexFilter that filters out bindings from linkages other than that @@ -69,8 +72,9 @@ public class IndexFilter { * * @param binding the binding being checked for validity * @return whether or not the binding is valid + * @throws CoreException */ - public boolean acceptBinding(IBinding binding) { + public boolean acceptBinding(IBinding binding) throws CoreException { return true; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java index 5cdb03d1c89..a45788a337e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java @@ -106,7 +106,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; /** * Created on Nov 5, 2004 @@ -1341,14 +1340,12 @@ public class CVisitor { IIndex index = tu.getIndex(); if (index != null) { try { - IndexFilter filter = IndexFilter - .getFilter(ILinkage.C_LINKAGE_ID); - IBinding[] bindings = prefix ? index.findBindingsForPrefix( - name.toCharArray(), true, filter) : index.findBindings( - name.toCharArray(), filter, - new NullProgressMonitor()); + IndexFilter filter = IndexFilter.getFilter(ILinkage.C_LINKAGE_ID); + IBinding[] bindings= prefix + ? index.findBindingsForPrefix(name.toCharArray(), true, filter, null) + : index.findBindings(name.toCharArray(), filter, null); - result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings); + result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings); } catch (CoreException e) { CCorePlugin.log(e); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java index b7e3f4177b4..709684c6c94 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java @@ -134,7 +134,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; /** * @author aniefer @@ -1048,8 +1047,8 @@ public class CPPSemantics { try { IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID); IBinding[] bindings = data.prefixLookup ? - index.findBindingsForPrefix(data.astName.toCharArray(), true, filter) : - index.findBindings(data.astName.toCharArray(), filter, new NullProgressMonitor()); + index.findBindingsForPrefix(data.astName.toCharArray(), true, filter, null) : + index.findBindings(data.astName.toCharArray(), filter, null); mergeResults(data, bindings, true); useASTResults = false; } catch (CoreException e) { 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 921112232fd..6d32e68afb3 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 @@ -42,6 +42,7 @@ import org.eclipse.cdt.internal.core.index.composite.c.CCompositesFactory; import org.eclipse.cdt.internal.core.index.composite.cpp.CPPCompositesFactory; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor; public class CIndex implements IIndex { @@ -98,7 +99,7 @@ public class CIndex implements IIndex { IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][]; for (int i = 0; i < fPrimaryFragmentCount; i++) { try { - IBinding[] part = fFragments[i].findBindings(patterns, isFullyQualified, retargetFilter(linkages[j], filter), new SubProgressMonitor(monitor, 1)); + IBinding[] part = fFragments[i].findBindings(patterns, isFullyQualified, retargetFilter(linkages[j], filter), monitor); fragmentBindings[i] = new IIndexFragmentBinding[part.length]; System.arraycopy(part, 0, fragmentBindings[i], 0, part.length); } catch (CoreException e) { @@ -306,6 +307,9 @@ public class CIndex implements IIndex { return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; } } else { + if (monitor == null) { + monitor= new NullProgressMonitor(); + } List result = new ArrayList(); ILinkage[] linkages = Linkage.getAllLinkages(); monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length); @@ -425,7 +429,7 @@ public class CIndex implements IIndex { private IndexFilter retargetFilter(final ILinkage linkage, final IndexFilter filter) { return new IndexFilter() { - public boolean acceptBinding(IBinding binding) { + public boolean acceptBinding(IBinding binding) throws CoreException { return filter.acceptBinding(binding); } public boolean acceptImplicitMethods() { @@ -437,9 +441,9 @@ public class CIndex implements IIndex { }; } - public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter) throws CoreException { + public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException { if(SPECIALCASE_SINGLES && fFragments.length==1) { - return fFragments[0].findBindingsForPrefix(prefix, filescope, filter); + return fFragments[0].findBindingsForPrefix(prefix, filescope, filter, monitor); } else { List result = new ArrayList(); ILinkage[] linkages = Linkage.getAllLinkages(); @@ -448,7 +452,7 @@ public class CIndex implements IIndex { IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][]; for (int i = 0; i < fPrimaryFragmentCount; i++) { try { - IBinding[] part = fFragments[i].findBindingsForPrefix(prefix, filescope, retargetFilter(linkages[j], filter)); + IBinding[] part = fFragments[i].findBindingsForPrefix(prefix, filescope, retargetFilter(linkages[j], filter), monitor); fragmentBindings[i] = new IIndexFragmentBinding[part.length]; System.arraycopy(part, 0, fragmentBindings[i], 0, part.length); } catch (CoreException e) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java new file mode 100644 index 00000000000..d0b3b7a6394 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/DeclaredBindingsFilter.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.index; + +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.core.runtime.CoreException; + +public class DeclaredBindingsFilter extends IndexFilter { + public boolean acceptBinding(IBinding binding) throws CoreException { + if (binding instanceof IIndexFragmentBinding) { + return ((IIndexFragmentBinding) binding).hasDeclaration(); + } + return true; // composite bindings don't support that kind of check. + } +} 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 713a8320d4b..2e6205aa743 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 @@ -99,7 +99,7 @@ final public class EmptyCIndex implements IIndex { return null; } - public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter) { + public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) { return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY; } 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 6b21597f302..e33a81980a3 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 @@ -110,7 +110,7 @@ public interface IIndexFragment { * @param patterns an array of patterns the names of the qualified name of the bindings have to match. * @param isFullyQualified if true, the array of pattern specifies the fully qualified name * @param filter a filter that allows for skipping parts of the index - * @param monitor a monitor to report progress + * @param monitor a monitor to report progress, may be null * @return an array of bindings matching the pattern * @throws CoreException */ @@ -121,7 +121,7 @@ public interface IIndexFragment { * 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 + * @param monitor a monitor to report progress, may be null * @return an array of bindings matching the pattern * @throws CoreException */ @@ -155,8 +155,9 @@ public interface IIndexFragment { /** * Returns all bindings with the given prefix, accepted by the given filter + * @param monitor to report progress, may be null */ - IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter) throws CoreException; + IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException; /** * Returns the linkages that are contained in this fragment diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java index 494eff58ccf..6223a47d8c7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java @@ -34,4 +34,10 @@ public interface IIndexFragmentBinding extends Comparable, IIndexBinding { * in its associated fragment. */ boolean hasDefinition() throws CoreException; + + /** + * Returns whether this binding has a declaration or definition associated with + * it in its associated fragment. + */ + boolean hasDeclaration() throws CoreException; } \ No newline at end of file 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 d162e1bf7ea..f564cfbf506 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 @@ -10,6 +10,7 @@ * Markus Schorn (Wind River Systems) * IBM Corporation * Andrew Ferguson (Symbian) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; @@ -61,6 +62,8 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.Status; @@ -377,6 +380,9 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { } public IIndexFragmentBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException { + if (monitor == null) { + monitor= new NullProgressMonitor(); + } BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter, monitor); for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { PDOMLinkage linkage = (PDOMLinkage) iter.next(); @@ -670,7 +676,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { return fPath; } - public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter) throws CoreException { + public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException { ArrayList result= new ArrayList(); for (Iterator iter= fLinkageIDCache.values().iterator(); iter.hasNext();) { PDOMLinkage linkage= (PDOMLinkage) iter.next(); @@ -678,14 +684,25 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { IBinding[] bindings; if(filescope) { BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false); - linkage.accept(visitor); + visitor.setMonitor(monitor); + try { + linkage.accept(visitor); + } + catch (OperationCanceledException e) { + } bindings= visitor.getBindings(); } else { BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false); - linkage.accept(visitor); - linkage.accept(new ApplyVisitor(linkage, visitor)); + visitor.setMonitor(monitor); + try { + linkage.accept(visitor); + linkage.accept(new ApplyVisitor(linkage, visitor)); + } + catch (OperationCanceledException e) { + } bindings= visitor.getBindings(); } + for (int j = 0; j < bindings.length; j++) { result.add(bindings[j]); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java index 7fbab8370cb..d5e5ab016d8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.core.runtime.CoreException; /** * Visitor to find bindings in a BTree or below a PDOMNode. Nested bindings are not visited. @@ -40,7 +41,7 @@ public final class BindingCollector extends NamedNodeCollector { this.filter= filter; } - public boolean addNode(PDOMNamedNode tBinding) { + public boolean addNode(PDOMNamedNode tBinding) throws CoreException { if (tBinding instanceof IBinding) { if (filter == null || filter.acceptBinding((IBinding) tBinding)) { return super.addNode(tBinding); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java index 8a341ad95f5..66eae4e301e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java @@ -17,6 +17,8 @@ import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; /** * Visitor to find named nodes in a BTree or below a PDOMNode. Nested nodes are not visited. @@ -27,6 +29,8 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor { private final char[] name; private final boolean prefixLookup; private final boolean caseSensitive; + private IProgressMonitor monitor= null; + private int monitorCheckCounter= 0; private List nodes = new ArrayList(); @@ -48,6 +52,14 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor { this.caseSensitive= caseSensitive; } + /** + * Allows to cancel a visit. If set a visit may throw an OperationCancelledException. + * @since 4.0 + */ + public void setMonitor(IProgressMonitor pm) { + monitor= pm; + } + final public int compare(int record) throws CoreException { PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record)); return compare(node); @@ -71,6 +83,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor { } final public boolean visit(int record) throws CoreException { + if (monitor != null) + checkCancelled(); + if (record == 0) return true; @@ -83,8 +98,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor { /** * Return true to continue the visit. + * @throws CoreException */ - protected boolean addNode(PDOMNamedNode node) { + protected boolean addNode(PDOMNamedNode node) throws CoreException { nodes.add(node); return true; // look for more } @@ -98,6 +114,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor { } final public boolean visit(IPDOMNode node) throws CoreException { + if (monitor != null) + checkCancelled(); + if (node instanceof PDOMNamedNode) { PDOMNamedNode pb= (PDOMNamedNode) node; if (compare(pb) == 0) { @@ -107,6 +126,12 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor { return false; // don't visit children } + private void checkCancelled() { + if (++monitorCheckCounter % 0x100 == 0 && monitor.isCanceled()) { + throw new OperationCanceledException(); + } + } + final public void leave(IPDOMNode node) throws CoreException { } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 4b6e8537f7c..029bdb6540a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -76,7 +76,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen return record; } - public boolean hasDeclarations() throws CoreException { + public boolean hasDeclaration() throws CoreException { Database db = pdom.getDB(); return db.getInt(record + FIRST_DECL_OFFSET) != 0 || db.getInt(record + FIRST_DEF_OFFSET) != 0; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java index ced62ed1b22..6f69fef5354 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java @@ -149,6 +149,11 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment return true; } + public boolean hasDeclaration() throws CoreException { + // parameter bindings do not span index fragments + return true; + } + public int compareTo(Object arg0) { throw new PDOMNotImplementedError(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java index de1905d41d4..3be8b5c4345 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java @@ -204,6 +204,11 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IIndexFra return true; } + public boolean hasDeclaration() throws CoreException { + // parameter bindings do not span index fragments + return true; + } + public int compareTo(Object arg0) { throw new PDOMNotImplementedError(); } diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java index 14f27f4f846..73df3545be1 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java @@ -240,8 +240,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects()); try { index.acquireReadLock(); - IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL); -// IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL, monitor); + IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL_DECLARED, monitor); for(int i=0; i