mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 05:45:58 +02:00
Fix for 172453, inconsistencies in index API + testcases.
This commit is contained in:
parent
97429d512d
commit
50c791143e
27 changed files with 276 additions and 207 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -21,6 +21,7 @@ import java.util.regex.Pattern;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.IName;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.BaseTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
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.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -408,7 +408,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
|
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
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);
|
assertEquals(2, bindings.length);
|
||||||
|
|
||||||
IBinding struct, typedef;
|
IBinding struct, typedef;
|
||||||
|
@ -443,7 +443,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
|
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
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);
|
assertEquals(2, bindings.length);
|
||||||
|
|
||||||
IBinding struct, typedef;
|
IBinding struct, typedef;
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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);
|
IIndexBinding[] result= fIndex.findBindings(Pattern.compile("testInclude_cpp"), true, IndexFilter.ALL, NPM);
|
||||||
assertEquals(1, result.length);
|
assertEquals(1, result.length);
|
||||||
|
|
||||||
|
result= fIndex.findBindings("testInclude_cpp".toCharArray(), IndexFilter.ALL, NPM);
|
||||||
|
assertEquals(1, result.length);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -101,6 +101,12 @@ public class IndexLocationTest extends BaseTestCase {
|
||||||
assertEquals(1, bs1.length);
|
assertEquals(1, bs1.length);
|
||||||
assertEquals(1, bs2.length);
|
assertEquals(1, bs2.length);
|
||||||
assertEquals(1, bs3.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[] nms1 = index.findNames(bs1[0], IIndex.FIND_ALL_OCCURENCES);
|
||||||
IIndexName[] nms2 = index.findNames(bs2[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);
|
IIndexName[] nms3 = index.findNames(bs3[0], IIndex.FIND_ALL_OCCURENCES);
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -104,8 +104,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFindClassInNamespace() throws CoreException {
|
public void testFindClassInNamespace() throws CoreException {
|
||||||
Pattern pcl= Pattern.compile("C160913");
|
String scl = "C160913";
|
||||||
Pattern pns= Pattern.compile("ns160913");
|
Pattern pcl= Pattern.compile(scl);
|
||||||
|
String sns = "ns160913";
|
||||||
|
Pattern pns= Pattern.compile(sns);
|
||||||
|
|
||||||
IIndexBinding[] bindings;
|
IIndexBinding[] bindings;
|
||||||
|
|
||||||
|
@ -113,6 +115,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsClass(bindings[0]);
|
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);
|
bindings= fIndex.findBindings(pcl, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(3, bindings.length);
|
assertEquals(3, bindings.length);
|
||||||
checkIsClass(bindings[0]);
|
checkIsClass(bindings[0]);
|
||||||
|
@ -123,6 +129,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsClass(bindings[0]);
|
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);
|
bindings= fIndex.findBindings(new Pattern[]{pns, pcl}, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
checkIsClass(bindings[0]);
|
checkIsClass(bindings[0]);
|
||||||
|
@ -132,6 +142,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsClass(bindings[0]);
|
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);
|
bindings= fIndex.findBindings(new Pattern[]{pns, pns, pcl}, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsClass(bindings[0]);
|
checkIsClass(bindings[0]);
|
||||||
|
@ -140,6 +154,8 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
public void testFindNamespaceInNamespace() throws CoreException {
|
public void testFindNamespaceInNamespace() throws CoreException {
|
||||||
Pattern pcl= Pattern.compile("C160913");
|
Pattern pcl= Pattern.compile("C160913");
|
||||||
Pattern pns= Pattern.compile("ns160913");
|
Pattern pns= Pattern.compile("ns160913");
|
||||||
|
char[] scl= pcl.pattern().toCharArray();
|
||||||
|
char[] sns= pns.pattern().toCharArray();
|
||||||
|
|
||||||
IIndexBinding[] bindings;
|
IIndexBinding[] bindings;
|
||||||
|
|
||||||
|
@ -147,6 +163,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsNamespace(bindings[0]);
|
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);
|
bindings= fIndex.findBindings(pns, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
checkIsNamespace(bindings[0]);
|
checkIsNamespace(bindings[0]);
|
||||||
|
@ -156,6 +176,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsNamespace(bindings[0]);
|
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);
|
bindings= fIndex.findBindings(new Pattern[]{pns, pns}, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsNamespace(bindings[0]);
|
checkIsNamespace(bindings[0]);
|
||||||
|
@ -169,12 +193,17 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
// the binding in the unnamed namespace is not visible in global scope.
|
// the binding in the unnamed namespace is not visible in global scope.
|
||||||
bindings= fIndex.findBindings(pcl, true, INDEX_FILTER, NPM);
|
bindings= fIndex.findBindings(pcl, true, INDEX_FILTER, NPM);
|
||||||
assertEquals(0, bindings.length);
|
assertEquals(0, bindings.length);
|
||||||
}
|
|
||||||
|
bindings= fIndex.findBindings(pcl.pattern().toCharArray(), INDEX_FILTER, NPM);
|
||||||
|
assertEquals(0, bindings.length);
|
||||||
|
}
|
||||||
|
|
||||||
public void testFindEnumerator() throws CoreException {
|
public void testFindEnumerator() throws CoreException {
|
||||||
Pattern pEnumeration= Pattern.compile("E20061017");
|
Pattern pEnumeration= Pattern.compile("E20061017");
|
||||||
Pattern pEnumerator= Pattern.compile("e20061017");
|
Pattern pEnumerator= Pattern.compile("e20061017");
|
||||||
|
char[] sEnumeration= pEnumeration.pattern().toCharArray();
|
||||||
|
char[] sEnumerator= pEnumerator.pattern().toCharArray();
|
||||||
|
|
||||||
IIndexBinding[] bindings;
|
IIndexBinding[] bindings;
|
||||||
|
|
||||||
// enumerators are found in global scope
|
// 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);
|
bindings= fIndex.findBindings(new Pattern[]{pEnumeration, pEnumerator}, true, INDEX_FILTER, NPM);
|
||||||
assertEquals(0, bindings.length);
|
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);
|
bindings= fIndex.findBindings(new Pattern[]{pEnumeration, pEnumerator}, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(0, bindings.length);
|
assertEquals(0, bindings.length);
|
||||||
|
|
||||||
|
@ -196,6 +228,10 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsEnumeration(bindings[0]);
|
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);
|
bindings= fIndex.findBindings(pEnumeration, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(1, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
checkIsEnumeration(bindings[0]);
|
checkIsEnumeration(bindings[0]);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 IBM Corporation.
|
* Copyright (c) 2006, 2007 IBM Corporation.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
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.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
@ -150,7 +151,7 @@ public class CPPFunctionTests extends PDOMTestBase {
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
ICPPFunction function = (ICPPFunction) bindings[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);
|
assertEquals(1, pdom.getDefinitions(function).length);
|
||||||
IParameter[] parameters = function.getParameters();
|
IParameter[] parameters = function.getParameters();
|
||||||
switch (parameters.length) {
|
switch (parameters.length) {
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -52,7 +52,7 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testOverloadedInCommonHeader_ClassScope() throws CoreException {
|
public void testOverloadedInCommonHeader_ClassScope() throws CoreException {
|
||||||
Pattern[] ManyOverloadedQuxPath = makePatternArray(new String[] {"ManyOverloaded","qux"});
|
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);
|
assertEquals(5,ManyOverloadedQux.length);
|
||||||
|
|
||||||
// ManyOverloaded.qux()
|
// ManyOverloaded.qux()
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
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.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
@ -45,26 +46,26 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDistinctBindingsPresent() throws Exception {
|
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);
|
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);
|
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);
|
assertEquals(4, FooBs.length);
|
||||||
|
|
||||||
Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"});
|
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);
|
assertEquals(4, XBarBs.length);
|
||||||
|
|
||||||
Pattern[] XFooPath = makePatternArray(new String[] {"X","Foo"});
|
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);
|
assertEquals(1, XFooPathBs.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReferencesToGlobalBindings() throws Exception {
|
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);
|
IBinding[] globalBs = getGlobalBindings(BarBs);
|
||||||
assertEquals(4, globalBs.length);
|
assertEquals(4, globalBs.length);
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testReferencesToNamespacedBindings() throws Exception {
|
public void testReferencesToNamespacedBindings() throws Exception {
|
||||||
Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"});
|
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()
|
// X::bar()
|
||||||
assertFunctionRefCount(new Class[] {}, XBarBs, 2);
|
assertFunctionRefCount(new Class[] {}, XBarBs, 2);
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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 java.util.regex.Pattern;
|
||||||
|
|
||||||
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.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
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 pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project);
|
||||||
pdom.acquireReadLock();
|
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)
|
if(Bs.length==1)
|
||||||
successes++;
|
successes++;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ package org.eclipse.cdt.core.index;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
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.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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;
|
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.
|
* Searches for all bindings in global scope with a given name. In case a binding exists in multiple projects, no duplicate bindings are returned.
|
||||||
* 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 linkage the linkage to be searched
|
* @param names an array of names, which has to be matched by the qualified name of the bindings.
|
||||||
* @param name a simple (unqualified) name.
|
* @param filter a filter that allows for skipping parts of the index
|
||||||
* @return an array of bindings
|
* @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
|
||||||
|
* <pre>
|
||||||
|
* findBindings(new Pattern[]{pattern}, isFullyQualified, filter, monitor);
|
||||||
|
* </pre>
|
||||||
|
* @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.
|
* 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
|
* @return an array of bindings with the prefix
|
||||||
* @throws CoreException
|
* @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
|
* Searches for all names that resolve to the given binding. You can limit the result to references, declarations
|
||||||
|
|
|
@ -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.
|
* 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)
|
* @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
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.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
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.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
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.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ public class CASTIdExpression extends CASTNode implements IASTIdExpression, IAST
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
b2 = index.findBindingsForPrefix(
|
b2 = index.findBindingsForPrefix(
|
||||||
n.toString(),
|
n.toCharArray(),
|
||||||
IndexFilter.getFilter(Linkage.C_LINKAGE));
|
IndexFilter.getFilter(ILinkage.C_LINKAGE_ID));
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class CASTTypedefNameSpecifier extends CASTBaseDeclSpecifier implements
|
||||||
|
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter);
|
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||||
for (int i = 0; i < bindings.length; i++) {
|
for (int i = 0; i < bindings.length; i++) {
|
||||||
filtered.add(bindings[i]);
|
filtered.add(bindings[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ public class CPPASTBaseSpecifier extends CPPASTNode implements
|
||||||
|
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter);
|
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||||
for (int i = 0; i < bindings.length; i++) {
|
for (int i = 0; i < bindings.length; i++) {
|
||||||
filtered.add(bindings[i]);
|
filtered.add(bindings[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
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.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
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.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
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.cdt.internal.core.dom.parser.IASTCompletionContext;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ public class CPPASTIdExpression extends CPPASTNode implements IASTIdExpression,
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
b2 = index.findBindingsForPrefix(
|
b2 = index.findBindingsForPrefix(
|
||||||
n.toString(),
|
n.toCharArray(),
|
||||||
IndexFilter.getFilter(Linkage.CPP_LINKAGE));
|
IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID));
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements
|
||||||
|
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter);
|
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||||
for (int i = 0; i < bindings.length; i++) {
|
for (int i = 0; i < bindings.length; i++) {
|
||||||
filtered.add(bindings[i]);
|
filtered.add(bindings[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class CPPASTUsingDeclaration extends CPPASTNode implements
|
||||||
|
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter);
|
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||||
for (int i = 0; i < bindings.length; i++) {
|
for (int i = 0; i < bindings.length; i++) {
|
||||||
filtered.add(bindings[i]);
|
filtered.add(bindings[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class CPPASTUsingDirective extends CPPASTNode implements
|
||||||
|
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = index.findBindingsForPrefix(n.toString(), filter);
|
IBinding[] bindings = index.findBindingsForPrefix(n.toCharArray(), filter);
|
||||||
for (int i = 0; i < bindings.length; i++) {
|
for (int i = 0; i < bindings.length; i++) {
|
||||||
filtered.add(bindings[i]);
|
filtered.add(bindings[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
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.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
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.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
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.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectSet;
|
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.IASTInternalScope;
|
||||||
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.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
*/
|
*/
|
||||||
abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
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 ) {
|
public CPPScopeProblem( IASTNode node, int id, char[] arg ) {
|
||||||
super( node, id, arg );
|
super( node, id, arg );
|
||||||
}
|
}
|
||||||
|
@ -91,8 +98,12 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
// Try looking this up in the PDOM
|
// Try looking this up in the PDOM
|
||||||
if (physicalNode instanceof IASTTranslationUnit) {
|
if (physicalNode instanceof IASTTranslationUnit) {
|
||||||
IBinding[] bindings= index.findInGlobalScope(Linkage.CPP_LINKAGE, name.toCharArray());
|
try {
|
||||||
binding= CPPSemantics.resolveAmbiguities(name, bindings);
|
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) {
|
else if (physicalNode instanceof ICPPASTNamespaceDefinition) {
|
||||||
ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode;
|
ICPPASTNamespaceDefinition nsdef = (ICPPASTNamespaceDefinition)physicalNode;
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
@ -155,7 +154,21 @@ public class CIndex implements IIndex {
|
||||||
monitor.done();
|
monitor.done();
|
||||||
return (IIndexBinding[]) result.toArray(new IIndexBinding[result.size()]);
|
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 {
|
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
|
||||||
ArrayList result= new ArrayList();
|
ArrayList result= new ArrayList();
|
||||||
for (int i = 0; i < fPrimaryFragmentCount; i++) {
|
for (int i = 0; i < fPrimaryFragmentCount; i++) {
|
||||||
|
@ -327,27 +340,6 @@ public class CIndex implements IIndex {
|
||||||
return result;
|
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) {
|
public IBinding[] findInNamespace(IBinding nsbinding, char[] name) {
|
||||||
ArrayList result= new ArrayList();
|
ArrayList result= new ArrayList();
|
||||||
for (int i = 0; i < fFragments.length; i++) {
|
for (int i = 0; i < fFragments.length; i++) {
|
||||||
|
@ -369,7 +361,7 @@ public class CIndex implements IIndex {
|
||||||
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
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();
|
ArrayList result= new ArrayList();
|
||||||
for (int i = 0; i < fFragments.length; i++) {
|
for (int i = 0; i < fFragments.length; i++) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.index;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
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.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
@ -95,19 +94,21 @@ final public class EmptyCIndex implements IIndex {
|
||||||
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
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) {
|
public IBinding[] findInNamespace(IBinding nsbinding, char[] name) {
|
||||||
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
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;
|
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.index;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
@ -107,7 +106,18 @@ public interface IIndexFragment {
|
||||||
* @return an array of bindings matching the pattern
|
* @return an array of bindings matching the pattern
|
||||||
* @throws CoreException
|
* @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
|
* 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();
|
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
|
* 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
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.pdom;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
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.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
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.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
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.index.IIndexProxyBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
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.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.IIndexLocationConverter;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
|
@ -204,13 +205,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
return getFirstLinkageRecord() == 0;
|
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
|
* @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 {
|
public IIndexBinding[] findBindings(Pattern pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
return findBindings(new Pattern[] { pattern }, isFullyQualified, filter, monitor);
|
return findBindings(new Pattern[] { pattern }, isFullyQualified, filter, monitor);
|
||||||
}
|
}
|
||||||
|
@ -364,6 +344,29 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
return finder.getBindings();
|
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 {
|
private void readLinkages() throws CoreException {
|
||||||
// populate the linkage cache
|
// populate the linkage cache
|
||||||
int record= getFirstLinkageRecord();
|
int record= getFirstLinkageRecord();
|
||||||
|
@ -597,14 +600,6 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
return fPath;
|
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 {
|
public IBinding[] findInNamespace(IBinding nsbinding, char[] name) throws CoreException {
|
||||||
IIndexProxyBinding ns= adaptBinding(nsbinding);
|
IIndexProxyBinding ns= adaptBinding(nsbinding);
|
||||||
if (ns instanceof ICPPNamespace) {
|
if (ns instanceof ICPPNamespace) {
|
||||||
|
@ -618,7 +613,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
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();
|
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();
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,18 +7,25 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
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;
|
||||||
|
|
||||||
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 PDOMLinkage linkage;
|
||||||
private final char[] name;
|
private final char[] name;
|
||||||
private final boolean prefixLookup;
|
private final boolean prefixLookup;
|
||||||
|
@ -29,7 +36,7 @@ public final class FindBindingsInBTree implements IBTreeVisitor {
|
||||||
/**
|
/**
|
||||||
* Collects all bindings with given name.
|
* Collects all bindings with given name.
|
||||||
*/
|
*/
|
||||||
public FindBindingsInBTree(PDOMLinkage linkage, char[] name) {
|
public BindingCollector(PDOMLinkage linkage, char[] name) {
|
||||||
this(linkage, name, null, false);
|
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
|
* Collects all bindings with given name, passing the filter. If prefixLookup is set to
|
||||||
* <code>true</code> a binding is considered if its name starts with the given prefix.
|
* <code>true</code> 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.name = name;
|
||||||
this.linkage= linkage;
|
this.linkage= linkage;
|
||||||
this.filter= filter;
|
this.filter= filter;
|
||||||
|
@ -46,6 +53,10 @@ public final class FindBindingsInBTree implements IBTreeVisitor {
|
||||||
|
|
||||||
public int compare(int record) throws CoreException {
|
public int compare(int record) throws CoreException {
|
||||||
PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
|
PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
|
||||||
|
return compare(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compare(PDOMNamedNode node) throws CoreException {
|
||||||
if (prefixLookup) {
|
if (prefixLookup) {
|
||||||
return node.getDBName().comparePrefix(name);
|
return node.getDBName().comparePrefix(name);
|
||||||
}
|
}
|
||||||
|
@ -57,13 +68,32 @@ public final class FindBindingsInBTree implements IBTreeVisitor {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
PDOMBinding tBinding = linkage.getPDOM().getBinding(record);
|
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)) {
|
if (filter == null || filter.acceptBinding(tBinding)) {
|
||||||
bindings.add(tBinding);
|
bindings.add(tBinding);
|
||||||
}
|
}
|
||||||
return true; // look for more
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding[] getBindings() {
|
public IBinding[] getBindings() {
|
||||||
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
|
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 {
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -107,21 +107,25 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||||
super.accept(visitor);
|
if (visitor instanceof IBTreeVisitor) {
|
||||||
getIndex().accept(new IBTreeVisitor() {
|
getIndex().accept((IBTreeVisitor) visitor);
|
||||||
public int compare(int record) throws CoreException {
|
}
|
||||||
return 0;
|
else {
|
||||||
}
|
getIndex().accept(new IBTreeVisitor() {
|
||||||
public boolean visit(int record) throws CoreException {
|
public int compare(int record) throws CoreException {
|
||||||
PDOMBinding binding = pdom.getBinding(record);
|
return 0;
|
||||||
if (binding != null) {
|
|
||||||
if (visitor.visit(binding))
|
|
||||||
binding.accept(visitor);
|
|
||||||
visitor.leave(binding);
|
|
||||||
}
|
}
|
||||||
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 {
|
public ILinkage getLinkage() throws CoreException {
|
||||||
|
@ -221,16 +225,9 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int getBindingType(IBinding binding);
|
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 {
|
public IBinding[] findBindingsForPrefix(char[] prefix, IndexFilter filter) throws CoreException {
|
||||||
FindBindingsInBTree visitor = new FindBindingsInBTree(this, prefix.toCharArray(), filter, true);
|
BindingCollector visitor = new BindingCollector(this, prefix, filter, true);
|
||||||
getIndex().accept(visitor);
|
getIndex().accept(visitor);
|
||||||
|
|
||||||
return visitor.getBindings();
|
return visitor.getBindings();
|
||||||
|
|
|
@ -17,11 +17,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
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.IPDOMVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
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.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
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.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.PDOMBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -71,21 +66,25 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||||
super.accept(visitor);
|
if (visitor instanceof IBTreeVisitor) {
|
||||||
getIndex().accept(new IBTreeVisitor() {
|
getIndex().accept((IBTreeVisitor) visitor);
|
||||||
public int compare(int record) throws CoreException {
|
}
|
||||||
return 0;
|
else {
|
||||||
}
|
getIndex().accept(new IBTreeVisitor() {
|
||||||
public boolean visit(int record) throws CoreException {
|
public int compare(int record) throws CoreException {
|
||||||
PDOMBinding binding = pdom.getBinding(record);
|
return 0;
|
||||||
if (binding != null) {
|
|
||||||
if (visitor.visit(binding))
|
|
||||||
binding.accept(visitor);
|
|
||||||
visitor.leave(binding);
|
|
||||||
}
|
}
|
||||||
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 {
|
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) {
|
public IBinding[] find(String name, boolean prefixLookup) {
|
||||||
try {
|
try {
|
||||||
FindBindingsInBTree visitor = new FindBindingsInBTree(getLinkageImpl(), name.toCharArray(), null, prefixLookup);
|
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup);
|
||||||
getIndex().accept(visitor);
|
getIndex().accept(visitor);
|
||||||
return visitor.getBindings();
|
return visitor.getBindings();
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -118,7 +117,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding implements ICPPNamespace, ICPPName
|
||||||
|
|
||||||
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
|
||||||
try {
|
try {
|
||||||
FindBindingsInBTree visitor= new FindBindingsInBTree(getLinkageImpl(), name.toCharArray());
|
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray());
|
||||||
getIndex().accept(visitor);
|
getIndex().accept(visitor);
|
||||||
|
|
||||||
IBinding[] bindings= visitor.getBindings();
|
IBinding[] bindings= visitor.getBindings();
|
||||||
|
|
|
@ -366,10 +366,6 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
|
||||||
// int a1;
|
// int a1;
|
||||||
// int b1;
|
// int b1;
|
||||||
// };
|
// };
|
||||||
// typedef struct S2 {
|
|
||||||
// int a2;
|
|
||||||
// int b2;
|
|
||||||
// } S2;
|
|
||||||
// typedef struct S3 {
|
// typedef struct S3 {
|
||||||
// int a3;
|
// int a3;
|
||||||
// int b3;
|
// int b3;
|
||||||
|
@ -388,14 +384,6 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
|
||||||
assertEquals(0, item.getItemCount());
|
assertEquals(0, item.getItemCount());
|
||||||
checkMethodTable(new String[] {"a1", "b1"});
|
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);
|
editor.selectAndReveal(content.indexOf("a3"), 1);
|
||||||
openTypeHierarchy(editor);
|
openTypeHierarchy(editor);
|
||||||
tree = getHierarchyViewer().getTree();
|
tree = getHierarchyViewer().getTree();
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -401,13 +400,13 @@ public class NewClassWizardUtil {
|
||||||
try {
|
try {
|
||||||
String fullyQualifiedTypeName = typeName.getFullyQualifiedName();
|
String fullyQualifiedTypeName = typeName.getFullyQualifiedName();
|
||||||
try {
|
try {
|
||||||
IndexFilter filter= new IndexFilter() {
|
IndexFilter filter= IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID);
|
||||||
public boolean acceptLinkage(ILinkage linkage) {
|
String[] nameStrs= fullyQualifiedTypeName.split("::"); //$NON-NLS-1$
|
||||||
return linkage.getID() == ILinkage.CPP_LINKAGE_ID;
|
char[][] names= new char[nameStrs.length][];
|
||||||
}
|
for (int i = 0; i < names.length; i++) {
|
||||||
};
|
names[i]= nameStrs[i].toCharArray();
|
||||||
// mstodo revisit, the pattern must be split
|
}
|
||||||
IBinding[] bindings = index.findBindings(Pattern.compile(typeName.getName()), true, filter, new NullProgressMonitor());
|
IBinding[] bindings = index.findBindings(names, filter, new NullProgressMonitor());
|
||||||
boolean sameTypeNameExists = false;
|
boolean sameTypeNameExists = false;
|
||||||
boolean sameNameDifferentTypeExists = false;
|
boolean sameNameDifferentTypeExists = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue