From c53849b219319bbc2b364852bc19c38e5517f675 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 29 Nov 2006 15:02:32 +0000 Subject: [PATCH] Fix for bug 166026 - getContainingFilename wrong for include directives --- .../cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java | 2 ++ .../eclipse/cdt/internal/core/parser/scanner2/LocationMap.java | 3 +++ 2 files changed, 5 insertions(+) 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();