mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-13 11:15:38 +02:00
Bug 483048 - Navigation to forward declaration of class template
Change-Id: I611b50acf1ed80f02f7ee3edae4f8f80c4dfb313
This commit is contained in:
parent
e3017e7656
commit
cee87b1757
2 changed files with 23 additions and 1 deletions
|
@ -35,6 +35,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -1279,4 +1280,21 @@ public class CPPSelectionTestsNoIndexer extends BaseSelectionTests {
|
|||
IBinding targetBinding = ((IASTName) target).resolveBinding();
|
||||
assertInstance(targetBinding, ICPPConstructor.class);
|
||||
}
|
||||
|
||||
// template <typename = short>
|
||||
// struct waldo;
|
||||
//
|
||||
// template <typename>
|
||||
// struct waldo {};
|
||||
public void testNavigationToTemplateForwardDecl_483048() throws Exception {
|
||||
String code = getAboveComment();
|
||||
IFile file = importFile("testBug483048.cpp", code);
|
||||
|
||||
int offset = code.indexOf("waldo {}");
|
||||
IASTNode target = testF3(file, offset);
|
||||
|
||||
// Check that the result of the navigation is the forward declaration,
|
||||
// not the definition.
|
||||
assertInstance(target.getParent(), IASTElaboratedTypeSpecifier.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
|
@ -267,9 +268,12 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
|||
if (candidateBindings.length != 0) {
|
||||
bindings = candidateBindings;
|
||||
}
|
||||
} else if (kind == NameKind.DEFINITION && b instanceof IType) {
|
||||
} else if (kind == NameKind.DEFINITION && b instanceof IType && !(b instanceof ICPPClassTemplate)) {
|
||||
// Don't navigate away from a type definition.
|
||||
// Select the name at the current location instead.
|
||||
// However, for a class template, it's useful to navigate to
|
||||
// a forward declaration, as it may contain definitions of
|
||||
// default arguments, while the definition may not.
|
||||
navigateToName(sourceName);
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue