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,123 +42,143 @@ 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;
//Binding private int currentIndex = 0;
private CScope compilationUnit = null;
private CVisitor visitor = null;
private ILocationResolver resolver;
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 IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[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 String EMPTY_STRING = ""; //$NON-NLS-1$
public void addDeclaration( IASTDeclaration d ) // Binding
{ private CScope compilationUnit = null;
if( decls == null )
{
decls = new IASTDeclaration[ DEFAULT_CHILDREN_LIST_SIZE ];
currentIndex = 0;
}
if( decls.length == currentIndex )
{
IASTDeclaration [] old = decls;
decls = new IASTDeclaration[ old.length * 2 ];
for( int i = 0; i < old.length; ++i )
decls[i] = old[i];
}
decls[ currentIndex++ ] = d;
}
private CVisitor visitor = null;
/* (non-Javadoc) private ILocationResolver resolver;
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/
public IASTDeclaration[] getDeclarations() {
if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return decls;
}
/** private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
* @param decls2
*/
private void removeNullDeclarations() {
int nullCount = 0;
for( int i = 0; i < decls.length; ++i )
if( decls[i] == null )
++nullCount;
if( nullCount == 0 ) return;
IASTDeclaration [] old = decls;
int newSize = old.length - nullCount;
decls = new IASTDeclaration[ newSize ];
for( int i = 0; i < newSize; ++i )
decls[i] = old[i];
currentIndex = newSize;
}
/* (non-Javadoc) private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
*/
public IScope getScope() {
if( compilationUnit == null )
compilationUnit = new CScope( this );
return compilationUnit;
}
/* (non-Javadoc) 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 IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
public void addDeclaration(IASTDeclaration d) {
if (decls == null) {
decls = new IASTDeclaration[DEFAULT_CHILDREN_LIST_SIZE];
currentIndex = 0;
}
if (decls.length == currentIndex) {
IASTDeclaration[] old = decls;
decls = new IASTDeclaration[old.length * 2];
for (int i = 0; i < old.length; ++i)
decls[i] = old[i];
}
decls[currentIndex++] = d;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations()
*/
public IASTDeclaration[] getDeclarations() {
if (decls == null)
return IASTDeclaration.EMPTY_DECLARATION_ARRAY;
removeNullDeclarations();
return decls;
}
/**
* @param decls2
*/
private void removeNullDeclarations() {
int nullCount = 0;
for (int i = 0; i < decls.length; ++i)
if (decls[i] == null)
++nullCount;
if (nullCount == 0)
return;
IASTDeclaration[] old = decls;
int newSize = old.length - nullCount;
decls = new IASTDeclaration[newSize];
for (int i = 0; i < newSize; ++i)
decls[i] = old[i];
currentIndex = newSize;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope()
*/
public IScope getScope() {
if (compilationUnit == null)
compilationUnit = new CScope(this);
return compilationUnit;
}
/*
* (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)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int,
* int)
*/
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
if (resolver == null)
return EMPTY_PREPROCESSOR_LOCATION_ARRAY;
return resolver.getLocations(offset, length);
}
private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction {
{
processNames = true;
processDeclarations = true;
processInitializers = true;
processParameterDeclarations = true;
processDeclarators = true;
processDeclSpecifiers = true;
processDesignators = true;
processExpressions = true;
processStatements = true;
processTypeIds = true;
processEnumerators = true;
}
/* (non-Javadoc) IASTNode foundNode = null;
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int)
*/
public IASTNodeLocation[] getLocationInfo(int offset, int length) {
if( resolver == null ) return EMPTY_PREPROCESSOR_LOCATION_ARRAY;
return resolver.getLocations(offset,length);
}
private class CFindNodeForOffsetAction extends CVisitor.CBaseVisitorAction { int offset = 0;
{
processNames = true;
processDeclarations = true;
processInitializers = true;
processParameterDeclarations = true;
processDeclarators = true;
processDeclSpecifiers = true;
processDesignators = true;
processExpressions = true;
processStatements = true;
processTypeIds = true;
processEnumerators = true;
}
IASTNode foundNode = null; int length = 0;
int offset = 0;
int length = 0;
/** /**
* *
*/ */
public CFindNodeForOffsetAction(int offset, int length) { public CFindNodeForOffsetAction(int offset, int length) {
@ -167,242 +186,303 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
this.length = length; this.length = length;
} }
public int processNode(IASTNode node) { public int processNode(IASTNode node) {
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
return PROCESS_SKIP; && offset > ((ASTNode) node).getOffset()
+ ((ASTNode) node).getLength())
return PROCESS_SKIP;
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) * (non-Javadoc)
*/ *
public int processDeclaration(IASTDeclaration declaration) { * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
// use declarations to determine if the search has gone past the offset (i.e. don't know the order the visitor visits the nodes) */
if (declaration instanceof ASTNode && ((ASTNode)declaration).getOffset() > offset) public int processDeclaration(IASTDeclaration declaration) {
return PROCESS_ABORT; // use declarations to determine if the search has gone past the
// 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 processNode(declaration); return processNode(declaration);
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) * (non-Javadoc)
*/ *
public int processDeclarator(IASTDeclarator declarator) { * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
int ret = processNode(declarator); */
public int processDeclarator(IASTDeclarator 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();
processNode(mods[i]); for (int i = 0; i < mods.length; i++)
} processNode(mods[i]);
}
return ret; return ret;
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) * (non-Javadoc)
*/ *
public int processDesignator(ICASTDesignator designator) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
return processNode(designator); */
} public int processDesignator(ICASTDesignator designator) {
return processNode(designator);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) * (non-Javadoc)
*/ *
public int processDeclSpecifier(IASTDeclSpecifier declSpec) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
return processNode(declSpec); */
} public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
return processNode(declSpec);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) * (non-Javadoc)
*/ *
public int processEnumerator(IASTEnumerator enumerator) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
return processNode((IASTNode)enumerator); */
} public int processEnumerator(IASTEnumerator enumerator) {
return processNode((IASTNode) enumerator);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) * (non-Javadoc)
*/ *
public int processExpression(IASTExpression expression) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
return processNode(expression); */
} public int processExpression(IASTExpression expression) {
return processNode(expression);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) * (non-Javadoc)
*/ *
public int processInitializer(IASTInitializer initializer) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
return processNode(initializer); */
} public int processInitializer(IASTInitializer initializer) {
return processNode(initializer);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) * (non-Javadoc)
*/ *
public int processName(IASTName name) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
if ( name.toString() != null ) */
return processNode(name); public int processName(IASTName name) {
return PROCESS_CONTINUE; if (name.toString() != null)
} return processNode(name);
return PROCESS_CONTINUE;
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) * (non-Javadoc)
*/ *
public int processParameterDeclaration( * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
IASTParameterDeclaration parameterDeclaration) { */
return processNode(parameterDeclaration); public int processParameterDeclaration(
} IASTParameterDeclaration parameterDeclaration) {
return processNode(parameterDeclaration);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) * (non-Javadoc)
*/ *
public int processStatement(IASTStatement statement) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
return processNode(statement); */
} public int processStatement(IASTStatement statement) {
return processNode(statement);
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) * (non-Javadoc)
*/ *
public int processTypeId(IASTTypeId typeId) { * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
return processNode(typeId); */
} public int processTypeId(IASTTypeId typeId) {
return processNode(typeId);
}
public IASTNode getNode() { public IASTNode getNode() {
return foundNode; return foundNode;
} }
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation) * (non-Javadoc)
*/ *
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) { * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
IASTNode node = null; */
public IASTNode selectNodeForLocation(String path, int realOffset,
int realLength) {
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
int globalOffset = ipne.getGlobalOffset(); // from the AST if it's valid
if (globalOffset >= 0) { int globalOffset = ipne.getGlobalOffset();
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(globalOffset, realLength); if (globalOffset >= 0) {
getVisitor().visitTranslationUnit(nodeFinder); CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(
node = nodeFinder.getNode(); globalOffset, realLength);
} getVisitor().visitTranslationUnit(nodeFinder);
} node = nodeFinder.getNode();
}
}
return node; return node;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions()
*/
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
if (resolver == null)
return EMPTY_PREPROCESSOR_MACRODEF_ARRAY;
IASTPreprocessorMacroDefinition[] result = resolver
.getMacroDefinitions();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result;
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() * (non-Javadoc)
*/ *
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() { * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives()
if( resolver == null ) return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; */
IASTPreprocessorMacroDefinition [] result = resolver.getMacroDefinitions(); public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); if (resolver == null)
return result; return EMPTY_PREPROCESSOR_INCLUSION_ARRAY;
} IASTPreprocessorIncludeStatement[] result = resolver
.getIncludeDirectives();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result;
}
/**
* @param result
* @param preprocessor_statement
*/
protected void setParentRelationship(IASTNode[] result,
ASTNodeProperty property) {
for (int i = 0; i < result.length; ++i) {
result[i].setParent(this);
result[i].setPropertyInParent(property);
}
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives() * (non-Javadoc)
*/ *
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() { * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements()
if( resolver == null ) return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; */
IASTPreprocessorIncludeStatement [] result = resolver.getIncludeDirectives(); public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); if (resolver == null)
return result; return EMPTY_PREPROCESSOR_STATEMENT_ARRAY;
} IASTPreprocessorStatement[] result = resolver
.getAllPreprocessorStatements();
setParentRelationship(result,
IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver)
*/
public void setLocationResolver(ILocationResolver resolver) {
this.resolver = resolver;
}
/** /*
* @param result * (non-Javadoc)
* @param preprocessor_statement *
*/ * @see java.lang.Object#finalize()
protected void setParentRelationship(IASTNode[] result, ASTNodeProperty property ) { */
for( int i = 0; i < result.length; ++i ) protected void finalize() throws Throwable {
{ if (resolver != null)
result[i].setParent( this ); resolver.cleanup();
result[i].setPropertyInParent( property ); super.finalize();
} }
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
*/
public IASTProblem[] getPreprocesorProblems() {
if (resolver == null)
return EMPTY_PROBLEM_ARRAY;
IASTProblem[] result = resolver.getScannerProblems();
for (int i = 0; i < result.length; ++i) {
IASTProblem p = result[i];
p.setParent(this);
p.setPropertyInParent(IASTTranslationUnit.SCANNER_PROBLEM);
}
return result;
}
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements() * (non-Javadoc)
*/ *
public IASTPreprocessorStatement[] getAllPreprocessorStatements() { * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
if( resolver == null ) return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; */
IASTPreprocessorStatement [] result = resolver.getAllPreprocessorStatements(); public String getUnpreprocessedSignature(IASTNodeLocation[] locations) {
setParentRelationship( result, IASTTranslationUnit.PREPROCESSOR_STATEMENT ); if (resolver == null)
return result; return EMPTY_STRING;
} return new String(resolver.getUnpreprocessedSignature(locations));
}
/*
/* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver) *
*/
public void setLocationResolver(ILocationResolver resolver) {
this.resolver = resolver;
}
/* (non-Javadoc)
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
if( resolver != null ) resolver.cleanup();
super.finalize();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems()
*/
public IASTProblem[] getPreprocesorProblems() {
if( resolver == null ) return EMPTY_PROBLEM_ARRAY;
IASTProblem [] result = resolver.getScannerProblems();
for( int i = 0; i < result.length; ++i )
{
IASTProblem p = result[i];
p.setParent( this );
p.setPropertyInParent( IASTTranslationUnit.SCANNER_PROBLEM );
}
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
*/
public String getUnpreprocessedSignature(IASTNodeLocation[] locations) {
if( resolver == null ) return EMPTY_STRING;
return new String( resolver.getUnpreprocessedSignature(locations) );
}
/* (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());
}
} }