Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2015-03-30 07:23:47 +0000
committerSergey Prigogin2015-04-03 21:25:09 +0000
commitbb7af880828b77aedafd029eeb20a1d7ff76e4e8 (patch)
tree42321a2d4a610f5b0f4f20e701fbf61946ca83a1
parent4ff8bab2fb95b73774c973685333d591e3fdc4d6 (diff)
downloadorg.eclipse.cdt-bb7af880828b77aedafd029eeb20a1d7ff76e4e8.tar.gz
org.eclipse.cdt-bb7af880828b77aedafd029eeb20a1d7ff76e4e8.tar.xz
org.eclipse.cdt-bb7af880828b77aedafd029eeb20a1d7ff76e4e8.zip
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>
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsIndexer.java26
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java31
2 files changed, 55 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsIndexer.java
index a8a54f244fb..be0b5716ef0 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsIndexer.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsIndexer.java
@@ -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.IASTName;
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.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
@@ -1289,4 +1291,28 @@ public class CPPSelectionTestsIndexer extends BaseSelectionTestsIndexer {
IASTNode def = testF3(file, offset + 1);
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"));
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java
index 3cefaa6fa07..1b0f2320a44 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsJob.java
@@ -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.index.IIndex;
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.IIndexManager;
import org.eclipse.cdt.core.index.IIndexName;
@@ -229,7 +230,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
} else {
// Leave old method as fallback for local variables, parameters and
// everything else not covered by ICElementHandle.
- found = navigateOneLocation(targets);
+ found = navigateOneLocation(ast, targets);
}
if (!found && !navigationFallBack(ast, sourceName, kind)) {
fAction.reportSymbolLookupFailure(new String(sourceName.toCharArray()));
@@ -581,7 +582,33 @@ class OpenDeclarationsJob extends Job implements ASTRunnable {
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) {
if (navigateToName(name)) {
return true;

Back to the top