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 c735035f10a..57d38c5d0e0 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 @@ -1315,4 +1315,23 @@ public class CPPSelectionTestsIndexer extends BaseSelectionTestsIndexer { String expansion = new String(((IMacroBinding) binding).getExpansion()); assertTrue(expansion.contains("42")); } + + // #define DEFINE_FUNC(...) void foo() { __VA_ARGS__ } + // struct Waldo { + // void find(); + // }; + // DEFINE_FUNC + // ( + // Waldo waldo; + // waldo.find(); + // ) + public void testDeclarationInMacroArgment_509733() throws Exception { + String code = getAboveComment(); + IFile file = importFile("test.cpp", code); + waitUntilFileIsIndexed(index, file); + + int offset= code.indexOf("waldo.find()"); + IASTNode def = testF3(file, offset + 1); + assertTrue(def instanceof IASTName); + } } 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 55f0550c11a..2f8bff506e5 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 @@ -46,6 +46,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; +import org.eclipse.cdt.core.dom.ast.IASTImageLocation; import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -428,18 +429,32 @@ class OpenDeclarationsJob extends Job implements ASTRunnable { return null; } - private boolean areOverlappingNames(IName n1, IName n2) { + private static boolean areOverlappingNames(IName n1, IName n2) { if (n1 == n2) return true; - IASTFileLocation loc1 = n1.getFileLocation(); - IASTFileLocation loc2 = n2.getFileLocation(); + IASTFileLocation loc1 = getFileLocation(n1); + IASTFileLocation loc2 = getFileLocation(n2); if (loc1 == null || loc2 == null) return false; return loc1.getFileName().equals(loc2.getFileName()) && max(loc1.getNodeOffset(), loc2.getNodeOffset()) < min(loc1.getNodeOffset() + loc1.getNodeLength(), loc2.getNodeOffset() + loc2.getNodeLength()); } + + private static IASTFileLocation getFileLocation(IName name) { + IASTFileLocation fileLocation = name.getFileLocation(); + if (name instanceof IASTName) { + IASTName astName = (IASTName) name; + IASTImageLocation imageLocation = astName.getImageLocation(); + if (imageLocation != null && + imageLocation.getLocationKind() != IASTImageLocation.MACRO_DEFINITION && + astName.getTranslationUnit().getFilePath().equals(fileLocation.getFileName())) { + fileLocation = imageLocation; + } + } + return fileLocation; + } private static boolean isInSameFunction(IASTName refName, IName funcDeclName) { if (funcDeclName instanceof IASTName) { @@ -517,7 +532,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable { if (tu != null) { if (tu instanceof IWorkingCopy) tu = ((IWorkingCopy) tu).getOriginalElement(); - IASTFileLocation loc= astName.getFileLocation(); + IASTFileLocation loc= getFileLocation(astName); IRegion region= new Region(loc.getNodeOffset(), loc.getNodeLength()); return CElementHandleFactory.create(tu, binding, astName.isDefinition(), region, 0); } @@ -653,7 +668,7 @@ class OpenDeclarationsJob extends Job implements ASTRunnable { } private boolean navigateToName(IName name) { - return navigateToLocation(name.getFileLocation()); + return navigateToLocation(getFileLocation(name)); } private boolean navigateToLocation(IASTFileLocation fileloc) {