mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 08:46:02 +02:00
Static variables/functions in Open Element and Search (bug 193057 and 196414).
This commit is contained in:
parent
41e74e8cbf
commit
9b07ea66db
20 changed files with 195 additions and 103 deletions
|
@ -234,18 +234,18 @@ public class IndexSearchTest extends IndexTestBase {
|
||||||
checkIsEnumeration(bindings[0]);
|
checkIsEnumeration(bindings[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _testFindStatic_161216() throws CoreException {
|
public void testFindStatic_161216() throws CoreException {
|
||||||
Pattern pFunc= Pattern.compile("staticFunc20061017");
|
Pattern pFunc= Pattern.compile("staticFunc20061017");
|
||||||
Pattern pVar= Pattern.compile("staticVar20061017");
|
Pattern pVar= Pattern.compile("staticVar20061017");
|
||||||
|
|
||||||
IIndexBinding[] bindings;
|
IIndexBinding[] bindings;
|
||||||
|
|
||||||
bindings= fIndex.findBindings(pFunc, true, INDEX_FILTER, NPM);
|
bindings= fIndex.findBindings(pFunc, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
checkIsFunction(bindings[0]);
|
checkIsFunction(bindings[0]);
|
||||||
checkIsFunction(bindings[1]);
|
checkIsFunction(bindings[1]);
|
||||||
|
|
||||||
bindings= fIndex.findBindings(pVar, true, INDEX_FILTER, NPM);
|
bindings= fIndex.findBindings(pVar, false, INDEX_FILTER, NPM);
|
||||||
assertEquals(2, bindings.length);
|
assertEquals(2, bindings.length);
|
||||||
checkIsVariable(bindings[0]);
|
checkIsVariable(bindings[0]);
|
||||||
checkIsVariable(bindings[1]);
|
checkIsVariable(bindings[1]);
|
||||||
|
|
|
@ -57,9 +57,9 @@ public class CFunctionTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testStaticCFunction() throws Exception {
|
public void testStaticCFunction() throws Exception {
|
||||||
// static elements cannot be found on global scope, see bug 161216
|
// static elements cannot be found on global scope, see bug 161216
|
||||||
IBinding[] bindings = findQualifiedName(pdom, "staticCFunction");
|
IBinding[] bindings = findUnqualifiedName(pdom, "staticCFunction");
|
||||||
assertEquals(0, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
// assertTrue(((IFunction) bindings[0]).isStatic());
|
assertTrue(((IFunction) bindings[0]).isStatic());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInlineCFunction() throws Exception {
|
public void testInlineCFunction() throws Exception {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.pdom.tests;
|
package org.eclipse.cdt.internal.pdom.tests;
|
||||||
|
@ -117,9 +118,9 @@ public class CPPFunctionTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testStaticCPPFunction() throws Exception {
|
public void testStaticCPPFunction() throws Exception {
|
||||||
// static elements cannot be found on global scope, see bug 161216
|
// static elements cannot be found on global scope, see bug 161216
|
||||||
IBinding[] bindings = findQualifiedName(pdom, "staticCPPFunction");
|
IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPFunction");
|
||||||
assertEquals(0, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
// assertTrue(((ICPPFunction) bindings[0]).isStatic());
|
assertTrue(((ICPPFunction) bindings[0]).isStatic());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInlineCPPFunction() throws Exception {
|
public void testInlineCPPFunction() throws Exception {
|
||||||
|
|
|
@ -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
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.pdom.tests;
|
package org.eclipse.cdt.internal.pdom.tests;
|
||||||
|
@ -70,9 +71,9 @@ public class CPPVariableTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testCPPStaticVariable() throws Exception {
|
public void testCPPStaticVariable() throws Exception {
|
||||||
// static elements cannot be found on global scope, see bug 161216
|
// static elements cannot be found on global scope, see bug 161216
|
||||||
IBinding[] bindings = findQualifiedName(pdom, "staticCPPVariable");
|
IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPVariable");
|
||||||
assertEquals(0, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
// ICPPVariable variable = (ICPPVariable) bindings[0];
|
ICPPVariable variable = (ICPPVariable) bindings[0];
|
||||||
// assertTrue(variable.isStatic());
|
assertTrue(variable.isStatic());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.pdom.tests;
|
package org.eclipse.cdt.internal.pdom.tests;
|
||||||
|
@ -70,10 +71,10 @@ public class CVariableTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testCStaticVariable() throws Exception {
|
public void testCStaticVariable() throws Exception {
|
||||||
// static elements cannot be found on global scope, see bug 161216
|
// static elements cannot be found on global scope, see bug 161216
|
||||||
IBinding[] bindings = findQualifiedName(pdom, "staticCVariable");
|
IBinding[] bindings = findUnqualifiedName(pdom, "staticCVariable");
|
||||||
assertEquals(0, bindings.length);
|
assertEquals(1, bindings.length);
|
||||||
// IVariable variable = (IVariable) bindings[0];
|
IVariable variable = (IVariable) bindings[0];
|
||||||
// assertTrue(variable.isStatic());
|
assertTrue(variable.isStatic());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Symbian - Fix a race condition (157992)
|
* Symbian - Fix a race condition (157992)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.pdom.tests;
|
package org.eclipse.cdt.internal.pdom.tests;
|
||||||
|
|
||||||
|
@ -121,6 +121,15 @@ public class PDOMTestBase extends BaseTestCase {
|
||||||
return pdom.findBindings(pattern, true, IndexFilter.ALL, PROGRESS);
|
return pdom.findBindings(pattern, true, IndexFilter.ALL, PROGRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected IBinding[] findUnqualifiedName(PDOM pdom, String name) throws CoreException {
|
||||||
|
String[] segments = name.split("::");
|
||||||
|
Pattern[] pattern = new Pattern[segments.length];
|
||||||
|
for (int i = 0; i < segments.length; i++) {
|
||||||
|
pattern[i] = Pattern.compile(segments[i]);
|
||||||
|
}
|
||||||
|
return pdom.findBindings(pattern, false, IndexFilter.ALL, PROGRESS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method for checking the number of PDOM references for a
|
* Convenience method for checking the number of PDOM references for a
|
||||||
* particular name.
|
* particular name.
|
||||||
|
|
|
@ -66,6 +66,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String[] fqn;
|
private final String[] fqn;
|
||||||
|
private final String fileLocal;
|
||||||
private final int elementType;
|
private final int elementType;
|
||||||
private final IIndex index;
|
private final IIndex index;
|
||||||
private final String[] params;
|
private final String[] params;
|
||||||
|
@ -81,6 +82,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
public static IndexTypeInfo create(IIndex index, IIndexBinding binding) {
|
public static IndexTypeInfo create(IIndex index, IIndexBinding binding) {
|
||||||
String[] fqn;
|
String[] fqn;
|
||||||
int elementType;
|
int elementType;
|
||||||
|
String flsq= null;
|
||||||
try {
|
try {
|
||||||
elementType = IndexModelUtil.getElementType(binding);
|
elementType = IndexModelUtil.getElementType(binding);
|
||||||
if (binding instanceof ICPPBinding) {
|
if (binding instanceof ICPPBinding) {
|
||||||
|
@ -94,18 +96,22 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
else {
|
else {
|
||||||
fqn= new String[] {binding.getName()};
|
fqn= new String[] {binding.getName()};
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
flsq = binding.getFileLocalScopeQualifier();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
if (binding instanceof IFunction) {
|
if (binding instanceof IFunction) {
|
||||||
final IFunction function= (IFunction)binding;
|
final IFunction function= (IFunction)binding;
|
||||||
final String[] paramTypes= IndexModelUtil.extractParameterTypes(function);
|
final String[] paramTypes= IndexModelUtil.extractParameterTypes(function);
|
||||||
final String returnType= IndexModelUtil.extractReturnType(function);
|
final String returnType= IndexModelUtil.extractReturnType(function);
|
||||||
return new IndexTypeInfo(fqn, elementType, paramTypes, returnType, index);
|
return new IndexTypeInfo(fqn, flsq, elementType, index, paramTypes, returnType, null);
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
// index bindings don't throw DOMExceptions.
|
// index bindings don't throw DOMExceptions.
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new IndexTypeInfo(fqn, elementType, index);
|
return new IndexTypeInfo(fqn, flsq, elementType, index, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,9 +125,10 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
return new IndexTypeInfo(new String[] {new String(name)}, ICElement.C_MACRO, index);
|
return new IndexTypeInfo(new String[] {new String(name)}, ICElement.C_MACRO, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndexTypeInfo(String[] fqn, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) {
|
private IndexTypeInfo(String[] fqn, String fileLocal, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) {
|
||||||
Assert.isTrue(index != null);
|
Assert.isTrue(index != null);
|
||||||
this.fqn= fqn;
|
this.fqn= fqn;
|
||||||
|
this.fileLocal= fileLocal;
|
||||||
this.elementType= elementType;
|
this.elementType= elementType;
|
||||||
this.index= index;
|
this.index= index;
|
||||||
this.params= params;
|
this.params= params;
|
||||||
|
@ -133,18 +140,18 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
* @deprecated, use {@link #create(IIndex, IBinding)}.
|
* @deprecated, use {@link #create(IIndex, IBinding)}.
|
||||||
*/
|
*/
|
||||||
public IndexTypeInfo(String[] fqn, int elementType, IIndex index) {
|
public IndexTypeInfo(String[] fqn, int elementType, IIndex index) {
|
||||||
this(fqn, elementType, index, null, null, null);
|
this(fqn, null, elementType, index, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated, use {@link #create(IIndex, IBinding)}.
|
* @deprecated, use {@link #create(IIndex, IBinding)}.
|
||||||
*/
|
*/
|
||||||
public IndexTypeInfo(String[] fqn, int elementType, String[] params, String returnType, IIndex index) {
|
public IndexTypeInfo(String[] fqn, int elementType, String[] params, String returnType, IIndex index) {
|
||||||
this(fqn, elementType, index, params, returnType, null);
|
this(fqn, null, elementType, index, params, returnType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexTypeInfo(IndexTypeInfo rhs, ITypeReference ref) {
|
public IndexTypeInfo(IndexTypeInfo rhs, ITypeReference ref) {
|
||||||
this(rhs.fqn, rhs.elementType, rhs.index, rhs.params, rhs.returnType, ref);
|
this(rhs.fqn, rhs.fileLocal, rhs.elementType, rhs.index, rhs.params, rhs.returnType, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDerivedReference(ITypeReference location) {
|
public void addDerivedReference(ITypeReference location) {
|
||||||
|
@ -337,11 +344,19 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
List references= new ArrayList();
|
List references= new ArrayList();
|
||||||
try {
|
try {
|
||||||
index.acquireReadLock();
|
index.acquireReadLock();
|
||||||
|
int j= 0;
|
||||||
char[][] cfqn = new char[fqn.length][];
|
char[][] cfqn;
|
||||||
for(int i=0; i<fqn.length; i++)
|
if (fileLocal != null) {
|
||||||
cfqn[i] = fqn[i].toCharArray();
|
cfqn = new char[fqn.length+1][];
|
||||||
|
cfqn[j++]= fileLocal.toCharArray();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cfqn = new char[fqn.length][];
|
||||||
|
}
|
||||||
|
for(int i=0; i<fqn.length; i++) {
|
||||||
|
cfqn[j++] = fqn[i].toCharArray();
|
||||||
|
}
|
||||||
|
|
||||||
IIndexBinding[] ibs = index.findBindings(cfqn, new IndexFilter() {
|
IIndexBinding[] ibs = index.findBindings(cfqn, new IndexFilter() {
|
||||||
public boolean acceptBinding(IBinding binding) {
|
public boolean acceptBinding(IBinding binding) {
|
||||||
boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
|
boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
|
||||||
|
@ -366,7 +381,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
if (names.length == 0) {
|
if (names.length == 0) {
|
||||||
names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
||||||
}
|
}
|
||||||
for (int j = 0; j < names.length; j++) {
|
for (j = 0; j < names.length; j++) {
|
||||||
IIndexName indexName = names[j];
|
IIndexName indexName = names[j];
|
||||||
if (checkFile(iflMap, indexName.getFile())) {
|
if (checkFile(iflMap, indexName.getFile())) {
|
||||||
IndexTypeReference ref= createReference(binding, indexName);
|
IndexTypeReference ref= createReference(binding, indexName);
|
||||||
|
|
|
@ -250,6 +250,9 @@ public interface IIndex {
|
||||||
/**
|
/**
|
||||||
* Searches for all bindings in global scope with a given name. In case a binding exists in multiple projects, no duplicate bindings are returned.
|
* Searches for all bindings in global scope with a given name. In case a binding exists in multiple projects, no duplicate bindings are returned.
|
||||||
* This method makes use of the BTree and is faster than the methods using patterns.
|
* This method makes use of the BTree and is faster than the methods using patterns.
|
||||||
|
* <p>
|
||||||
|
* To find bindings for file-local (static) variables or functions you need to provide an additional qualifier. It can be obtained by calling
|
||||||
|
* {@link #getFileLocalScopeQualifier()} or {@link IndexLocationFactory#getFileLocalQualifier(IIndexLocation)}.
|
||||||
* @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, may be <code>null</code>.
|
* @param monitor a monitor to report progress, may be <code>null</code>.
|
||||||
|
@ -342,4 +345,11 @@ public interface IIndex {
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public IIndexBinding adaptBinding(IBinding binding);
|
public IIndexBinding adaptBinding(IBinding binding);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the additional qualifier with which you can search for static (file-local) functions and
|
||||||
|
* variables.
|
||||||
|
* @see #findBindings(char[][], IndexFilter, IProgressMonitor).
|
||||||
|
*/
|
||||||
|
public String getFileLocalScopeQualifier(IIndexFileLocation loc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,4 +43,11 @@ public interface IIndexBinding extends IBinding {
|
||||||
* in another index.
|
* in another index.
|
||||||
*/
|
*/
|
||||||
boolean isFileLocal() throws CoreException;
|
boolean isFileLocal() throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the qualifier that can be used to search for file local bindings using
|
||||||
|
* {@link IIndex#findBindings(char[][], IndexFilter, org.eclipse.core.runtime.IProgressMonitor)}.
|
||||||
|
* In case the binding is not file-local, <code>null</code> is returned.
|
||||||
|
*/
|
||||||
|
String getFileLocalScopeQualifier() throws CoreException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -558,4 +558,32 @@ public class CIndex implements IIndex {
|
||||||
fFragments[i].resetCacheCounters();
|
fFragments[i].resetCacheCounters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileLocalScopeQualifier(IIndexFileLocation loc) {
|
||||||
|
return new String(getFileLocalScopeQualifier(loc.getFullPath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char[] getFileLocalScopeQualifier(String fullPath) {
|
||||||
|
char[] fname= fullPath.toCharArray();
|
||||||
|
int fnamestart= findFileNameStart(fname);
|
||||||
|
StringBuffer buf= new StringBuffer();
|
||||||
|
buf.append('{');
|
||||||
|
buf.append(fname, fnamestart, fname.length-fnamestart);
|
||||||
|
buf.append(':');
|
||||||
|
buf.append(fullPath.hashCode());
|
||||||
|
buf.append('}');
|
||||||
|
fname= buf.toString().toCharArray();
|
||||||
|
return fname;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int findFileNameStart(char[] fname) {
|
||||||
|
for (int i= fname.length-2; i>=0; i--) {
|
||||||
|
switch (fname[i]) {
|
||||||
|
case '/':
|
||||||
|
case '\\':
|
||||||
|
return i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,4 +121,8 @@ final public class EmptyCIndex implements IIndex {
|
||||||
public IIndexMacro[] findMacrosForPrefix(char[] prefix, IndexFilter filter, IProgressMonitor monitor) {
|
public IIndexMacro[] findMacrosForPrefix(char[] prefix, IndexFilter filter, IProgressMonitor monitor) {
|
||||||
return IIndexMacro.EMPTY_INDEX_MACRO_ARRAY;
|
return IIndexMacro.EMPTY_INDEX_MACRO_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileLocalScopeQualifier(IIndexFileLocation loc) {
|
||||||
|
return new String(CIndex.getFileLocalScopeQualifier(loc.getFullPath()));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -6,9 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Ferguson (Symbian) - Initial implementation
|
* Andrew Ferguson (Symbian) - Initial implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Bryan Wilkinson (QNX)
|
* Bryan Wilkinson (QNX)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.index.composite;
|
package org.eclipse.cdt.internal.core.index.composite;
|
||||||
|
|
||||||
|
@ -87,9 +87,13 @@ public abstract class CompositeIndexBinding implements IIndexBinding {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFileLocal() throws CoreException {
|
public boolean isFileLocal() throws CoreException {
|
||||||
return rbinding instanceof IIndexBinding ? ((IIndexBinding)rbinding).isFileLocal() : true;
|
return rbinding != null ? rbinding.isFileLocal() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileLocalScopeQualifier() throws CoreException {
|
||||||
|
return rbinding != null ? rbinding.getFileLocalScopeQualifier() : null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -54,12 +54,14 @@ import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
|
||||||
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.MacroCollector;
|
import org.eclipse.cdt.internal.core.pdom.dom.MacroCollector;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.NamedNodeCollector;
|
||||||
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.PDOMFile;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||||
|
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;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -372,20 +374,20 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
if (monitor.isCanceled())
|
if (monitor.isCanceled())
|
||||||
throw new CoreException(Status.OK_STATUS);
|
throw new CoreException(Status.OK_STATUS);
|
||||||
|
|
||||||
if (node instanceof PDOMBinding) {
|
if (node instanceof PDOMNamedNode) {
|
||||||
PDOMBinding binding = (PDOMBinding)node;
|
PDOMNamedNode nnode = (PDOMNamedNode)node;
|
||||||
String name = binding.getName();
|
String name = new String(nnode.getNameCharArray());
|
||||||
|
|
||||||
// check if we have a complete match.
|
// check if we have a complete match.
|
||||||
final int lastIdx = pattern.length-1;
|
final int lastIdx = pattern.length-1;
|
||||||
if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) {
|
if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) {
|
||||||
if (filter.acceptBinding(binding)) {
|
if (nnode instanceof IBinding && filter.acceptBinding((IBinding) nnode)) {
|
||||||
bindings.add(binding);
|
bindings.add(nnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we have a partial match
|
// check if we have a partial match
|
||||||
if (binding.mayHaveChildren()) {
|
if (nnode.mayHaveChildren()) {
|
||||||
boolean visitNextLevel= false;
|
boolean visitNextLevel= false;
|
||||||
BitSet updatedMatchesUpToLevel= new BitSet();
|
BitSet updatedMatchesUpToLevel= new BitSet();
|
||||||
if (!isFullyQualified) {
|
if (!isFullyQualified) {
|
||||||
|
@ -401,7 +403,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
if (visitNextLevel) {
|
if (visitNextLevel) {
|
||||||
matchStack.add(matchesUpToLevel);
|
matchStack.add(matchesUpToLevel);
|
||||||
matchesUpToLevel= updatedMatchesUpToLevel;
|
matchesUpToLevel= updatedMatchesUpToLevel;
|
||||||
currentPath.add(binding);
|
currentPath.add(nnode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,24 +451,33 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
if (names.length == 0) {
|
||||||
|
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
}
|
||||||
ArrayList result= new ArrayList();
|
ArrayList result= new ArrayList();
|
||||||
|
ArrayList nodes= 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();
|
||||||
if (filter.acceptLinkage(linkage)) {
|
if (filter.acceptLinkage(linkage)) {
|
||||||
ArrayList bindings= new ArrayList();
|
nodes.add(linkage);
|
||||||
bindings.add(linkage);
|
for (int i=0; i < names.length-1; i++) {
|
||||||
for (int i=0; i < names.length; i++) {
|
|
||||||
char[] name= names[i];
|
char[] name= names[i];
|
||||||
IndexFilter levelFilter= i==names.length-1 ? filter : IndexFilter.ALL;
|
NamedNodeCollector collector= new NamedNodeCollector(linkage, name, false, true);
|
||||||
BindingCollector collector= new BindingCollector(linkage, name, levelFilter, false, true);
|
for (Iterator in = nodes.iterator(); in.hasNext();) {
|
||||||
for (Iterator in = bindings.iterator(); in.hasNext();) {
|
|
||||||
PDOMNode node= (PDOMNode) in.next();
|
PDOMNode node= (PDOMNode) in.next();
|
||||||
node.accept(collector);
|
node.accept(collector);
|
||||||
}
|
}
|
||||||
bindings.clear();
|
nodes.clear();
|
||||||
bindings.addAll(Arrays.asList(collector.getBindings()));
|
nodes.addAll(Arrays.asList(collector.getNodes()));
|
||||||
}
|
}
|
||||||
result.addAll(bindings);
|
char[] name= names[names.length-1];
|
||||||
|
BindingCollector collector= new BindingCollector(linkage, name, filter, false, true);
|
||||||
|
for (Iterator in = nodes.iterator(); in.hasNext();) {
|
||||||
|
PDOMNode node= (PDOMNode) in.next();
|
||||||
|
node.accept(collector);
|
||||||
|
}
|
||||||
|
nodes.clear();
|
||||||
|
result.addAll(Arrays.asList(collector.getBindings()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
|
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
@ -242,10 +242,6 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
* Convenience method to shorten subclass file length
|
* Convenience method to shorten subclass file length
|
||||||
*/
|
*/
|
||||||
protected final void fail() { throw new PDOMNotImplementedError(); }
|
protected final void fail() { throw new PDOMNotImplementedError(); }
|
||||||
|
|
||||||
public boolean mayHaveChildren() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IName getScopeName() throws DOMException {
|
public IName getScopeName() throws DOMException {
|
||||||
try {
|
try {
|
||||||
|
@ -279,7 +275,15 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
final public boolean isFileLocal() throws CoreException {
|
final public boolean isFileLocal() throws CoreException {
|
||||||
return getParentNode() instanceof PDOMFileLocalScope;
|
return getParentNode() instanceof PDOMFileLocalScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public String getFileLocalScopeQualifier() throws CoreException {
|
||||||
|
final PDOMNode parentNode = getParentNode();
|
||||||
|
if (parentNode instanceof PDOMFileLocalScope) {
|
||||||
|
return ((PDOMFileLocalScope) parentNode).getDBName().getString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean hasDefinition() throws CoreException {
|
public boolean hasDefinition() throws CoreException {
|
||||||
return getFirstDefinition()!=null;
|
return getFirstDefinition()!=null;
|
||||||
|
|
|
@ -56,4 +56,8 @@ public class PDOMFileLocalScope extends PDOMNamedNode implements IPDOMMemberOwne
|
||||||
// no support for deleting bindings and their scopes.
|
// no support for deleting bindings and their scopes.
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean mayHaveChildren() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
|
import org.eclipse.cdt.internal.core.index.CIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
||||||
|
@ -130,11 +131,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
public boolean visit(int record) throws CoreException {
|
public boolean visit(int record) throws CoreException {
|
||||||
PDOMBinding binding = pdom.getBinding(record);
|
PDOMNode node= getNode(record);
|
||||||
if (binding != null) {
|
if (node != null) {
|
||||||
if (visitor.visit(binding))
|
if (visitor.visit(node))
|
||||||
binding.accept(visitor);
|
node.accept(visitor);
|
||||||
visitor.leave(binding);
|
visitor.leave(node);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -372,15 +373,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
final protected PDOMFileLocalScope findFileLocalScope(String fileName, boolean create) throws CoreException {
|
final protected PDOMFileLocalScope findFileLocalScope(String fileName, boolean create) throws CoreException {
|
||||||
char[] fname= fileName.toCharArray();
|
char[] fname = CIndex.getFileLocalScopeQualifier(fileName);
|
||||||
int fnamestart= findFileNameStart(fname);
|
|
||||||
StringBuffer buf= new StringBuffer();
|
|
||||||
buf.append('{');
|
|
||||||
buf.append(fname, fnamestart, fname.length-fnamestart);
|
|
||||||
buf.append(':');
|
|
||||||
buf.append(fileName.hashCode());
|
|
||||||
buf.append('}');
|
|
||||||
fname= buf.toString().toCharArray();
|
|
||||||
|
|
||||||
final PDOMFileLocalScope[] fls= new PDOMFileLocalScope[] {null};
|
final PDOMFileLocalScope[] fls= new PDOMFileLocalScope[] {null};
|
||||||
NamedNodeCollector collector= new NamedNodeCollector(this, fname) {
|
NamedNodeCollector collector= new NamedNodeCollector(this, fname) {
|
||||||
|
@ -399,17 +392,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
}
|
}
|
||||||
return fls[0];
|
return fls[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int findFileNameStart(char[] fname) {
|
|
||||||
for (int i= fname.length-2; i>=0; i--) {
|
|
||||||
switch (fname[i]) {
|
|
||||||
case '/':
|
|
||||||
case '\\':
|
|
||||||
return i+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteType(IType type, int ownerRec) throws CoreException {
|
public void deleteType(IType type, int ownerRec) throws CoreException {
|
||||||
if (type instanceof PDOMNode) {
|
if (type instanceof PDOMNode) {
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
@ -75,4 +76,8 @@ public abstract class PDOMNamedNode extends PDOMNode {
|
||||||
}
|
}
|
||||||
super.delete(linkage);
|
super.delete(linkage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean mayHaveChildren() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||||
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
@ -74,7 +75,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNodeType() {
|
public int getNodeType() {
|
||||||
return PDOMCLinkage.CPARAMETER;
|
return IIndexCBindingConstants.CPARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextParameter(PDOMCParameter nextParam) throws CoreException {
|
public void setNextParameter(PDOMCParameter nextParam) throws CoreException {
|
||||||
|
@ -161,6 +162,9 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
|
||||||
public boolean isFileLocal() throws CoreException {
|
public boolean isFileLocal() throws CoreException {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public String getFileLocalScopeQualifier() throws CoreException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String[] getQualifiedName() {
|
public String[] getQualifiedName() {
|
||||||
throw new PDOMNotImplementedError();
|
throw new PDOMNotImplementedError();
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
@ -121,7 +122,7 @@ class PDOMCPPParameter extends PDOMNamedNode
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNodeType() {
|
public int getNodeType() {
|
||||||
return PDOMCPPLinkage.CPPPARAMETER;
|
return IIndexCPPBindingConstants.CPPPARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextParameter(PDOMCPPParameter nextParam) throws CoreException {
|
public void setNextParameter(PDOMCPPParameter nextParam) throws CoreException {
|
||||||
|
@ -236,6 +237,10 @@ class PDOMCPPParameter extends PDOMNamedNode
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileLocalScopeQualifier() throws CoreException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public int getBindingConstant() {
|
public int getBindingConstant() {
|
||||||
return getNodeType();
|
return getNodeType();
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,10 +271,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
|
||||||
final IndexFilter filter= new IndexFilter() {
|
final IndexFilter filter= new IndexFilter() {
|
||||||
public boolean acceptBinding(IBinding binding) throws CoreException {
|
public boolean acceptBinding(IBinding binding) throws CoreException {
|
||||||
if (isVisibleType(IndexModelUtil.getElementType(binding))) {
|
if (isVisibleType(IndexModelUtil.getElementType(binding))) {
|
||||||
if (IndexFilter.ALL_DECLARED.acceptBinding(binding)) {
|
return IndexFilter.ALL_DECLARED.acceptBinding(binding);
|
||||||
// until we have correctly modeled file-local variables and functions, don't show them.
|
|
||||||
return !((IIndexBinding) binding).isFileLocal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue