1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 03:05:39 +02:00

Removed warning.

Added IASTTranslationUnit#getFilePath().
This commit is contained in:
John Camelon 2005-02-23 19:55:18 +00:00
parent 42141ccb94
commit 37bbc9660f
3 changed files with 411 additions and 320 deletions

View file

@ -75,4 +75,5 @@ public interface IASTTranslationUnit extends IASTNode {
public IASTVisitor getVisitor(); public IASTVisitor getVisitor();
public String getFilePath();
} }

View file

@ -9,7 +9,6 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator; import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier; import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
@ -43,47 +42,56 @@ import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeExce
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit, IRequiresLocationInformation { public class CASTTranslationUnit extends CASTNode implements
IASTTranslationUnit, IRequiresLocationInformation {
private IASTDeclaration[] decls = null;
private IASTDeclaration [] decls = null;
private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; private static final int DEFAULT_CHILDREN_LIST_SIZE = 8;
private int currentIndex = 0; private int currentIndex = 0;
//Binding // Binding
private CScope compilationUnit = null; private CScope compilationUnit = null;
private CVisitor visitor = null; private CVisitor visitor = null;
private ILocationResolver resolver; private ILocationResolver resolver;
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0]; private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0]; private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0]; private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
public void addDeclaration( IASTDeclaration d ) public void addDeclaration(IASTDeclaration d) {
{ if (decls == null) {
if( decls == null ) decls = new IASTDeclaration[DEFAULT_CHILDREN_LIST_SIZE];
{
decls = new IASTDeclaration[ DEFAULT_CHILDREN_LIST_SIZE ];
currentIndex = 0; currentIndex = 0;
} }
if( decls.length == currentIndex ) if (decls.length == currentIndex) {
{ IASTDeclaration[] old = decls;
IASTDeclaration [] old = decls; decls = new IASTDeclaration[old.length * 2];
decls = new IASTDeclaration[ old.length * 2 ]; for (int i = 0; i < old.length; ++i)
for( int i = 0; i < old.length; ++i )
decls[i] = old[i]; decls[i] = old[i];
} }
decls[ currentIndex++ ] = d; decls[currentIndex++] = d;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/ */
public IASTDeclaration[] getDeclarations() { public IASTDeclaration[] getDeclarations() {
if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; if (decls == null)
return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations(); removeNullDeclarations();
return decls; return decls;
} }
@ -93,51 +101,60 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
*/ */
private void removeNullDeclarations() { private void removeNullDeclarations() {
int nullCount = 0; int nullCount = 0;
for( int i = 0; i < decls.length; ++i ) for (int i = 0; i < decls.length; ++i)
if( decls[i] == null ) if (decls[i] == null)
++nullCount; ++nullCount;
if( nullCount == 0 ) return; if (nullCount == 0)
IASTDeclaration [] old = decls; return;
IASTDeclaration[] old = decls;
int newSize = old.length - nullCount; int newSize = old.length - nullCount;
decls = new IASTDeclaration[ newSize ]; decls = new IASTDeclaration[newSize];
for( int i = 0; i < newSize; ++i ) for (int i = 0; i < newSize; ++i)
decls[i] = old[i]; decls[i] = old[i];
currentIndex = newSize; currentIndex = newSize;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
*/ */
public IScope getScope() { public IScope getScope() {
if( compilationUnit == null ) if (compilationUnit == null)
compilationUnit = new CScope( this ); compilationUnit = new CScope(this);
return compilationUnit; return compilationUnit;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public IASTName[] getDeclarations(IBinding binding) { public IASTName[] getDeclarations(IBinding binding) {
//TODO if binding is macro, circumvent the visitor // TODO if binding is macro, circumvent the visitor
return CVisitor.getDeclarations(this, binding); return CVisitor.getDeclarations(this, binding);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding)
*/ */
public IASTName[] getReferences(IBinding binding) { public IASTName[] getReferences(IBinding binding) {
//TODO if binding is macro, circumvent the visitor // TODO if binding is macro, circumvent the visitor
return CVisitor.getReferences( this, binding ); return CVisitor.getReferences(this, binding);
} }
/*
* (non-Javadoc)
/* (non-Javadoc) *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int,
* int)
*/ */
public IASTNodeLocation[] getLocationInfo(int offset, int length) { public IASTNodeLocation[] getLocationInfo(int offset, int length) {
if( resolver == null ) return EMPTY_PREPROCESSOR_LOCATION_ARRAY; if (resolver == null)
return resolver.getLocations(offset,length); return EMPTY_PREPROCESSOR_LOCATION_ARRAY;
return resolver.getLocations(offset, length);
} }
private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction { private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction {
@ -156,7 +173,9 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
} }
IASTNode foundNode = null; IASTNode foundNode = null;
int offset = 0; int offset = 0;
int length = 0; int length = 0;
/** /**
@ -171,96 +190,119 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
if (foundNode != null) if (foundNode != null)
return PROCESS_ABORT; return PROCESS_ABORT;
if (node instanceof ASTNode && if (node instanceof ASTNode
((ASTNode)node).getOffset() == offset && && ((ASTNode) node).getOffset() == offset
((ASTNode)node).getLength() == length) { && ((ASTNode) node).getLength() == length) {
foundNode = node; foundNode = node;
return PROCESS_ABORT; return PROCESS_ABORT;
} }
// skip the rest of this node if the selection is outside of its bounds // skip the rest of this node if the selection is outside of its
if (node instanceof ASTNode && // bounds
offset > ((ASTNode)node).getOffset() + ((ASTNode)node).getLength()) if (node instanceof ASTNode
&& offset > ((ASTNode) node).getOffset()
+ ((ASTNode) node).getLength())
return PROCESS_SKIP; return PROCESS_SKIP;
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
*/ */
public int processDeclaration(IASTDeclaration declaration) { public int processDeclaration(IASTDeclaration declaration) {
// use declarations to determine if the search has gone past the offset (i.e. don't know the order the visitor visits the nodes) // use declarations to determine if the search has gone past the
if (declaration instanceof ASTNode && ((ASTNode)declaration).getOffset() > offset) // offset (i.e. don't know the order the visitor visits the nodes)
if (declaration instanceof ASTNode
&& ((ASTNode) declaration).getOffset() > offset)
return PROCESS_ABORT; return PROCESS_ABORT;
return processNode(declaration); return processNode(declaration);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
*/ */
public int processDeclarator(IASTDeclarator declarator) { public int processDeclarator(IASTDeclarator declarator) {
int ret = processNode(declarator); int ret = processNode(declarator);
IASTPointerOperator[] ops = declarator.getPointerOperators(); IASTPointerOperator[] ops = declarator.getPointerOperators();
for(int i=0; i<ops.length; i++) for (int i = 0; i < ops.length; i++)
processNode(ops[i]); processNode(ops[i]);
if (declarator instanceof IASTArrayDeclarator) { if (declarator instanceof IASTArrayDeclarator) {
IASTArrayModifier[] mods = ((IASTArrayDeclarator)declarator).getArrayModifiers(); IASTArrayModifier[] mods = ((IASTArrayDeclarator) declarator)
for(int i=0; i<mods.length; i++) .getArrayModifiers();
for (int i = 0; i < mods.length; i++)
processNode(mods[i]); processNode(mods[i]);
} }
return ret; return ret;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
*/ */
public int processDesignator(ICASTDesignator designator) { public int processDesignator(ICASTDesignator designator) {
return processNode(designator); return processNode(designator);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
*/ */
public int processDeclSpecifier(IASTDeclSpecifier declSpec) { public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
return processNode(declSpec); return processNode(declSpec);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
*/ */
public int processEnumerator(IASTEnumerator enumerator) { public int processEnumerator(IASTEnumerator enumerator) {
return processNode((IASTNode)enumerator); return processNode((IASTNode) enumerator);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
*/ */
public int processExpression(IASTExpression expression) { public int processExpression(IASTExpression expression) {
return processNode(expression); return processNode(expression);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
*/ */
public int processInitializer(IASTInitializer initializer) { public int processInitializer(IASTInitializer initializer) {
return processNode(initializer); return processNode(initializer);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
public int processName(IASTName name) { public int processName(IASTName name) {
if ( name.toString() != null ) if (name.toString() != null)
return processNode(name); return processNode(name);
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
*/ */
public int processParameterDeclaration( public int processParameterDeclaration(
@ -268,14 +310,18 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
return processNode(parameterDeclaration); return processNode(parameterDeclaration);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
*/ */
public int processStatement(IASTStatement statement) { public int processStatement(IASTStatement statement) {
return processNode(statement); return processNode(statement);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
*/ */
public int processTypeId(IASTTypeId typeId) { public int processTypeId(IASTTypeId typeId) {
@ -287,19 +333,24 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
} }
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
*/ */
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) { public IASTNode selectNodeForLocation(String path, int realOffset,
int realLength) {
IASTNode node = null; IASTNode node = null;
try { try {
node = resolver.getPreprocessorNode(path, realOffset, realLength); node = resolver.getPreprocessorNode(path, realOffset, realLength);
} catch (InvalidPreprocessorNodeException ipne) { } catch (InvalidPreprocessorNodeException ipne) {
// extract global offset from the exception, use it to get the node from the AST if it's valid // extract global offset from the exception, use it to get the node
// from the AST if it's valid
int globalOffset = ipne.getGlobalOffset(); int globalOffset = ipne.getGlobalOffset();
if (globalOffset >= 0) { if (globalOffset >= 0) {
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(globalOffset, realLength); CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(
globalOffset, realLength);
getVisitor().visitTranslationUnit(nodeFinder); getVisitor().visitTranslationUnit(nodeFinder);
node = nodeFinder.getNode(); node = nodeFinder.getNode();
} }
@ -308,101 +359,130 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
return node; return node;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
*/ */
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() { public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; if (resolver == null)
IASTPreprocessorMacroDefinition [] result = resolver.getMacroDefinitions(); return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); IASTPreprocessorMacroDefinition[] result = resolver
.getMacroDefinitions();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
*/ */
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() { public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; if (resolver == null)
IASTPreprocessorIncludeStatement [] result = resolver.getIncludeDirectives(); return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); IASTPreprocessorIncludeStatement[] result = resolver
.getIncludeDirectives();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
/** /**
* @param result * @param result
* @param preprocessor_statement * @param preprocessor_statement
*/ */
protected void setParentRelationship(IASTNode[] result, ASTNodeProperty property ) { protected void setParentRelationship(IASTNode[] result,
for( int i = 0; i < result.length; ++i ) ASTNodeProperty property) {
{ for (int i = 0; i < result.length; ++i) {
result[i].setParent( this ); result[i].setParent(this);
result[i].setPropertyInParent( property ); result[i].setPropertyInParent(property);
} }
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
*/ */
public IASTPreprocessorStatement[] getAllPreprocessorStatements() { public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
if( resolver == null ) return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; if (resolver == null)
IASTPreprocessorStatement [] result = resolver.getAllPreprocessorStatements(); return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); IASTPreprocessorStatement[] result = resolver
.getAllPreprocessorStatements();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver) * @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver)
*/ */
public void setLocationResolver(ILocationResolver resolver) { public void setLocationResolver(ILocationResolver resolver) {
this.resolver = resolver; this.resolver = resolver;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see java.lang.Object#finalize() * @see java.lang.Object#finalize()
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if( resolver != null ) resolver.cleanup(); if (resolver != null)
resolver.cleanup();
super.finalize(); super.finalize();
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
*/ */
public IASTProblem[] getPreprocesorProblems() { public IASTProblem[] getPreprocesorProblems() {
if( resolver == null ) return EMPTY_PROBLEM_ARRAY; if (resolver == null)
IASTProblem [] result = resolver.getScannerProblems(); return EMPTY_PROBLEM_ARRAY;
for( int i = 0; i < result.length; ++i ) IASTProblem[] result = resolver.getScannerProblems();
{ for (int i = 0; i < result.length; ++i) {
IASTProblem p = result[i]; IASTProblem p = result[i];
p.setParent( this ); p.setParent(this);
p.setPropertyInParent( IASTTranslationUnit.SCANNER_PROBLEM ); p.setPropertyInParent(IASTTranslationUnit.SCANNER_PROBLEM);
} }
return result; return result;
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[]) * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
*/ */
public String getUnpreprocessedSignature(IASTNodeLocation[] locations) { public String getUnpreprocessedSignature(IASTNodeLocation[] locations) {
if( resolver == null ) return EMPTY_STRING; if (resolver == null)
return new String( resolver.getUnpreprocessedSignature(locations) ); return EMPTY_STRING;
return new String(resolver.getUnpreprocessedSignature(locations));
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getVisitor() * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getVisitor()
*/ */
public IASTVisitor getVisitor() { public IASTVisitor getVisitor() {
if( visitor == null ) if (visitor == null)
visitor = new CVisitor( this ); visitor = new CVisitor(this);
return visitor; return visitor;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
*/
public String getFilePath() {
if (resolver == null)
return EMPTY_STRING;
return new String(resolver.getTranslationUnitPath());
}
} }

View file

@ -67,7 +67,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
private ILocationResolver resolver; private ILocationResolver resolver;
private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0];
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
@ -451,4 +450,15 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
visitor = new CPPVisitor( this ); visitor = new CPPVisitor( this );
return visitor; return visitor;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
*/
public String getFilePath() {
if (resolver == null)
return EMPTY_STRING;
return new String(resolver.getTranslationUnitPath());
}
} }