mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 01:06:01 +02:00
Bug 279366. Fix and test case.
This commit is contained in:
parent
8d95baecd0
commit
c9e4e19de9
3 changed files with 65 additions and 20 deletions
|
@ -1145,8 +1145,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde
|
|||
decl = testF3(file, offset2);
|
||||
assertNode("~X", offset1, decl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// template<typename T>
|
||||
// class C {
|
||||
// public:
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <code>null</code> 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(),
|
||||
|
|
Loading…
Add table
Reference in a new issue