mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 341008: Open element for enumerators nested in classes.
This commit is contained in:
parent
7edc697389
commit
a3be88af27
2 changed files with 47 additions and 40 deletions
|
@ -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<C>", 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 {};
|
||||
|
|
|
@ -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<PDOMBinding> result= new ArrayList<PDOMBinding>();
|
||||
ArrayList<PDOMNamedNode> nodes= new ArrayList<PDOMNamedNode>();
|
||||
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<PDOMNamedNode> 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<PDOMNamedNode> 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue