diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java index ffa994ab2fd..4e3ebfd1f48 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNodeSpecification.java @@ -201,10 +201,36 @@ public class ASTNodeSpecification { } public IASTPreprocessorMacroExpansion findLeadingMacroExpansion(ASTNodeSelector nodeSelector) { - return nodeSelector.findEnclosingMacroExpansion(fZeroToLeft ? fFileOffset-1 : fFileOffset, 1); + IASTPreprocessorMacroExpansion exp= nodeSelector.findEnclosingMacroExpansion(fZeroToLeft ? fFileOffset-1 : fFileOffset, 1); + if (fRelation == Relation.ENCLOSING) + return exp; + + if (exp != null) { + IASTFileLocation loc= exp.getFileLocation(); + if (loc != null) { + final int offset= loc.getNodeOffset(); + final int endOffset= offset+loc.getNodeLength(); + if (offset == fFileOffset && endOffset <= fFileEndOffset) + return exp; + } + } + return null; } public IASTPreprocessorMacroExpansion findTrailingMacroExpansion(ASTNodeSelector nodeSelector) { - return nodeSelector.findEnclosingMacroExpansion(fZeroToLeft ? fFileEndOffset : fFileEndOffset-1, 1); + IASTPreprocessorMacroExpansion exp= nodeSelector.findEnclosingMacroExpansion(fFileEndOffset==fFileOffset && !fZeroToLeft ? fFileEndOffset : fFileEndOffset-1, 1); + if (fRelation == Relation.ENCLOSING) + return exp; + + if (exp != null) { + IASTFileLocation loc= exp.getFileLocation(); + if (loc != null) { + final int offset= loc.getNodeOffset(); + final int endOffset= offset+loc.getNodeLength(); + if (endOffset == fFileEndOffset && offset >= fFileOffset) + return exp; + } + } + return null; } } \ No newline at end of file