1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added IASTNode#getFileLocation().

Updated DOM Indexer to use it.
This commit is contained in:
John Camelon 2005-05-30 19:32:59 +00:00
parent 2b8a395550
commit 1786169b2b
3 changed files with 49 additions and 38 deletions

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.index.domsourceindexer;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry; import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer; import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -73,16 +72,7 @@ public class IndexEncoderUtil {
* @return * @return
*/ */
public static IASTFileLocation getFileLocation(IASTNode node) { public static IASTFileLocation getFileLocation(IASTNode node) {
IASTFileLocation fileLoc = null; return node.getFileLocation();
IASTNodeLocation[] locs = node.getNodeLocations();
if (locs.length == 1 && locs[0] instanceof IASTFileLocation) {
fileLoc = (IASTFileLocation) locs[0];
}
else if (locs.length > 0) {
fileLoc = node.getTranslationUnit().flattenLocationsToFile(locs);
}
return fileLoc;
} }
public static boolean nodeInExternalHeader(IASTNode node) { public static boolean nodeInExternalHeader(IASTNode node) {

View file

@ -44,6 +44,15 @@ public interface IASTNode {
*/ */
public IASTNodeLocation[] getNodeLocations(); public IASTNodeLocation[] getNodeLocations();
/**
* Get the location of the node as a file.
*
* @return <code>IASTFileLocation</code>
*/
public IASTFileLocation getFileLocation();
/** /**
* Lightweight check for understanding what file we are in. * Lightweight check for understanding what file we are in.
* *

View file

@ -9,6 +9,7 @@
* IBM Rational Software - Initial API and implementation */ * IBM Rational Software - Initial API and implementation */
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
@ -18,7 +19,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
public abstract class ASTNode implements IASTNode { public abstract class ASTNode implements IASTNode {
private int length; private int length;
private int offset; private int offset;
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0]; private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
public int getOffset() { public int getOffset() {
@ -29,48 +32,57 @@ public abstract class ASTNode implements IASTNode {
return length; return length;
} }
public void setOffset( int offset ) public void setOffset(int offset) {
{
this.offset = offset; this.offset = offset;
this.locations = null; this.locations = null;
} }
public void setLength( int length ) public void setLength(int length) {
{
this.length = length; this.length = length;
this.locations = null; this.locations = null;
} }
public void setOffsetAndLength(int offset, int length) { public void setOffsetAndLength(int offset, int length) {
this.offset = offset; this.offset = offset;
this.length = length; this.length = length;
this.locations = null; this.locations = null;
} }
public void setOffsetAndLength( ASTNode node ) public void setOffsetAndLength(ASTNode node) {
{ setOffsetAndLength(node.getOffset(), node.getLength());
setOffsetAndLength( node.getOffset(), node.getLength() );
} }
private IASTNodeLocation [] locations = null; private IASTNodeLocation[] locations = null;
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations() * @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
*/ */
public IASTNodeLocation[] getNodeLocations() { public IASTNodeLocation[] getNodeLocations() {
if( locations != null ) return locations; if (locations != null)
if( length == 0 ) return EMPTY_LOCATION_ARRAY; return locations;
locations = getTranslationUnit().getLocationInfo( offset, length ); if (length == 0)
return EMPTY_LOCATION_ARRAY;
locations = getTranslationUnit().getLocationInfo(offset, length);
return locations; return locations;
} }
/* (non-Javadoc) /*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getRawSignature() * (non-Javadoc)
*/ *
public String getRawSignature() { * @see org.eclipse.cdt.core.dom.ast.IASTNode#getRawSignature()
return getTranslationUnit().getUnpreprocessedSignature( getNodeLocations() ); */
} public String getRawSignature() {
return getTranslationUnit().getUnpreprocessedSignature(
public String getContainingFilename() { getNodeLocations());
return getTranslationUnit().getContainingFilename( offset ); }
}
public String getContainingFilename() {
return getTranslationUnit().getContainingFilename(offset);
}
public IASTFileLocation getFileLocation() {
return getTranslationUnit().flattenLocationsToFile( getNodeLocations() );
}
} }