1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 463234 - When disambiguating between targets for Open Declaration,

only prefer a method to a class if the method belongs to that class

Change-Id: I8cf9aed692ce989d83cc8ffd08672a3ee73a1c8b
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-03-29 22:30:52 -04:00 committed by Sergey Prigogin
parent c89901c49a
commit 55475a9fea
2 changed files with 37 additions and 2 deletions

View file

@ -1191,4 +1191,31 @@ public class CPPSelectionTestsNoIndexer extends BaseSelectionTests {
int offset = code.indexOf("obj.waldo") + 4;
assertTrue(testF3(file, offset) instanceof IASTName);
}
// struct A {
// A();
// };
//
// template <class>
// struct B {
// B() {}
// };
//
// struct C {
// C();
// B<A>* b;
// };
//
// C::C() : b(new B<A>()) {}
public void testAmbiguityWithImplicitName_463234() throws Exception {
String code = getAboveComment();
IFile file = importFile("testBug463234.cpp", code);
int offset = code.indexOf("new B<A>") + 6;
// There should be two ambiguous targets, the class A and the constructor B::B,
// with the class A being the first one (index 0).
IASTNode target = testF3WithAmbiguity(file, offset, 0);
assertTrue(target instanceof IASTName);
assertEquals("A", ((IASTName) target).toString());
}
}

View file

@ -528,9 +528,10 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
if (uniqueElements.size() == 2) {
final ICElement e0 = uniqueElements.get(0);
final ICElement e1 = uniqueElements.get(1);
if (e0 instanceof IStructureDeclaration && e1 instanceof IMethodDeclaration) {
// Prefer a method of a class, to the class itself.
if (isMethodOfClass(e1, e0)) {
target= (ISourceReference) e1;
} else if (e1 instanceof IStructureDeclaration && e0 instanceof IMethodDeclaration) {
} else if (isMethodOfClass(e0, e1)) {
target= (ISourceReference) e0;
}
}
@ -555,6 +556,13 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
}
}
}
private boolean isMethodOfClass(ICElement method, ICElement clazz) {
return method instanceof IMethodDeclaration
&& clazz instanceof IStructureDeclaration
&& method.getParent() != null
&& method.getParent().equals(clazz);
}
});
return true;
}