diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IString.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IString.java index cdf7d20ea12..190be28a5da 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IString.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/IString.java @@ -59,7 +59,19 @@ public interface IString { * @throws CoreException */ public int compare(char[] chars) throws CoreException; + + /** + * Compare this IString record and the specified character array + * @param chars + * @return
* N.B. This method can be expensive: compare and equals can be used for
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/LongString.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/LongString.java
index 83639841960..1f275bd6896 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/LongString.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/LongString.java
@@ -153,6 +153,10 @@ public class LongString implements IString {
throw new PDOMNotImplementedError();
}
+ public int comparePrefix(char[] name) {
+ throw new PDOMNotImplementedError();
+ }
+
private interface IReader {
public void appendChar(char c);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/ShortString.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/ShortString.java
index 153eda1ca71..7cc737fc5ac 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/ShortString.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/ShortString.java
@@ -223,6 +223,33 @@ public class ShortString implements IString {
return 0;
}
+ public int comparePrefix(char[] other) throws CoreException {
+ Chunk chunk = db.getChunk(record);
+
+ int i1 = record + CHARS;
+ int i2 = 0;
+ int n1 = i1 + chunk.getInt(record + LENGTH) * 2;
+ int n2 = other.length;
+
+ while (i1 < n1 && i2 < n2) {
+ char c1 = chunk.getChar(i1);
+ char c2 = other[i2];
+
+ if (c1 < c2)
+ return -1;
+ if (c1 > c2)
+ return 1;
+
+ i1 += 2;
+ ++i2;
+ }
+
+ if (i1 == n1 && i2 != n2)
+ return -1;
+ else
+ return 0;
+ }
+
public int compare(String other) throws CoreException {
Chunk chunk = db.getChunk(record);
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/FindBindingsInBTree.java
index 4f6b47934fe..9f0c5be9980 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/FindBindingsInBTree.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 QNX Software Systems and others.
+ * Copyright (c) 2006 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,74 +14,42 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
-import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException;
public final class FindBindingsInBTree implements IBTreeVisitor {
- protected final PDOMLinkage linkage;
- protected final char[] name;
- protected final boolean prefixLookup;
+ private final PDOMLinkage linkage;
+ private final char[] name;
+ private final boolean prefixLookup;
+ private IndexFilter filter;
+ private List bindings = new ArrayList();
+
+ /**
+ * Collects all bindings with given name.
+ */
+ public FindBindingsInBTree(PDOMLinkage linkage, char[] name) {
+ this(linkage, name, null, false);
+ }
+
+ /**
+ * 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) {
+ this.name = name;
+ this.linkage= linkage;
+ this.filter= filter;
+ this.prefixLookup = prefixLookup;
+ }
public int compare(int record) throws CoreException {
PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
- IString n = node.getDBName();
- if (prefixLookup && n.getString().startsWith(new String(name))) {
- return 0;
+ if (prefixLookup) {
+ return node.getDBName().comparePrefix(name);
}
- return n.compare(name);
- }
-
- private List bindings = new ArrayList();
- private final int[] desiredType;
-
- /**
- * Matches all types.
- *
- * @param pdom
- * @param name
- */
- public FindBindingsInBTree(PDOMLinkage linkage, char[] name) {
- this(linkage, name, null);
- }
-
- /**
- * Match a specific type.
- *
- * @param pdom
- * @param name
- * @param desiredType
- */
- public FindBindingsInBTree(PDOMLinkage linkage, char[] name, int desiredType) {
- this(linkage, name, new int[] { desiredType });
- }
-
- /**
- * Match a collection of types.
- *
- * @param pdom
- * @param name
- * @param desiredType
- */
- public FindBindingsInBTree(PDOMLinkage linkage, char[] name, int[] desiredType) {
- this(linkage, name, desiredType, false);
- }
-
- /**
- * Match a collection of types.
- *
- * @param pdom
- * @param name
- * @param desiredType
- * @param prefixLookup
- */
- public FindBindingsInBTree(PDOMLinkage linkage, char[] name, int[] desiredType, boolean prefixLookup) {
- this.name = name;
- this.desiredType = desiredType;
- this.linkage= linkage;
- this.prefixLookup = prefixLookup;
+ return node.getDBName().compare(name);
}
public boolean visit(int record) throws CoreException {
@@ -89,29 +57,13 @@ public final class FindBindingsInBTree implements IBTreeVisitor {
return true;
PDOMBinding tBinding = linkage.getPDOM().getBinding(record);
- if ((!prefixLookup && !tBinding.hasName(name))
- || (prefixLookup && !CharArrayUtils.equals(
- tBinding.getNameCharArray(),
- 0, name.length, name, false)))
- return false;
-
- if (desiredType == null) {
+ if (filter == null || filter.acceptBinding(tBinding)) {
bindings.add(tBinding);
- return true; // look for more
- } else {
- int nodeType = tBinding.getNodeType();
- for (int i = 0; i < desiredType.length; ++i)
- if (nodeType == desiredType[i]) {
- bindings.add(tBinding);
- return true; // look for more
- }
- }
-
- // wrong type, try again
- return true;
+ }
+ return true; // look for more
}
- public IBinding[] getBinding() {
+ public IBinding[] getBindings() {
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
}
}
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 448c4561e4e..093ccf2e734 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
@@ -14,9 +14,6 @@
package org.eclipse.cdt.internal.core.pdom.dom;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
@@ -32,7 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLinkage;
@@ -230,48 +226,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
FindBindingsInBTree visitor= new FindBindingsInBTree(this, name);
getIndex().accept(visitor);
- return visitor.getBinding();
- }
-
- private static class PrefixedBindingFinder implements IBTreeVisitor {
- private PDOMLinkage linkage;
- private String prefix;
- private IndexFilter filter;
- private List bindings = new ArrayList();
-
- PrefixedBindingFinder(PDOMLinkage linkage, String prefix, IndexFilter filter) {
- this.linkage = linkage;
- this.prefix = prefix;
- this.filter = filter;
- }
-
- public int compare(int record) throws CoreException {
- PDOMNamedNode node = (PDOMNamedNode) linkage.getNode(record);
- IString name = node.getDBName();
- if (name.getString().startsWith(prefix)) {
- return 0;
- }
- return name.compare(prefix);
- }
-
- public boolean visit(int record) throws CoreException {
- PDOMBinding binding = linkage.getPDOM().getBinding(record);
- if (filter.acceptImplicitMethods() || !(binding instanceof ICPPMethod) ||
- !((ICPPMethod)binding).isImplicit()) {
- if (filter.acceptBinding(binding)) {
- bindings.add(binding);
- }
- }
- return true;
- }
-
- public IBinding[] getBindings() {
- return (IBinding[]) bindings.toArray(new IBinding[bindings.size()]);
- }
+ return visitor.getBindings();
}
public IBinding[] findBindingsForPrefix(String prefix, IndexFilter filter) throws CoreException {
- PrefixedBindingFinder visitor = new PrefixedBindingFinder(this, prefix, filter);
+ FindBindingsInBTree visitor = new FindBindingsInBTree(this, prefix.toCharArray(), 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 5f29b8651c3..5948da31eeb 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
@@ -109,7 +109,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
try {
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), null, prefixLookup);
getIndex().accept(visitor);
- return visitor.getBinding();
+ return visitor.getBindings();
} catch (CoreException e) {
CCorePlugin.log(e);
}
@@ -121,7 +121,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
FindBindingsInBTree visitor= new FindBindingsInBTree(getLinkageImpl(), name.toCharArray());
getIndex().accept(visitor);
- IBinding[] bindings= visitor.getBinding();
+ IBinding[] bindings= visitor.getBindings();
return CPPSemantics.resolveAmbiguities(name, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);