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.dom.ast.IASTFileLocation;
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.sourceindexer.SourceIndexer;
import org.eclipse.core.resources.IFile;
@ -73,16 +72,7 @@ public class IndexEncoderUtil {
* @return
*/
public static IASTFileLocation getFileLocation(IASTNode node) {
IASTFileLocation fileLoc = null;
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;
return node.getFileLocation();
}
public static boolean nodeInExternalHeader(IASTNode node) {

View file

@ -44,6 +44,15 @@ public interface IASTNode {
*/
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.
*

View file

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