diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java index 2480c07dd3b..acace37dfda 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java @@ -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(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index 6221367274b..82a50196b2b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -1145,4 +1145,32 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde decl = testF3(file, offset2); assertNode("~X", offset1, decl); } + + + // template + // class C { + // public: + // T operator+(int); + // }; + + // void main() { + // C 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); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java index bbb541de4d0..98ebdebad37 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java @@ -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); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java index 7c073751354..bf6e4d69b80 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java @@ -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$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index c92811fc8d1..0d067b6a456 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -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) {