1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 03:53:21 +02:00

Bug 484899 - Navigation to inherited constructor

Change-Id: I3ce24f3fb70e50b50757900c5ccb372abd855dfc
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-12-26 01:45:17 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent f82660f14c
commit e667b2631c
4 changed files with 38 additions and 3 deletions

View file

@ -455,8 +455,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
if (name == null) if (name == null)
return false; return false;
if (!isPrefixLookup) if (!isPrefixLookup) {
return CPPVisitor.isConstructorDeclaration(name); return CPPVisitor.isConstructorDeclaration(name)
|| CPPVisitor.isLastNameInUsingDeclaration(name);
}
IASTNode node = name.getParent(); IASTNode node = name.getParent();
if (node instanceof ICPPASTTemplateId) if (node instanceof ICPPASTTemplateId)

View file

@ -1031,6 +1031,13 @@ public class CPPVisitor extends ASTQueries {
return false; return false;
} }
public static boolean isLastNameInUsingDeclaration(IASTName name) {
IASTNode parent = name.getParent();
return parent instanceof ICPPASTQualifiedName
&& ((ICPPASTQualifiedName) parent).getLastName() == name
&& parent.getParent() instanceof ICPPASTUsingDeclaration;
}
public static IScope getContainingNonTemplateScope(final IASTNode inputNode) { public static IScope getContainingNonTemplateScope(final IASTNode inputNode) {
IScope scope= getContainingScope(inputNode); IScope scope= getContainingScope(inputNode);
while (scope instanceof ICPPTemplateScope) { while (scope instanceof ICPPTemplateScope) {

View file

@ -37,6 +37,8 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.core.testplugin.FileManager;
@ -1259,4 +1261,22 @@ public class CPPSelectionTestsNoIndexer extends BaseSelectionTests {
int offset = code.indexOf("42_d") + 3; int offset = code.indexOf("42_d") + 3;
assertTrue(testF3(file, offset) instanceof IASTName); assertTrue(testF3(file, offset) instanceof IASTName);
} }
// struct Base {
// Base(int, int);
// };
//
// struct Derived : Base {
// using Base::Base;
// };
public void testInheritedConstructor_484899() throws Exception {
String code = getAboveComment();
IFile file = importFile("testBug484899.cpp", code);
int offset = code.indexOf("Base::Base") + 7;
IASTNode target = testF3(file, offset);
assertInstance(target, IASTName.class);
IBinding targetBinding = ((IASTName) target).resolveBinding();
assertInstance(targetBinding, ICPPConstructor.class);
}
} }

View file

@ -215,6 +215,12 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
continue; continue;
} }
} }
if (binding instanceof ICPPUsingDeclaration) {
// For using-declarations, apply the logic below to each delegate
// individually.
bindings = ArrayUtil.addAll(bindings, ((ICPPUsingDeclaration) binding).getDelegates());
continue;
}
if (binding != null && !(binding instanceof IProblemBinding)) { if (binding != null && !(binding instanceof IProblemBinding)) {
IName[] names = findDeclNames(ast, kind, binding); IName[] names = findDeclNames(ast, kind, binding);
for (final IName name : names) { for (final IName name : names) {