From a3be88af27c519e6b5d68083c57cd7569d8b71b5 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 30 Mar 2011 16:49:04 +0000 Subject: [PATCH] Bug 341008: Open element for enumerators nested in classes. --- .../tests/IndexCPPTemplateResolutionTest.java | 25 ++++---- .../eclipse/cdt/internal/core/pdom/PDOM.java | 62 +++++++++++-------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 41296c1fbe4..9ccba88bf57 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -15,9 +15,7 @@ import java.util.List; import junit.framework.TestSuite; -import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBasicType.Kind; @@ -52,10 +50,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.parser.util.ObjectMap; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBasicType; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassSpecializationScope; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates; @@ -1189,24 +1187,23 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassType b1= getBindingFromASTName("B adb", 1, ICPPClassType.class, ICPPSpecialization.class); ICPPClassType b2= getBindingFromASTName("A", 4, ICPPClassType.class, ICPPSpecialization.class); - ICPPClassType b3= (ICPPClassType) getIndex().findBindings("A".toCharArray(), new IndexFilter() { + IIndexBinding[] sr = getIndex().findBindings("A".toCharArray(), new IndexFilter() { @Override public boolean acceptBinding(IBinding binding) throws CoreException { return !(binding instanceof ICPPSpecialization); } - }, npm())[0]; + }, npm()); + assertTrue(sr.length == 1); + ICPPClassType b3= (ICPPClassType) sr[0]; - ICPPClassType b4= (ICPPClassType) getIndex().findBindings(new char[][] {"A".toCharArray(), "B".toCharArray()}, new IndexFilter() { + sr = getIndex().findBindings(new char[][] {"A".toCharArray(), "B".toCharArray()}, new IndexFilter() { @Override public boolean acceptBinding(IBinding binding) throws CoreException { - try { - return !(binding.getScope() instanceof CPPClassSpecializationScope); // - } catch(DOMException de) { - CCorePlugin.log(de); - return false; - } + return binding instanceof ICPPSpecialization; } - }, npm())[0]; + }, npm()); + assertTrue(sr.length == 1); + ICPPClassType b4= (ICPPClassType) sr[0]; assertFalse(b0 instanceof ICPPSpecialization); @@ -1217,7 +1214,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa ICPPClassScope cs1= assertInstance(s1, ICPPClassScope.class); assertInstance(cs1.getClassType(), ICPPClassType.class); assertInstance(cs1.getClassType(), ICPPTemplateInstance.class); - assertTrue(((IType)s4.getScopeBinding()).isSameType( (IType) ((IIndexScope)b3.getCompositeScope()).getScopeBinding() )); + assertTrue(((IType)((ICPPClassSpecialization) s4.getScopeBinding()).getSpecializedBinding()).isSameType( (IType) ((IIndexScope)b3.getCompositeScope()).getScopeBinding() )); } // class A {}; 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 501ad6fd756..6848412b17d 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 @@ -56,6 +56,8 @@ import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexMacroContainer; import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexFragment; @@ -75,7 +77,6 @@ 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.MacroContainerCollector; import org.eclipse.cdt.internal.core.pdom.dom.MacroContainerPatternCollector; -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; @@ -729,35 +730,44 @@ public class PDOM extends PlatformObject implements IPDOM { if (names.length == 0) { return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; } - ArrayList result= new ArrayList(); - ArrayList nodes= new ArrayList(); - for (PDOMLinkage linkage : getLinkageList()) { - if (filter.acceptLinkage(linkage)) { - nodes.add(linkage); - for (int i=0; i < names.length-1; i++) { - char[] name= names[i]; - NamedNodeCollector collector= new NamedNodeCollector(linkage, name, false, false, caseSensitive); - for (Iterator in = nodes.iterator(); in.hasNext();) { - PDOMNode node= in.next(); - node.accept(collector); - } - nodes.clear(); - nodes.addAll(Arrays.asList(collector.getNodes())); - } - char[] name= names[names.length-1]; - BindingCollector collector= new BindingCollector(linkage, name, filter, false, false, caseSensitive); - for (Iterator in = nodes.iterator(); in.hasNext();) { - PDOMNode node= in.next(); - node.accept(collector); - } - nodes.clear(); - result.addAll(Arrays.asList(collector.getBindings())); + if (names.length == 1) { + return findBindings(names[0], true, caseSensitive, filter, monitor); + } + + IIndexFragmentBinding[] candidates = findBindings(names[names.length-1], false, caseSensitive, filter, monitor); + int j= 0; + for (int i = 0; i < candidates.length; i++) { + IIndexFragmentBinding cand = candidates[i]; + if (matches(cand, names, caseSensitive)) { + candidates[j++]= cand; } } - return result.toArray(new IIndexFragmentBinding[result.size()]); + return ArrayUtil.trimAt(IIndexFragmentBinding.class, candidates, j-1); + } + + private boolean matches(IIndexFragmentBinding cand, char[][] names, boolean caseSensitive) { + int i= names.length-1; + while(i >= 0) { + if (cand == null) + return false; + + char[] name= cand.getNameCharArray(); + if (!CharArrayUtils.equals(name, 0, name.length, names[i], !caseSensitive)) { + if (cand instanceof IEnumeration) { + if (cand instanceof ICPPEnumeration && ((ICPPEnumeration) cand).isScoped()) + return false; + // Unscoped enumerations are not part of the qualified name. + i++; + } else { + return false; + } + } + cand= cand.getOwner(); + i--; + } + return cand == null; } - private long getFirstLinkageRecord() throws CoreException { return db.getRecPtr(LINKAGES); }