mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 440940 - For Open Declaration, filter out results in headers that
aren't included Change-Id: I4d4ca59dbde1606105c7f3702559046fa160d686 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
4ff8bab2fb
commit
bb7af88082
2 changed files with 55 additions and 2 deletions
|
@ -27,6 +27,8 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
|
@ -1289,4 +1291,28 @@ public class CPPSelectionTestsIndexer extends BaseSelectionTestsIndexer {
|
||||||
IASTNode def = testF3(file, offset + 1);
|
IASTNode def = testF3(file, offset + 1);
|
||||||
assertTrue(def instanceof IASTName);
|
assertTrue(def instanceof IASTName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #define WALDO 42
|
||||||
|
|
||||||
|
// #define WALDO 98
|
||||||
|
|
||||||
|
// #include "a.hpp"
|
||||||
|
// int x = WALDO;
|
||||||
|
public void testTwoMacrosWithSameName_440940() throws Exception {
|
||||||
|
StringBuilder[] buffers = getContents(3);
|
||||||
|
String aHpp = buffers[0].toString();
|
||||||
|
String bHpp = buffers[1].toString();
|
||||||
|
String cpp = buffers[2].toString();
|
||||||
|
IFile aHppFile = importFile("a.hpp", aHpp);
|
||||||
|
IFile bHppFile = importFile("b.hpp", bHpp);
|
||||||
|
IFile cppFile = importFile("test.cpp", cpp);
|
||||||
|
waitUntilFileIsIndexed(index, cppFile);
|
||||||
|
|
||||||
|
IASTNode result = testF3(cppFile, cpp.indexOf("WALDO") + 1);
|
||||||
|
assertTrue(result instanceof IASTName);
|
||||||
|
IBinding binding = ((IASTName) result).resolveBinding();
|
||||||
|
assertTrue(binding instanceof IMacroBinding);
|
||||||
|
String expansion = new String(((IMacroBinding) binding).getExpansion());
|
||||||
|
assertTrue(expansion.contains("42"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
@ -229,7 +230,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
} else {
|
} else {
|
||||||
// Leave old method as fallback for local variables, parameters and
|
// Leave old method as fallback for local variables, parameters and
|
||||||
// everything else not covered by ICElementHandle.
|
// everything else not covered by ICElementHandle.
|
||||||
found = navigateOneLocation(targets);
|
found = navigateOneLocation(ast, targets);
|
||||||
}
|
}
|
||||||
if (!found && !navigationFallBack(ast, sourceName, kind)) {
|
if (!found && !navigationFallBack(ast, sourceName, kind)) {
|
||||||
fAction.reportSymbolLookupFailure(new String(sourceName.toCharArray()));
|
fAction.reportSymbolLookupFailure(new String(sourceName.toCharArray()));
|
||||||
|
@ -581,7 +582,33 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean navigateOneLocation(IName[] names) {
|
private IName[] filterNamesByIndexFileSet(IASTTranslationUnit ast, IName[] names) {
|
||||||
|
IIndexFileSet indexFileSet = ast.getIndexFileSet();
|
||||||
|
if (indexFileSet == null) {
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
IName[] result = IName.EMPTY_ARRAY;
|
||||||
|
for (IName name : names) {
|
||||||
|
if (name instanceof IIndexName) {
|
||||||
|
try {
|
||||||
|
if (!indexFileSet.contains(((IIndexName) name).getFile()))
|
||||||
|
continue;
|
||||||
|
} catch (CoreException e) {}
|
||||||
|
}
|
||||||
|
result = ArrayUtil.append(result, name);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean navigateOneLocation(IASTTranslationUnit ast, IName[] names) {
|
||||||
|
// If there is more than one name, try to filter out
|
||||||
|
// ones defined in a file not in the AST's index file set.
|
||||||
|
if (names.length > 1) {
|
||||||
|
IName[] filteredNames = filterNamesByIndexFileSet(ast, names);
|
||||||
|
if (filteredNames.length > 0) {
|
||||||
|
names = filteredNames;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (IName name : names) {
|
for (IName name : names) {
|
||||||
if (navigateToName(name)) {
|
if (navigateToName(name)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue