From 429128162f4564252658dfb6b4d215d1d264a808 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 25 Oct 2006 14:32:45 +0000 Subject: [PATCH] Keeps static functions/variables out of the index, see bug 161216 --- .../internal/pdom/tests/CFunctionTests.java | 5 +- .../internal/pdom/tests/CPPFunctionTests.java | 5 +- .../internal/pdom/tests/CPPVariableTests.java | 7 +- .../internal/pdom/tests/CVariableTests.java | 7 +- .../cdt/internal/pdom/tests/DefDeclTests.java | 16 ++-- .../core/pdom/dom/c/PDOMCLinkage.java | 75 +++++++++++-------- .../core/pdom/dom/cpp/PDOMCPPLinkage.java | 13 +++- .../callhierarchy/CallHierarchyBaseTest.java | 2 +- 8 files changed, 80 insertions(+), 50 deletions(-) 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 8af80aa1044..784ab6b3645 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 @@ -49,9 +49,10 @@ 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(1, bindings.length); - assertTrue(((IFunction) bindings[0]).isStatic()); + assertEquals(0, 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 e1c0ec6fb6c..f8d13234468 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 @@ -91,9 +91,10 @@ 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(1, bindings.length); - assertTrue(((ICPPFunction) bindings[0]).isStatic()); + assertEquals(0, 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 e37c3f67d76..f2555603a3f 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 @@ -64,9 +64,10 @@ 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(1, bindings.length); - ICPPVariable variable = (ICPPVariable) bindings[0]; - assertTrue(variable.isStatic()); + assertEquals(0, 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 64ee81a9433..502dda55986 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 @@ -64,10 +64,11 @@ 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(1, bindings.length); - IVariable variable = (IVariable) bindings[0]; - assertTrue(variable.isStatic()); + assertEquals(0, 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/DefDeclTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java index 18ab5978067..7a0781cd3dd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java @@ -227,12 +227,18 @@ public class DefDeclTests extends PDOMTestBase { public void testStaticBindings_f08_unexpected() throws Exception { // should be 2 bindings, otherwise how to distinguish proper def/decl // pairs? + // static elements cannot be found on global scope, see bug 161216 String elName = "foo" + "08"; - IBinding binding = findSingleBinding(elName); - checkDefinition(binding, "def" + "08", 2); - checkReference(binding, "ref" + "08", 2); - checkDefinition(binding, "defS" + "08", 2); - checkReference(binding, "refS" + "08", 2); + IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, + IndexFilter.ALL, new NullProgressMonitor()); + assertEquals(0, binds.length); +// assertEquals(elName, binds[0].getName()); +// IBinding element = binds[0]; +// IBinding binding = element; +// checkDefinition(binding, "def" + "08", 2); +// checkReference(binding, "ref" + "08", 2); +// checkDefinition(binding, "defS" + "08", 2); +// checkReference(binding, "refS" + "08", 2); } public void testSimpleGlobalWrite_v09() throws Exception { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java index 88b0d4c5133..c87fc941afc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java @@ -104,41 +104,54 @@ class PDOMCLinkage extends PDOMLinkage { return null; PDOMBinding pdomBinding = adaptBinding(binding); - if (pdomBinding == null) { - PDOMNode parent = getAdaptedParent(binding); - if (parent == null) - return null; + try { + if (pdomBinding == null) { + PDOMNode parent = getAdaptedParent(binding); + if (parent == null) + return null; - if (binding instanceof IParameter) - return null; // skip parameters - else if (binding instanceof IField) { // must be before IVariable - if (parent instanceof IPDOMMemberOwner) - pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, name); - } else if (binding instanceof IVariable) - pdomBinding = new PDOMCVariable(pdom, parent, name); - else if (binding instanceof IFunction) - pdomBinding = new PDOMCFunction(pdom, parent, name); - else if (binding instanceof ICompositeType) - pdomBinding = new PDOMCStructure(pdom, parent, name); - else if (binding instanceof IEnumeration) - pdomBinding = new PDOMCEnumeration(pdom, parent, name); - else if (binding instanceof IEnumerator) { - try { - IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); - PDOMBinding pdomEnumeration = adaptBinding(enumeration); - if (pdomEnumeration instanceof PDOMCEnumeration) - pdomBinding = new PDOMCEnumerator(pdom, parent, name, - (PDOMCEnumeration)pdomEnumeration); - } catch (DOMException e) { - throw new CoreException(Util.createStatus(e)); + if (binding instanceof IParameter) + return null; // skip parameters + else if (binding instanceof IField) { // must be before IVariable + if (parent instanceof IPDOMMemberOwner) + pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, name); + } else if (binding instanceof IVariable) { + IVariable var= (IVariable) binding; + if (!var.isStatic()) { // bug 161216 + pdomBinding = new PDOMCVariable(pdom, parent, name); + } + } + else if (binding instanceof IFunction) { + IFunction func= (IFunction) binding; + if (!func.isStatic()) { // bug 161216 + pdomBinding = new PDOMCFunction(pdom, parent, name); + } + } + else if (binding instanceof ICompositeType) + pdomBinding = new PDOMCStructure(pdom, parent, name); + else if (binding instanceof IEnumeration) + pdomBinding = new PDOMCEnumeration(pdom, parent, name); + else if (binding instanceof IEnumerator) { + try { + IEnumeration enumeration = (IEnumeration)((IEnumerator)binding).getType(); + PDOMBinding pdomEnumeration = adaptBinding(enumeration); + if (pdomEnumeration instanceof PDOMCEnumeration) + pdomBinding = new PDOMCEnumerator(pdom, parent, name, + (PDOMCEnumeration)pdomEnumeration); + } catch (DOMException e) { + throw new CoreException(Util.createStatus(e)); + } + } else if (binding instanceof ITypedef) + pdomBinding = new PDOMCTypedef(pdom, parent, name, (ITypedef)binding); + + if(pdomBinding!=null) { + parent.addChild(pdomBinding); } - } else if (binding instanceof ITypedef) - pdomBinding = new PDOMCTypedef(pdom, parent, name, (ITypedef)binding); - - if(pdomBinding!=null) { - parent.addChild(pdomBinding); } } + catch (DOMException e) { + throw new CoreException(Util.createStatus(e)); + } if (pdomBinding != null) new PDOMName(pdom, name, file, pdomBinding); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index c67add19bf5..ddf93824f60 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -136,8 +136,12 @@ class PDOMCPPLinkage extends PDOMLinkage { if (binding instanceof ICPPField && parent instanceof PDOMCPPClassType) pdomBinding = new PDOMCPPField(pdom, (PDOMCPPClassType)parent, name); else if (binding instanceof ICPPVariable) { - if (!(binding.getScope() instanceof CPPBlockScope)) - pdomBinding = new PDOMCPPVariable(pdom, parent, name); + if (!(binding.getScope() instanceof CPPBlockScope)) { + ICPPVariable var= (ICPPVariable) binding; + if (!var.isStatic()) { // bug 161216 + pdomBinding = new PDOMCPPVariable(pdom, parent, name); + } + } } else if (binding instanceof ICPPMethod && parent instanceof PDOMCPPClassType) { pdomBinding = new PDOMCPPMethod(pdom, parent, name); } else if (binding instanceof CPPImplicitMethod && parent instanceof PDOMCPPClassType) { @@ -147,7 +151,10 @@ class PDOMCPPLinkage extends PDOMLinkage { pdomBinding = new PDOMCPPMethod(pdom, parent, name); } } else if (binding instanceof ICPPFunction) { - pdomBinding = new PDOMCPPFunction(pdom, parent, name); + ICPPFunction func= (ICPPFunction) binding; + if (!func.isStatic()) { // bug 161216 + pdomBinding = new PDOMCPPFunction(pdom, parent, name); + } } else if (binding instanceof ICPPClassType) { pdomBinding = new PDOMCPPClassType(pdom, parent, name); } else if (binding instanceof ICPPNamespaceAlias) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java index 9ddebf3f380..319c9107901 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java @@ -97,7 +97,7 @@ public class CallHierarchyBaseTest extends BaseUITestCase { try { TreeItem root= tree.getItem(i0); TreeItem item= root.getItem(i1); - for (int i=0; i<20; i++) { + for (int i=0; i<40; i++) { if (!"...".equals(item.getText())) { break; }