Class SourcePositionImpl
java.lang.Object
spoon.support.reflect.cu.position.SourcePositionImpl
- All Implemented Interfaces:
Serializable
,SourcePosition
- Direct Known Subclasses:
CompoundSourcePositionImpl
This immutable class represents the position of a Java program element in a source
file.
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from interface spoon.reflect.cu.SourcePosition
NOPOSITION
-
Constructor Summary
ConstructorDescriptionSourcePositionImpl(CompilationUnit compilationUnit, int sourceStart, int sourceEnd, int[] lineSeparatorPositions)
-
Method Summary
Modifier and TypeMethodDescriptionprotected static void
checkArgsAreAscending(int... values)
fails when `values` are not sorted ascending It is used to check whether start/end values of SourcePosition are consistentboolean
int
Gets the column in the source file (1 indexed).Gets the compilation unit for this position.int
Gets the end column in the source file (1 indexed).int
Gets the end line in the source file (1 indexed).getFile()
Gets the file for this position.protected String
getFragment(int start, int end)
int
getLine()
Gets the line in the source file (1 indexed).Helper for debugging purposes.int
Gets the index at which the position ends in the source file.int
Gets the index at which the position starts in the source file.int
hashCode()
boolean
protected int
searchColumnNumber(int position)
Search the column numberprotected int
searchLineNumber(int position)
Search the line number corresponding to a specific positiontoString()
Returns a string representation of this position in the form "sourcefile:line", or "sourcefile" if no line number is available.
-
Constructor Details
-
SourcePositionImpl
public SourcePositionImpl(CompilationUnit compilationUnit, int sourceStart, int sourceEnd, int[] lineSeparatorPositions)
-
-
Method Details
-
searchLineNumber
protected int searchLineNumber(int position)Search the line number corresponding to a specific position -
searchColumnNumber
protected int searchColumnNumber(int position)Search the column number -
isValidPosition
public boolean isValidPosition()- Specified by:
isValidPosition
in interfaceSourcePosition
- Returns:
- true if this instance holds start/end indexes of related sources. false if they are unknown
-
getColumn
public int getColumn()Description copied from interface:SourcePosition
Gets the column in the source file (1 indexed). This method is slow because it has to calculate the column number depending onEnvironment.getTabulationSize()
andCtCompilationUnit.getOriginalSourceCode()
. PreferSourcePosition.getSourceStart()
.- Specified by:
getColumn
in interfaceSourcePosition
-
getEndColumn
public int getEndColumn()Description copied from interface:SourcePosition
Gets the end column in the source file (1 indexed). This method is slow because it has to calculate the column number depending onEnvironment.getTabulationSize()
andCtCompilationUnit.getOriginalSourceCode()
. PreferSourcePosition.getSourceEnd()
.- Specified by:
getEndColumn
in interfaceSourcePosition
-
getFile
Description copied from interface:SourcePosition
Gets the file for this position.- Specified by:
getFile
in interfaceSourcePosition
-
getLine
public int getLine()Description copied from interface:SourcePosition
Gets the line in the source file (1 indexed). Prefer usingSourcePosition.getSourceStart()
}. For CtNamedElement the line is where the name is declared.- Specified by:
getLine
in interfaceSourcePosition
-
getEndLine
public int getEndLine()Description copied from interface:SourcePosition
Gets the end line in the source file (1 indexed). Prefer usingSourcePosition.getSourceEnd()
}.- Specified by:
getEndLine
in interfaceSourcePosition
-
getSourceEnd
public int getSourceEnd()Description copied from interface:SourcePosition
Gets the index at which the position ends in the source file. Heavily used for the sniper mode.- Specified by:
getSourceEnd
in interfaceSourcePosition
-
getSourceStart
public int getSourceStart()Description copied from interface:SourcePosition
Gets the index at which the position starts in the source file.- Specified by:
getSourceStart
in interfaceSourcePosition
-
toString
Returns a string representation of this position in the form "sourcefile:line", or "sourcefile" if no line number is available.- Specified by:
toString
in interfaceSourcePosition
- Overrides:
toString
in classObject
-
equals
-
hashCode
public int hashCode() -
getCompilationUnit
Description copied from interface:SourcePosition
Gets the compilation unit for this position.- Specified by:
getCompilationUnit
in interfaceSourcePosition
-
getSourceDetails
Helper for debugging purposes. Displays |startIndex; endIndex|sourceCode| of thisSourcePosition
If this instance isDeclarationSourcePosition
orBodyHolderSourcePosition
Then details about name, modifiers and body are included in resulting string too- Returns:
- details about source code of this
SourcePosition
-
getFragment
-
checkArgsAreAscending
protected static void checkArgsAreAscending(int... values)fails when `values` are not sorted ascending It is used to check whether start/end values of SourcePosition are consistent
-