mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
[272744] fix for Open Declaration, doesn't work for ostream::operator <<
This commit is contained in:
parent
e2f1c90b0b
commit
3bd0a9fb8e
5 changed files with 62 additions and 28 deletions
|
@ -214,7 +214,7 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase {
|
|||
|
||||
if (part instanceof CEditor) {
|
||||
CEditor editor= (CEditor) part;
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10);
|
||||
((AbstractTextEditor)part).getSelectionProvider().setSelection(new TextSelection(offset,length));
|
||||
|
||||
final OpenDeclarationsAction action = (OpenDeclarationsAction) editor.getAction("OpenDeclarations"); //$NON-NLS-1$
|
||||
|
@ -224,7 +224,7 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase {
|
|||
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||
assertTrue (part instanceof CEditor);
|
||||
editor= (CEditor) part;
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10);
|
||||
|
||||
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
||||
ISelection sel= editor.getSelectionProvider().getSelection();
|
||||
|
|
|
@ -1145,4 +1145,32 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
|
|||
decl = testF3(file, offset2);
|
||||
assertNode("~X", offset1, decl);
|
||||
}
|
||||
|
||||
|
||||
// template<typename T>
|
||||
// class C {
|
||||
// public:
|
||||
// T operator+(int);
|
||||
// };
|
||||
|
||||
// void main() {
|
||||
// C<char> a;
|
||||
// a + 2;
|
||||
// }
|
||||
public void testBug272744() throws Exception {
|
||||
StringBuffer[] buffers= getContents(2);
|
||||
String hcode= buffers[0].toString();
|
||||
String scode= buffers[1].toString();
|
||||
IFile hfile = importFile("test.h", hcode); //$NON-NLS-1$
|
||||
IFile file = importFile("test.cpp", scode); //$NON-NLS-1$
|
||||
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
|
||||
|
||||
int hoffset= hcode.indexOf("operator+"); //$NON-NLS-1$
|
||||
int soffset = scode.indexOf("+"); //$NON-NLS-1$
|
||||
IASTNode def = testF3(file, soffset + 1);
|
||||
assertTrue(def instanceof IASTName);
|
||||
assertEquals(((IASTName) def).toString(), "operator +"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode) def).getOffset(), hoffset);
|
||||
assertEquals(((ASTNode) def).getLength(), 9);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
|||
IEditorPart part = null;
|
||||
try {
|
||||
part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer((AbstractTextEditor) part), 100, 500, 10);
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer((AbstractTextEditor) part), 100, 5000, 10);
|
||||
} catch (PartInitException e) {
|
||||
assertFalse(true);
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ public class CSelectionTestsNoIndexer extends BaseUITestCase {
|
|||
|
||||
if (part instanceof CEditor) {
|
||||
CEditor editor= (CEditor) part;
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 500, 10);
|
||||
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10);
|
||||
editor.getSelectionProvider().setSelection(new TextSelection(offset,length));
|
||||
|
||||
final OpenDeclarationsAction action = (OpenDeclarationsAction) editor.getAction("OpenDeclarations"); //$NON-NLS-1$
|
||||
|
|
|
@ -167,7 +167,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
|
|||
for(IASTImplicitName name : implicits) {
|
||||
if(((ASTNode)name).getOffset() == ((ASTNode)implicit).getOffset()) {
|
||||
IBinding binding = name.resolveBinding(); // guaranteed to resolve
|
||||
IName[] declNames = findNames(fIndex, ast, KIND_OTHER, binding);
|
||||
IName[] declNames = findDeclNames(ast, KIND_OTHER, binding);
|
||||
allNames.addAll(Arrays.asList(declNames));
|
||||
}
|
||||
}
|
||||
|
@ -193,29 +193,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
|
|||
isKind= KIND_DEFINITION;
|
||||
}
|
||||
}
|
||||
IName[] declNames = findNames(fIndex, ast, isKind, binding);
|
||||
if (declNames.length == 0) {
|
||||
if (binding instanceof ICPPSpecialization) {
|
||||
// bug 207320, handle template instances
|
||||
IBinding specialized= ((ICPPSpecialization) binding).getSpecializedBinding();
|
||||
if (specialized != null && !(specialized instanceof IProblemBinding)) {
|
||||
declNames = findNames(fIndex, ast, KIND_DEFINITION, specialized);
|
||||
}
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
// bug 86829, handle implicit methods.
|
||||
ICPPMethod method= (ICPPMethod) binding;
|
||||
if (method.isImplicit()) {
|
||||
try {
|
||||
IBinding clsBinding= method.getClassOwner();
|
||||
if (clsBinding != null && !(clsBinding instanceof IProblemBinding)) {
|
||||
declNames= findNames(fIndex, ast, KIND_OTHER, clsBinding);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
// don't log problem bindings.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
IName[] declNames = findDeclNames(ast, isKind, binding);
|
||||
if (navigateViaCElements(fWorkingCopy.getCProject(), fIndex, declNames)) {
|
||||
found= true;
|
||||
}
|
||||
|
@ -243,6 +221,34 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
|
|||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
|
||||
private IName[] findDeclNames(IASTTranslationUnit ast, int isKind, IBinding binding) throws CoreException {
|
||||
IName[] declNames = findNames(fIndex, ast, isKind, binding);
|
||||
if (declNames.length == 0) {
|
||||
if (binding instanceof ICPPSpecialization) {
|
||||
// bug 207320, handle template instances
|
||||
IBinding specialized= ((ICPPSpecialization) binding).getSpecializedBinding();
|
||||
if (specialized != null && !(specialized instanceof IProblemBinding)) {
|
||||
declNames = findNames(fIndex, ast, KIND_DEFINITION, specialized);
|
||||
}
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
// bug 86829, handle implicit methods.
|
||||
ICPPMethod method= (ICPPMethod) binding;
|
||||
if (method.isImplicit()) {
|
||||
try {
|
||||
IBinding clsBinding= method.getClassOwner();
|
||||
if (clsBinding != null && !(clsBinding instanceof IProblemBinding)) {
|
||||
declNames= findNames(fIndex, ast, KIND_OTHER, clsBinding);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
// don't log problem bindings.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return declNames;
|
||||
}
|
||||
|
||||
private boolean navigationFallBack(IASTTranslationUnit ast) {
|
||||
// bug 102643, as a fall-back we look up the selected word in the index
|
||||
if (sAllowFallback && fSelectedText != null && fSelectedText.length() > 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue