1
0
Fork 0
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:
John Camelon 2005-04-13 17:43:40 +00:00
parent c7b5a7da63
commit 7a6f934182
8 changed files with 51 additions and 2 deletions

View file

@ -43,7 +43,14 @@ public interface IASTNode {
* @return <code>IASTNodeLocation []</code>
*/
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.
*

View file

@ -161,6 +161,8 @@ public interface IASTTranslationUnit extends IASTNode {
}
public IDependencyTree getDependencyTree();
public String getContainingFilename(int offset);

View file

@ -129,7 +129,12 @@ public class CodeReader {
}
public String toString() {
return new String( filename );
return getPath();
}
public String getPath()
{
return new String( filename );
}
}

View file

@ -69,4 +69,8 @@ public abstract class ASTNode implements IASTNode {
public String getRawSignature() {
return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() );
}
public String getContainingFilename() {
return getTranslationUnit().getContainingFilename( offset );
}
}

View file

@ -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 );
}
}

View file

@ -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 );
}
}

View file

@ -49,5 +49,6 @@ public interface ILocationResolver {
public IASTName[] getDeclarations(IMacroBinding binding);
public IASTName[] getMacroExpansions();
public IDependencyTree getDependencyTree();
public String getContainingFilename(int offset);
}

View file

@ -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();
}
}