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 2229d964eba..9f91deb2c41 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,8 +1145,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde decl = testF3(file, offset2); assertNode("~X", offset1, decl); } - - + // template // class C { // public: 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 05a5a8e6f36..1a9e2020d74 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 @@ -259,7 +259,7 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase { ITextEditor editor= (ITextEditor) part; editor.getSelectionProvider().setSelection(new TextSelection(offset,length)); - final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor)part).getAction("OpenDeclarations"); //$NON-NLS-1$ + final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor) part).getAction("OpenDeclarations"); //$NON-NLS-1$ action.runSync(); // the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU @@ -1091,4 +1091,23 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase { IASTNode node= testF3(file, offset); assertNull(node); } + + // void func(int a); + // void func(float a); + // void func(int* a); + // void test() { + // func(); + // } + public void testUnresolvedOverloadedFunction() throws Exception { + String code= getContentsForTest(1)[0].toString(); + IFile file = importFile("testUnresolvedOverloadFunction.cpp", code); + int offset= code.indexOf("func();"); + try { + IASTNode node= testF3(file, offset); + } catch (RuntimeException e) { + assertEquals("ambiguous input: 3", e.getMessage()); + return; + } + fail("Expected exception not caught"); + } } 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 879297b470a..6f6439b259e 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 @@ -202,34 +202,46 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR navigateToName(sourceName); return Status.OK_STATUS; } + IName[] declNames = null; + String filename = ast.getFilePath(); for (IBinding binding : bindings) { if (binding != null && !(binding instanceof IProblemBinding)) { - IName[] declNames = findDeclNames(ast, kind, binding); - // Exclude the current location. - for (int i = 0; i < declNames.length; i++) { - if (isSameName(declNames[i], sourceName)) { - declNames[i] = null; + IName[] names = findDeclNames(ast, kind, binding); + for (int i = 0; i < names.length; i++) { + if (names[i] instanceof IIndexName && + filename.equals(((IIndexName) names[i]).getFileLocation().getFileName())) { + // Exclude index names from the current file. + names[i] = null; + } else if (isSameName(names[i], sourceName)) { + // Exclude the current location. + names[i] = null; } else if (binding instanceof IParameter) { - if (!isInSameFunction(sourceName, declNames[i])) { - declNames[i] = null; + if (!isInSameFunction(sourceName, names[i])) { + names[i] = null; } } else if (binding instanceof ICPPTemplateParameter) { - if (!isInSameTemplate(sourceName, declNames[i])) { - declNames[i] = null; + if (!isInSameTemplate(sourceName, names[i])) { + names[i] = null; } } } - declNames = (IName[]) ArrayUtil.removeNulls(IName.class, declNames); - - if (navigateViaCElements(fWorkingCopy.getCProject(), fIndex, declNames)) { - found= true; + compact(names); + if (declNames == null) { + declNames = names; } else { - // Leave old method as fallback for local variables, parameters and - // everything else not covered by ICElementHandle. - found = navigateOneLocation(declNames); + declNames = (IName[]) ArrayUtil.addAll(IName.class, declNames, names); } } } + declNames = (IName[]) ArrayUtil.removeNulls(IName.class, declNames); + + if (navigateViaCElements(fWorkingCopy.getCProject(), fIndex, declNames)) { + found= true; + } else { + // Leave old method as fallback for local variables, parameters and + // everything else not covered by ICElementHandle. + found = navigateOneLocation(declNames); + } if (!found && !navigationFallBack(ast, sourceName, kind)) { reportSymbolLookupFailure(new String(sourceName.toCharArray())); } @@ -248,6 +260,21 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR return Status.OK_STATUS; } + /** + * Compacts an array by moving all null elements to the end. + * @param array + */ + private void compact(Object[] array) { + for (int i = 0, j = 0; i < array.length; i++) { + if (array[i] != null) { + if (i != j) { + array[j] = array[i]; + } + j++; + } + } + } + private static NameKind getNameKind(IName name) { if (name.isDefinition()) { if (getBinding(name) instanceof ICPPUsingDeclaration) { @@ -496,7 +523,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR target= (ISourceReference) elements.get(0); } else { if (sIsJUnitTest) { - throw new RuntimeException("ambiguous input"); //$NON-NLS-1$ + throw new RuntimeException("ambiguous input: " + elements.size()); //$NON-NLS-1$ } ICElement[] elemArray= elements.toArray(new ICElement[elements.size()]); target = (ISourceReference) OpenActionUtil.selectCElement(elemArray, getSite().getShell(),