diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index 0285de6f199..4a15757345d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -226,6 +226,8 @@ public class DOMLocationInclusionTests extends AST2FileBasePluginTest { assertNotNull(incs); assertEquals(incs.length, 1); assertSoleFileLocation(incs[0], filename, code.indexOf("#inc"), "#include \"foo.h\"".length()); + // test bug 166026 + assertEquals(tu.getFilePath(), incs[0].getContainingFilename()); checkInclude(incs[0], filename, code, "foo.h", false); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index a172403f452..571c5cc5134 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -2596,6 +2596,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { public String getContainingFilename(int offset) { _Context c = findContextForOffset(offset); if( c == null ) return EMPTY_STRING; + if (c instanceof _Inclusion && c.containsInDirective(offset, 1)) { + c = c.getParent(); + } _CompositeFileContext file = c.getContainingFileContext(); if( file == null ) return EMPTY_STRING; return file.reader.getPath();