diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java index 2450bfbbc3d..8c654bf27b5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java @@ -234,18 +234,18 @@ public class IndexSearchTest extends IndexTestBase { checkIsEnumeration(bindings[0]); } - public void _testFindStatic_161216() throws CoreException { + public void testFindStatic_161216() throws CoreException { Pattern pFunc= Pattern.compile("staticFunc20061017"); Pattern pVar= Pattern.compile("staticVar20061017"); IIndexBinding[] bindings; - bindings= fIndex.findBindings(pFunc, true, INDEX_FILTER, NPM); + bindings= fIndex.findBindings(pFunc, false, INDEX_FILTER, NPM); assertEquals(2, bindings.length); checkIsFunction(bindings[0]); checkIsFunction(bindings[1]); - bindings= fIndex.findBindings(pVar, true, INDEX_FILTER, NPM); + bindings= fIndex.findBindings(pVar, false, INDEX_FILTER, NPM); assertEquals(2, bindings.length); checkIsVariable(bindings[0]); checkIsVariable(bindings[1]); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java index daa28627b80..623bac1b99a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CFunctionTests.java @@ -57,9 +57,9 @@ public class CFunctionTests extends PDOMTestBase { public void testStaticCFunction() throws Exception { // static elements cannot be found on global scope, see bug 161216 - IBinding[] bindings = findQualifiedName(pdom, "staticCFunction"); - assertEquals(0, bindings.length); -// assertTrue(((IFunction) bindings[0]).isStatic()); + IBinding[] bindings = findUnqualifiedName(pdom, "staticCFunction"); + assertEquals(1, bindings.length); + assertTrue(((IFunction) bindings[0]).isStatic()); } public void testInlineCFunction() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java index 2bf0c479c1f..0b544e2122b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPFunctionTests.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -117,9 +118,9 @@ public class CPPFunctionTests extends PDOMTestBase { public void testStaticCPPFunction() throws Exception { // static elements cannot be found on global scope, see bug 161216 - IBinding[] bindings = findQualifiedName(pdom, "staticCPPFunction"); - assertEquals(0, bindings.length); -// assertTrue(((ICPPFunction) bindings[0]).isStatic()); + IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPFunction"); + assertEquals(1, bindings.length); + assertTrue(((ICPPFunction) bindings[0]).isStatic()); } public void testInlineCPPFunction() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java index 4d47ab81f17..c55d8941621 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CPPVariableTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation. + * Copyright (c) 2006, 2007 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -70,9 +71,9 @@ public class CPPVariableTests extends PDOMTestBase { public void testCPPStaticVariable() throws Exception { // static elements cannot be found on global scope, see bug 161216 - IBinding[] bindings = findQualifiedName(pdom, "staticCPPVariable"); - assertEquals(0, bindings.length); -// ICPPVariable variable = (ICPPVariable) bindings[0]; -// assertTrue(variable.isStatic()); + IBinding[] bindings = findUnqualifiedName(pdom, "staticCPPVariable"); + assertEquals(1, bindings.length); + ICPPVariable variable = (ICPPVariable) bindings[0]; + assertTrue(variable.isStatic()); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java index 2c3cd61f74c..eec3085dea1 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/CVariableTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 IBM Corporation. + * Copyright (c) 2006, 2007 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -70,10 +71,10 @@ public class CVariableTests extends PDOMTestBase { public void testCStaticVariable() throws Exception { // static elements cannot be found on global scope, see bug 161216 - IBinding[] bindings = findQualifiedName(pdom, "staticCVariable"); - assertEquals(0, bindings.length); -// IVariable variable = (IVariable) bindings[0]; -// assertTrue(variable.isStatic()); + IBinding[] bindings = findUnqualifiedName(pdom, "staticCVariable"); + assertEquals(1, bindings.length); + IVariable variable = (IVariable) bindings[0]; + assertTrue(variable.isStatic()); } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java index 6db543ae67f..56f10c73af4 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTestBase.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation - * Symbian - Fix a race condition (157992) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * IBM Corporation + * Symbian - Fix a race condition (157992) *******************************************************************************/ package org.eclipse.cdt.internal.pdom.tests; @@ -121,6 +121,15 @@ public class PDOMTestBase extends BaseTestCase { 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 * particular name. diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java index 3564fe548e9..1fd51118bcb 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java @@ -66,6 +66,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { } private final String[] fqn; + private final String fileLocal; private final int elementType; private final IIndex index; private final String[] params; @@ -81,6 +82,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { public static IndexTypeInfo create(IIndex index, IIndexBinding binding) { String[] fqn; int elementType; + String flsq= null; try { elementType = IndexModelUtil.getElementType(binding); if (binding instanceof ICPPBinding) { @@ -94,18 +96,22 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { else { fqn= new String[] {binding.getName()}; } + try { + flsq = binding.getFileLocalScopeQualifier(); + } catch (CoreException e) { + } if (binding instanceof IFunction) { final IFunction function= (IFunction)binding; final String[] paramTypes= IndexModelUtil.extractParameterTypes(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) { // index bindings don't throw DOMExceptions. 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); } - 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); this.fqn= fqn; + this.fileLocal= fileLocal; this.elementType= elementType; this.index= index; this.params= params; @@ -133,18 +140,18 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { * @deprecated, use {@link #create(IIndex, IBinding)}. */ 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)}. */ 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) { - 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) { @@ -337,11 +344,19 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { List references= new ArrayList(); try { index.acquireReadLock(); - - char[][] cfqn = new char[fqn.length][]; - for(int i=0; i + * 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 filter a filter that allows for skipping parts of the index * @param monitor a monitor to report progress, may be null. @@ -342,4 +345,11 @@ public interface IIndex { * @throws CoreException */ 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); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java index 89da0dc5ad4..b2dd99e6ba4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java @@ -43,4 +43,11 @@ public interface IIndexBinding extends IBinding { * in another index. */ 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, null is returned. + */ + String getFileLocalScopeQualifier() throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java index 33ce7860361..f6f5c398adb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java @@ -558,4 +558,32 @@ public class CIndex implements IIndex { 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java index cc4d17df512..988e3774ad0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java @@ -121,4 +121,8 @@ final public class EmptyCIndex implements IIndex { public IIndexMacro[] findMacrosForPrefix(char[] prefix, IndexFilter filter, IProgressMonitor monitor) { return IIndexMacro.EMPTY_INDEX_MACRO_ARRAY; } + + public String getFileLocalScopeQualifier(IIndexFileLocation loc) { + return new String(CIndex.getFileLocalScopeQualifier(loc.getFullPath())); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java index ed617a2ccd0..f7f4d4fc862 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeIndexBinding.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Ferguson (Symbian) - Initial implementation - * Markus Schorn (Wind River Systems) - * Bryan Wilkinson (QNX) + * Andrew Ferguson (Symbian) - Initial implementation + * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) *******************************************************************************/ package org.eclipse.cdt.internal.core.index.composite; @@ -87,9 +87,13 @@ public abstract class CompositeIndexBinding implements IIndexBinding { } 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) { if (obj == this) return true; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 5138048d8d2..79c9a753488 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -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.IPDOMLinkageFactory; 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.PDOMFile; 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.PDOMMacro; 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.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -372,20 +374,20 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (monitor.isCanceled()) throw new CoreException(Status.OK_STATUS); - if (node instanceof PDOMBinding) { - PDOMBinding binding = (PDOMBinding)node; - String name = binding.getName(); + if (node instanceof PDOMNamedNode) { + PDOMNamedNode nnode = (PDOMNamedNode)node; + String name = new String(nnode.getNameCharArray()); // check if we have a complete match. final int lastIdx = pattern.length-1; if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) { - if (filter.acceptBinding(binding)) { - bindings.add(binding); + if (nnode instanceof IBinding && filter.acceptBinding((IBinding) nnode)) { + bindings.add(nnode); } } // check if we have a partial match - if (binding.mayHaveChildren()) { + if (nnode.mayHaveChildren()) { boolean visitNextLevel= false; BitSet updatedMatchesUpToLevel= new BitSet(); if (!isFullyQualified) { @@ -401,7 +403,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { if (visitNextLevel) { matchStack.add(matchesUpToLevel); matchesUpToLevel= updatedMatchesUpToLevel; - currentPath.add(binding); + currentPath.add(nnode); 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 { + if (names.length == 0) { + return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; + } ArrayList result= new ArrayList(); + ArrayList nodes= 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++) { + nodes.add(linkage); + for (int i=0; i < names.length-1; i++) { char[] name= names[i]; - IndexFilter levelFilter= i==names.length-1 ? filter : IndexFilter.ALL; - BindingCollector collector= new BindingCollector(linkage, name, levelFilter, false, true); - for (Iterator in = bindings.iterator(); in.hasNext();) { + NamedNodeCollector collector= new NamedNodeCollector(linkage, name, false, true); + for (Iterator in = nodes.iterator(); in.hasNext();) { PDOMNode node= (PDOMNode) in.next(); node.accept(collector); } - bindings.clear(); - bindings.addAll(Arrays.asList(collector.getBindings())); + nodes.clear(); + 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()]); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 77b3ff07056..a6da94c6195 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) - * Andrew Ferguson (Symbian) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Andrew Ferguson (Symbian) *******************************************************************************/ 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 */ protected final void fail() { throw new PDOMNotImplementedError(); } - - public boolean mayHaveChildren() { - return false; - } public IName getScopeName() throws DOMException { try { @@ -279,7 +275,15 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen final public boolean isFileLocal() throws CoreException { 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 { return getFirstDefinition()!=null; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java index 6caf82c2565..4ec95ad4f75 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java @@ -56,4 +56,8 @@ public class PDOMFileLocalScope extends PDOMNamedNode implements IPDOMMemberOwne // no support for deleting bindings and their scopes. assert false; } + + public boolean mayHaveChildren() { + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index c8297913754..16045193266 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -41,6 +41,7 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexLinkage; import org.eclipse.cdt.internal.core.Util; 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.IIndexScope; import org.eclipse.cdt.internal.core.index.composite.CompositeScope; @@ -130,11 +131,11 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage return 0; } 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); + PDOMNode node= getNode(record); + if (node != null) { + if (visitor.visit(node)) + node.accept(visitor); + visitor.leave(node); } return true; } @@ -372,15 +373,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage * @since 4.0 */ final protected PDOMFileLocalScope findFileLocalScope(String fileName, boolean create) throws CoreException { - char[] fname= fileName.toCharArray(); - 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(); + char[] fname = CIndex.getFileLocalScopeQualifier(fileName); final PDOMFileLocalScope[] fls= new PDOMFileLocalScope[] {null}; NamedNodeCollector collector= new NamedNodeCollector(this, fname) { @@ -399,17 +392,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage } 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 { if (type instanceof PDOMNode) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java index 8ef77bee0bd..bda40e23e34 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java @@ -6,9 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * IBM Corporation - * Andrew Ferguson (Symbian) + * QNX - Initial API and implementation + * IBM Corporation + * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; @@ -75,4 +76,8 @@ public abstract class PDOMNamedNode extends PDOMNode { } super.delete(linkage); } + + public boolean mayHaveChildren() { + return false; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java index 4050a29d22a..25b6287eb0a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Andrew Ferguson (Symbian) + * QNX - Initial API and implementation + * Andrew Ferguson (Symbian) *******************************************************************************/ 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.ITypedef; 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.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -74,7 +75,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment } public int getNodeType() { - return PDOMCLinkage.CPARAMETER; + return IIndexCBindingConstants.CPARAMETER; } public void setNextParameter(PDOMCParameter nextParam) throws CoreException { @@ -161,6 +162,9 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment public boolean isFileLocal() throws CoreException { return true; } + public String getFileLocalScopeQualifier() throws CoreException { + return null; + } public String[] getQualifiedName() { throw new PDOMNotImplementedError(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java index 826b40f553c..2fcb1ccea5b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) - * IBM Corporation + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * IBM Corporation *******************************************************************************/ 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.dom.parser.cpp.CPPParameter; 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.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.pdom.PDOM; @@ -121,7 +122,7 @@ class PDOMCPPParameter extends PDOMNamedNode } public int getNodeType() { - return PDOMCPPLinkage.CPPPARAMETER; + return IIndexCPPBindingConstants.CPPPARAMETER; } public void setNextParameter(PDOMCPPParameter nextParam) throws CoreException { @@ -236,6 +237,10 @@ class PDOMCPPParameter extends PDOMNamedNode return true; } + public String getFileLocalScopeQualifier() throws CoreException { + return null; + } + public int getBindingConstant() { return getNodeType(); } diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java index f245cd60215..6d1afde40b4 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java @@ -271,10 +271,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog { final IndexFilter filter= new IndexFilter() { public boolean acceptBinding(IBinding binding) throws CoreException { if (isVisibleType(IndexModelUtil.getElementType(binding))) { - if (IndexFilter.ALL_DECLARED.acceptBinding(binding)) { - // until we have correctly modeled file-local variables and functions, don't show them. - return !((IIndexBinding) binding).isFileLocal(); - } + return IndexFilter.ALL_DECLARED.acceptBinding(binding); } return false; }