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 1c2830d8f02..8cd2b31fa79 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 @@ -351,6 +351,27 @@ public class DOMLocationInclusionTests extends FileBasePluginTest { assertEquals( "_INCLUDE_H_".length(), flatLoc.getNodeLength() ); //$NON-NLS-1$ } } + + public void testIProblemLocation() throws Exception + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "#include \n"); //$NON-NLS-1$ + buffer.append( "int x,y,z;"); //$NON-NLS-1$ + String code = buffer.toString(); + IFile f = importFile( "blah.c", code ); //$NON-NLS-1$ + for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP + : null) { + IASTTranslationUnit tu = parse( f, p ); //$NON-NLS-1$ + IASTProblem [] prbs = tu.getPreprocessorProblems(); + assertEquals( prbs.length, 1 ); + IASTNodeLocation [] locs = prbs[0].getNodeLocations(); + assertEquals( locs.length, 1 ); + IASTFileLocation fileLoc = (IASTFileLocation) locs[0]; + assertEquals( code.indexOf( "#include" ), fileLoc.getNodeOffset() ); //$NON-NLS-1$ + assertEquals( "#include \n".length(), fileLoc.getNodeLength() ); //$NON-NLS-1$ + } + + } public static Test suite() { TestSuite suite = new TestSuite(DOMLocationInclusionTests.class); 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 9f2dfa9bb0e..91a3f287573 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 @@ -1736,7 +1736,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { protected IASTNodeLocation createSoleLocation(_Context c, int offset, int length) { - if (c instanceof _IPreprocessorDirective) { + if (c instanceof _IPreprocessorDirective || c instanceof _Problem ) { if (c.containsInDirective(offset, length)) { _CompositeContext parent = c.parent; while (!(parent instanceof _CompositeFileContext)) @@ -1745,7 +1745,6 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { return new FileLocation(fc.reader.filename, reconcileOffset(fc, c, offset), length); } - } if (c instanceof _CompositeFileContext) { return new FileLocation(