mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added IASTNode#getContainingFilename()
This commit is contained in:
parent
c7b5a7da63
commit
7a6f934182
8 changed files with 51 additions and 2 deletions
|
@ -43,7 +43,14 @@ public interface IASTNode {
|
||||||
* @return <code>IASTNodeLocation []</code>
|
* @return <code>IASTNodeLocation []</code>
|
||||||
*/
|
*/
|
||||||
public IASTNodeLocation[] getNodeLocations();
|
public IASTNodeLocation[] getNodeLocations();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lightweight check for understanding what file we are in.
|
||||||
|
*
|
||||||
|
* @return <code>String</code> absolute path
|
||||||
|
*/
|
||||||
|
public String getContainingFilename();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent node of this node in the tree.
|
* Get the parent node of this node in the tree.
|
||||||
*
|
*
|
||||||
|
|
|
@ -161,6 +161,8 @@ public interface IASTTranslationUnit extends IASTNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDependencyTree getDependencyTree();
|
public IDependencyTree getDependencyTree();
|
||||||
|
|
||||||
|
public String getContainingFilename(int offset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,12 @@ public class CodeReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new String( filename );
|
return getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPath()
|
||||||
|
{
|
||||||
|
return new String( filename );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,4 +69,8 @@ public abstract class ASTNode implements IASTNode {
|
||||||
public String getRawSignature() {
|
public String getRawSignature() {
|
||||||
return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() );
|
return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContainingFilename() {
|
||||||
|
return getTranslationUnit().getContainingFilename( offset );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,4 +509,10 @@ public class CASTTranslationUnit extends CASTNode implements
|
||||||
return null;
|
return null;
|
||||||
return resolver.getDependencyTree();
|
return resolver.getDependencyTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContainingFilename(int offset) {
|
||||||
|
if( resolver == null )
|
||||||
|
return EMPTY_STRING;
|
||||||
|
return resolver.getContainingFilename( offset );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,5 +497,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||||
return resolver.getDependencyTree();
|
return resolver.getDependencyTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getContainingFilename(int offset) {
|
||||||
|
if( resolver == null )
|
||||||
|
return EMPTY_STRING;
|
||||||
|
return resolver.getContainingFilename( offset );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,5 +49,6 @@ public interface ILocationResolver {
|
||||||
public IASTName[] getDeclarations(IMacroBinding binding);
|
public IASTName[] getDeclarations(IMacroBinding binding);
|
||||||
public IASTName[] getMacroExpansions();
|
public IASTName[] getMacroExpansions();
|
||||||
public IDependencyTree getDependencyTree();
|
public IDependencyTree getDependencyTree();
|
||||||
|
public String getContainingFilename(int offset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -994,6 +994,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
return false;
|
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 {
|
protected static class _CompositeContext extends _Context {
|
||||||
|
@ -2116,6 +2125,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
protected IASTTranslationUnit rootNode;
|
protected IASTTranslationUnit rootNode;
|
||||||
|
|
||||||
|
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected static int collectContexts(int key, _Context source,
|
protected static int collectContexts(int key, _Context source,
|
||||||
|
@ -2521,4 +2532,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
tu.addBuiltinMacro( result );
|
tu.addBuiltinMacro( result );
|
||||||
return 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();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue