1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Fix for 183379 in coop with Anton Leherbauer, progress monitor for findBindingsForPrefix.

This commit is contained in:
Markus Schorn 2007-04-23 14:34:22 +00:00
parent b42099a8c7
commit c5c4332df0
28 changed files with 149 additions and 60 deletions

View file

@ -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); 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); 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); 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); assertEquals(2, bindings.length);
} }
finally { finally {

View file

@ -39,7 +39,7 @@ import org.eclipse.core.runtime.CoreException;
public class IndexSearchTest extends IndexTestBase { 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() { public static TestSuite suite() {
TestSuite suite= suite(IndexSearchTest.class, "_"); TestSuite suite= suite(IndexSearchTest.class, "_");

View file

@ -56,7 +56,7 @@ public class CCompositeTypeTests extends PDOMTestBase {
//TODO PDOM does not distinguish between a struct or union in C //TODO PDOM does not distinguish between a struct or union in C
public void _testSimpleCStructureDistinction() throws Exception { public void _testSimpleCStructureDistinction() throws Exception {
assertType(pdom, "SimpleCStructure", ICompositeType.class); 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(1, bindings.length);
assertEquals(ICompositeType.k_struct, ((ICompositeType)bindings[0]).getKey()); 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 // TODO PDOM does not distinguish between a struct or union in C
public void _testCUnionDistinction() throws Exception { 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(1, bindings.length);
assertEquals(ICompositeType.k_union, ((ICompositeType)bindings[0]).getKey()); assertEquals(ICompositeType.k_union, ((ICompositeType)bindings[0]).getKey());
} }

View file

@ -74,7 +74,7 @@ public class DefDeclTests extends PDOMTestBase {
private IBinding findSingleBinding(String elName) throws CoreException { private IBinding findSingleBinding(String elName) throws CoreException {
IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true,
new IndexFilter(), new NullProgressMonitor()); IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, binds.length); assertEquals(1, binds.length);
assertEquals(elName, binds[0].getName()); assertEquals(elName, binds[0].getName());
IBinding element = binds[0]; IBinding element = binds[0];
@ -283,7 +283,7 @@ public class DefDeclTests extends PDOMTestBase {
String num = "_t04"; String num = "_t04";
String elName = "type" + num; 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); assertEquals(2,bindings.length);
IBinding typedef = bindings[0] instanceof ITypedef ? bindings[0] : bindings[1]; IBinding typedef = bindings[0] instanceof ITypedef ? bindings[0] : bindings[1];

View file

@ -54,7 +54,7 @@ public class EnumerationTests extends PDOMTestBase {
public void testC() throws Exception { public void testC() throws Exception {
// Check bindings // Check bindings
Pattern pattern = Pattern.compile("TestCEnum"); 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); assertEquals(1, bindings.length);
IEnumeration enumeration = (IEnumeration)bindings[0]; IEnumeration enumeration = (IEnumeration)bindings[0];
assertEquals("TestCEnum", enumeration.getName()); assertEquals("TestCEnum", enumeration.getName());
@ -86,7 +86,7 @@ public class EnumerationTests extends PDOMTestBase {
public void testCPP() throws Exception { public void testCPP() throws Exception {
// Check bindings // Check bindings
Pattern pattern = Pattern.compile("TestCPPEnum"); 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); assertEquals(1, bindings.length);
IEnumeration enumeration = (IEnumeration)bindings[0]; IEnumeration enumeration = (IEnumeration)bindings[0];
assertEquals("TestCPPEnum", enumeration.getName()); assertEquals("TestCPPEnum", enumeration.getName());

View file

@ -71,7 +71,7 @@ public class FilesOnReindexTests extends PDOMTestBase {
IIndex index = CCorePlugin.getIndexManager().getIndex(project); IIndex index = CCorePlugin.getIndexManager().getIndex(project);
assertNotNull(index.getFile(IndexLocationFactory.getWorkspaceIFL(file))); 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); assertEquals(1, bs.length);
IIndexBinding binding = (IIndexBinding) bs[0]; IIndexBinding binding = (IIndexBinding) bs[0];

View file

@ -41,7 +41,7 @@ public class NamespaceTests extends PDOMTestBase {
protected ICProject project; protected ICProject project;
protected PDOM pdom; protected PDOM pdom;
protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
protected IndexFilter INDEX_FILTER = new IndexFilter(); protected IndexFilter INDEX_FILTER = IndexFilter.ALL;
public static Test suite() { public static Test suite() {
return suite(NamespaceTests.class); return suite(NamespaceTests.class);

View file

@ -111,7 +111,7 @@ public class PDOMProviderTests extends PDOMTestBase {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) {
return binding instanceof ICPPClassType; return binding instanceof ICPPClassType;
} }
}); }, null);
assertEquals(2, bindings.length); assertEquals(2, bindings.length);
} }
@ -185,7 +185,7 @@ public class PDOMProviderTests extends PDOMTestBase {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) {
return binding instanceof ICPPClassType; return binding instanceof ICPPClassType;
} }
}); }, null);
assertEquals(2, bindings.length); assertEquals(2, bindings.length);
} }
@ -198,7 +198,7 @@ public class PDOMProviderTests extends PDOMTestBase {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) {
return binding instanceof ICPPClassType; return binding instanceof ICPPClassType;
} }
}); }, null);
assertEquals(2, bindings.length); assertEquals(2, bindings.length);
} }
@ -211,7 +211,7 @@ public class PDOMProviderTests extends PDOMTestBase {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) {
return binding instanceof ICPPClassType; return binding instanceof ICPPClassType;
} }
}); }, null);
assertEquals(3, bindings.length); assertEquals(3, bindings.length);
} }
} }

View file

@ -45,7 +45,7 @@ public class PDOMSearchTest extends PDOMTestBase {
protected ICProject project; protected ICProject project;
protected PDOM pdom; protected PDOM pdom;
protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor(); protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
protected IndexFilter INDEX_FILTER = new IndexFilter(); protected IndexFilter INDEX_FILTER = IndexFilter.ALL;
public static Test suite() { public static Test suite() {
return suite(PDOMSearchTest.class); return suite(PDOMSearchTest.class);

View file

@ -115,7 +115,7 @@ public class PDOMTestBase extends BaseTestCase {
for (int i = 0; i < segments.length; i++) { for (int i = 0; i < segments.length; i++) {
pattern[i] = Pattern.compile(segments[i]); pattern[i] = Pattern.compile(segments[i]);
} }
return pdom.findBindings(pattern, true, new IndexFilter(), PROGRESS); return pdom.findBindings(pattern, true, IndexFilter.ALL, PROGRESS);
} }
/** /**

View file

@ -56,7 +56,7 @@ public class TypesTests extends PDOMTestBase {
public void testC() throws Exception { public void testC() throws Exception {
// Get the binding for A::f // 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); assertEquals(1, CAs.length);
ICompositeType CA = (ICompositeType)CAs[0]; ICompositeType CA = (ICompositeType)CAs[0];
IField [] CAfields = CA.getFields(); IField [] CAfields = CA.getFields();
@ -73,7 +73,7 @@ public class TypesTests extends PDOMTestBase {
public void testCPP() throws Exception { public void testCPP() throws Exception {
// Get the binding for A::f // 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); assertEquals(1, As.length);
ICPPClassType A = (ICPPClassType)As[0]; ICPPClassType A = (ICPPClassType)As[0];
ICPPMethod[] Amethods = A.getDeclaredMethods(); ICPPMethod[] Amethods = A.getDeclaredMethods();
@ -89,7 +89,7 @@ public class TypesTests extends PDOMTestBase {
} }
public void test145351() throws Exception { 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); assertEquals(1, bindings.length);
ITypedef spinlock_t = (ITypedef)bindings[0]; ITypedef spinlock_t = (ITypedef)bindings[0];
IName [] refs = pdom.findNames(spinlock_t, IIndex.FIND_REFERENCES); IName [] refs = pdom.findNames(spinlock_t, IIndex.FIND_REFERENCES);

View file

@ -204,7 +204,7 @@ public interface IIndex {
* @param pattern the pattern the name of the binding has to match. * @param pattern the pattern the name of the binding has to match.
* @param isFullyQualified if <code>true</code>, binding must be in global scope * @param isFullyQualified if <code>true</code>, binding must be in global scope
* @param filter a filter that allows for skipping parts of the index * @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 <code>null</code>.
* @return an array of bindings matching the pattern * @return an array of bindings matching the pattern
* @throws CoreException * @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 patterns an array of patterns the names of the qualified name of the bindings have to match.
* @param isFullyQualified if <code>true</code>, the array of pattern specifies the fully qualified name * @param isFullyQualified if <code>true</code>, the array of pattern specifies the fully qualified name
* @param filter a filter that allows for skipping parts of the index * @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 <code>null</code>.
* @return an array of bindings matching the pattern * @return an array of bindings matching the pattern
* @throws CoreException * @throws CoreException
*/ */
@ -228,7 +228,7 @@ public interface IIndex {
* This method makes use of the BTree and is faster than the methods using patterns. * 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 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 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 <code>null</code>.
* @return an array of bindings matching the pattern * @return an array of bindings matching the pattern
* @throws CoreException * @throws CoreException
*/ */
@ -245,7 +245,7 @@ public interface IIndex {
* </pre> * </pre>
* @param names an array of names, which has to be matched by the qualified name of the bindings. * @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 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 <code>null</code>.
* @return an array of bindings matching the pattern * @return an array of bindings matching the pattern
* @throws CoreException * @throws CoreException
*/ */
@ -256,10 +256,11 @@ public interface IIndex {
* @param prefix the prefix with which all returned bindings must start * @param prefix the prefix with which all returned bindings must start
* @param filescope if true, only bindings at file scope are returned * @param filescope if true, only bindings at file scope are returned
* @param filter a filter that allows for skipping parts of the index * @param filter a filter that allows for skipping parts of the index
* @param monitor a monitor for progress reporting and cancellation, may be <code>null</code>
* @return an array of bindings with the prefix * @return an array of bindings with the prefix
* @throws CoreException * @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 * Searches for all names that resolve to the given binding. You can limit the result to references, declarations

View file

@ -15,6 +15,8 @@ package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IBinding; 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. * Can be subclassed and used for queries in the index.
@ -27,8 +29,9 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
* </p> * </p>
*/ */
public class IndexFilter { abstract public class IndexFilter {
public static final IndexFilter ALL = new 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 * 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 * @param binding the binding being checked for validity
* @return whether or not the binding is valid * @return whether or not the binding is valid
* @throws CoreException
*/ */
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) throws CoreException {
return true; return true;
} }
} }

View file

@ -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.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
/** /**
* Created on Nov 5, 2004 * Created on Nov 5, 2004
@ -1341,14 +1340,12 @@ public class CVisitor {
IIndex index = tu.getIndex(); IIndex index = tu.getIndex();
if (index != null) { if (index != null) {
try { try {
IndexFilter filter = IndexFilter IndexFilter filter = IndexFilter.getFilter(ILinkage.C_LINKAGE_ID);
.getFilter(ILinkage.C_LINKAGE_ID); IBinding[] bindings= prefix
IBinding[] bindings = prefix ? index.findBindingsForPrefix( ? index.findBindingsForPrefix(name.toCharArray(), true, filter, null)
name.toCharArray(), true, filter) : index.findBindings( : index.findBindings(name.toCharArray(), filter, null);
name.toCharArray(), filter,
new NullProgressMonitor());
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings); result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }

View file

@ -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.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
/** /**
* @author aniefer * @author aniefer
@ -1048,8 +1047,8 @@ public class CPPSemantics {
try { try {
IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID); IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID);
IBinding[] bindings = data.prefixLookup ? IBinding[] bindings = data.prefixLookup ?
index.findBindingsForPrefix(data.astName.toCharArray(), true, filter) : index.findBindingsForPrefix(data.astName.toCharArray(), true, filter, null) :
index.findBindings(data.astName.toCharArray(), filter, new NullProgressMonitor()); index.findBindings(data.astName.toCharArray(), filter, null);
mergeResults(data, bindings, true); mergeResults(data, bindings, true);
useASTResults = false; useASTResults = false;
} catch (CoreException e) { } catch (CoreException e) {

View file

@ -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.cdt.internal.core.index.composite.cpp.CPPCompositesFactory;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor;
public class CIndex implements IIndex { public class CIndex implements IIndex {
@ -98,7 +99,7 @@ public class CIndex implements IIndex {
IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][]; IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][];
for (int i = 0; i < fPrimaryFragmentCount; i++) { for (int i = 0; i < fPrimaryFragmentCount; i++) {
try { 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]; fragmentBindings[i] = new IIndexFragmentBinding[part.length];
System.arraycopy(part, 0, fragmentBindings[i], 0, part.length); System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
} catch (CoreException e) { } catch (CoreException e) {
@ -306,6 +307,9 @@ public class CIndex implements IIndex {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
} }
} else { } else {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
List result = new ArrayList(); List result = new ArrayList();
ILinkage[] linkages = Linkage.getAllLinkages(); ILinkage[] linkages = Linkage.getAllLinkages();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length); 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) { private IndexFilter retargetFilter(final ILinkage linkage, final IndexFilter filter) {
return new IndexFilter() { return new IndexFilter() {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) throws CoreException {
return filter.acceptBinding(binding); return filter.acceptBinding(binding);
} }
public boolean acceptImplicitMethods() { 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) { if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].findBindingsForPrefix(prefix, filescope, filter); return fFragments[0].findBindingsForPrefix(prefix, filescope, filter, monitor);
} else { } else {
List result = new ArrayList(); List result = new ArrayList();
ILinkage[] linkages = Linkage.getAllLinkages(); ILinkage[] linkages = Linkage.getAllLinkages();
@ -448,7 +452,7 @@ public class CIndex implements IIndex {
IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][]; IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][];
for (int i = 0; i < fPrimaryFragmentCount; i++) { for (int i = 0; i < fPrimaryFragmentCount; i++) {
try { 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]; fragmentBindings[i] = new IIndexFragmentBinding[part.length];
System.arraycopy(part, 0, fragmentBindings[i], 0, part.length); System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
} catch (CoreException e) { } catch (CoreException e) {

View file

@ -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.
}
}

View file

@ -99,7 +99,7 @@ final public class EmptyCIndex implements IIndex {
return null; 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; return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
} }

View file

@ -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 patterns an array of patterns the names of the qualified name of the bindings have to match.
* @param isFullyQualified if <code>true</code>, the array of pattern specifies the fully qualified name * @param isFullyQualified if <code>true</code>, the array of pattern specifies the fully qualified name
* @param filter a filter that allows for skipping parts of the index * @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 <code>null</code>
* @return an array of bindings matching the pattern * @return an array of bindings matching the pattern
* @throws CoreException * @throws CoreException
*/ */
@ -121,7 +121,7 @@ public interface IIndexFragment {
* the given array of names. * the given array of names.
* @param names an array of names the qualified name of the bindings have to match. * @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 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 <code>null</code>
* @return an array of bindings matching the pattern * @return an array of bindings matching the pattern
* @throws CoreException * @throws CoreException
*/ */
@ -155,8 +155,9 @@ public interface IIndexFragment {
/** /**
* Returns all bindings with the given prefix, accepted by the given filter * Returns all bindings with the given prefix, accepted by the given filter
* @param monitor to report progress, may be <code>null</code>
*/ */
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 * Returns the linkages that are contained in this fragment

View file

@ -34,4 +34,10 @@ public interface IIndexFragmentBinding extends Comparable, IIndexBinding {
* in its associated fragment. * in its associated fragment.
*/ */
boolean hasDefinition() throws CoreException; boolean hasDefinition() throws CoreException;
/**
* Returns whether this binding has a declaration or definition associated with
* it in its associated fragment.
*/
boolean hasDeclaration() throws CoreException;
} }

View file

@ -10,6 +10,7 @@
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* IBM Corporation * IBM Corporation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom; 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.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; 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.PlatformObject;
import org.eclipse.core.runtime.Status; 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 { 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); BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter, monitor);
for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) { for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = (PDOMLinkage) iter.next(); PDOMLinkage linkage = (PDOMLinkage) iter.next();
@ -670,7 +676,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
return fPath; 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(); ArrayList result= new ArrayList();
for (Iterator iter= fLinkageIDCache.values().iterator(); iter.hasNext();) { for (Iterator iter= fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage= (PDOMLinkage) iter.next(); PDOMLinkage linkage= (PDOMLinkage) iter.next();
@ -678,14 +684,25 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
IBinding[] bindings; IBinding[] bindings;
if(filescope) { if(filescope) {
BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false); 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(); bindings= visitor.getBindings();
} else { } else {
BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false); BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false);
linkage.accept(visitor); visitor.setMonitor(monitor);
linkage.accept(new ApplyVisitor(linkage, visitor)); try {
linkage.accept(visitor);
linkage.accept(new ApplyVisitor(linkage, visitor));
}
catch (OperationCanceledException e) {
}
bindings= visitor.getBindings(); bindings= visitor.getBindings();
} }
for (int j = 0; j < bindings.length; j++) { for (int j = 0; j < bindings.length; j++) {
result.add(bindings[j]); result.add(bindings[j]);
} }

View file

@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IndexFilter; 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. * 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; this.filter= filter;
} }
public boolean addNode(PDOMNamedNode tBinding) { public boolean addNode(PDOMNamedNode tBinding) throws CoreException {
if (tBinding instanceof IBinding) { if (tBinding instanceof IBinding) {
if (filter == null || filter.acceptBinding((IBinding) tBinding)) { if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
return super.addNode(tBinding); return super.addNode(tBinding);

View file

@ -17,6 +17,8 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.core.runtime.CoreException; 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. * 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 char[] name;
private final boolean prefixLookup; private final boolean prefixLookup;
private final boolean caseSensitive; private final boolean caseSensitive;
private IProgressMonitor monitor= null;
private int monitorCheckCounter= 0;
private List nodes = new ArrayList(); private List nodes = new ArrayList();
@ -48,6 +52,14 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
this.caseSensitive= caseSensitive; 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 { final public int compare(int record) throws CoreException {
PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record)); PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
return compare(node); return compare(node);
@ -71,6 +83,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
} }
final public boolean visit(int record) throws CoreException { final public boolean visit(int record) throws CoreException {
if (monitor != null)
checkCancelled();
if (record == 0) if (record == 0)
return true; return true;
@ -83,8 +98,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
/** /**
* Return true to continue the visit. * Return true to continue the visit.
* @throws CoreException
*/ */
protected boolean addNode(PDOMNamedNode node) { protected boolean addNode(PDOMNamedNode node) throws CoreException {
nodes.add(node); nodes.add(node);
return true; // look for more return true; // look for more
} }
@ -98,6 +114,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
} }
final public boolean visit(IPDOMNode node) throws CoreException { final public boolean visit(IPDOMNode node) throws CoreException {
if (monitor != null)
checkCancelled();
if (node instanceof PDOMNamedNode) { if (node instanceof PDOMNamedNode) {
PDOMNamedNode pb= (PDOMNamedNode) node; PDOMNamedNode pb= (PDOMNamedNode) node;
if (compare(pb) == 0) { if (compare(pb) == 0) {
@ -107,6 +126,12 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
return false; // don't visit children 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 { final public void leave(IPDOMNode node) throws CoreException {
} }
} }

View file

@ -76,7 +76,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return record; return record;
} }
public boolean hasDeclarations() throws CoreException { public boolean hasDeclaration() throws CoreException {
Database db = pdom.getDB(); Database db = pdom.getDB();
return db.getInt(record + FIRST_DECL_OFFSET) != 0 return db.getInt(record + FIRST_DECL_OFFSET) != 0
|| db.getInt(record + FIRST_DEF_OFFSET) != 0; || db.getInt(record + FIRST_DEF_OFFSET) != 0;

View file

@ -149,6 +149,11 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
return true; return true;
} }
public boolean hasDeclaration() throws CoreException {
// parameter bindings do not span index fragments
return true;
}
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }

View file

@ -204,6 +204,11 @@ class PDOMCPPParameter extends PDOMNamedNode implements ICPPParameter, IIndexFra
return true; return true;
} }
public boolean hasDeclaration() throws CoreException {
// parameter bindings do not span index fragments
return true;
}
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }

View file

@ -240,8 +240,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects()); IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects());
try { try {
index.acquireReadLock(); index.acquireReadLock();
IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL); IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL_DECLARED, monitor);
// IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL, monitor);
for(int i=0; i<bindings.length; i++) { for(int i=0; i<bindings.length; i++) {
if ((i % 100) == 0 && monitor.isCanceled()) { if ((i % 100) == 0 && monitor.isCanceled()) {
return null; return null;

View file

@ -124,7 +124,7 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException { public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try { try {
IndexFilter filter= new IndexFilter(); IndexFilter filter= IndexFilter.ALL;
IIndexBinding[] bindings = index.findBindings(pattern, false, filter, monitor); IIndexBinding[] bindings = index.findBindings(pattern, false, filter, monitor);
for (int i = 0; i < bindings.length; ++i) { for (int i = 0; i < bindings.length; ++i) {
IIndexBinding pdomBinding = bindings[i]; IIndexBinding pdomBinding = bindings[i];