diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java index 05d4f5dcfea..22ea7b42331 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTNode.java @@ -43,7 +43,14 @@ public interface IASTNode { * @return IASTNodeLocation [] */ public IASTNodeLocation[] getNodeLocations(); - + + /** + * Lightweight check for understanding what file we are in. + * + * @return String absolute path + */ + public String getContainingFilename(); + /** * Get the parent node of this node in the tree. * diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java index 85acd26372d..fdf3f75ed4e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -161,6 +161,8 @@ public interface IASTTranslationUnit extends IASTNode { } public IDependencyTree getDependencyTree(); + + public String getContainingFilename(int offset); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CodeReader.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CodeReader.java index b1205fd4acc..3e6e218ded4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CodeReader.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/CodeReader.java @@ -129,7 +129,12 @@ public class CodeReader { } public String toString() { - return new String( filename ); + return getPath(); } + public String getPath() + { + return new String( filename ); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java index f3c69e873af..4d5ec5428dd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java @@ -69,4 +69,8 @@ public abstract class ASTNode implements IASTNode { public String getRawSignature() { return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() ); } + + public String getContainingFilename() { + return getTranslationUnit().getContainingFilename( offset ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 993bf3ba4ae..97d27e7b52b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -509,4 +509,10 @@ public class CASTTranslationUnit extends CASTNode implements return null; return resolver.getDependencyTree(); } + + public String getContainingFilename(int offset) { + if( resolver == null ) + return EMPTY_STRING; + return resolver.getContainingFilename( offset ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 6d331d90d7c..5135ba8a9e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -497,5 +497,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements return resolver.getDependencyTree(); } + public String getContainingFilename(int offset) { + if( resolver == null ) + return EMPTY_STRING; + return resolver.getContainingFilename( offset ); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java index 044435a1862..c8121721d0d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java @@ -49,5 +49,6 @@ public interface ILocationResolver { public IASTName[] getDeclarations(IMacroBinding binding); public IASTName[] getMacroExpansions(); public IDependencyTree getDependencyTree(); + public String getContainingFilename(int offset); } 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 b1b4903d66c..7eb167b8017 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 @@ -994,6 +994,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } return false; } + + public _CompositeFileContext getContainingFileContext() { + if( this instanceof _CompositeFileContext ) + return (_CompositeFileContext) this; + _CompositeContext result = getParent(); + while( !( result instanceof _CompositeFileContext ) ) + result = result.getParent(); + return (_CompositeFileContext) result; + } } protected static class _CompositeContext extends _Context { @@ -2116,6 +2125,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { protected IASTTranslationUnit rootNode; + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + protected static int collectContexts(int key, _Context source, @@ -2521,4 +2532,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { tu.addBuiltinMacro( result ); return result; } + + public String getContainingFilename(int offset) { + _Context c = findContextForOffset(offset); + if( c == null ) return EMPTY_STRING; + _CompositeFileContext file = c.getContainingFileContext(); + if( file == null ) return EMPTY_STRING; + return file.reader.getPath(); + } } \ No newline at end of file