Package com.google.common.css
Class SourceCodeLocation
- java.lang.Object
-
- com.google.common.css.SourceCodeLocation
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<SourceCodeLocation>
public class SourceCodeLocation extends java.lang.Object implements java.lang.Comparable<SourceCodeLocation>, java.io.Serializable
A location in source code. A location is a sequence of adjacent characters that usually represent a token or a larger language construct.Error messages represent the most common use of this class, as an error message usually relates to a source code location. The location related to some messages might not be known; this class has a special value that represents an "unknown" location.
Character sequences this class points to can have 0 length. If that is the case, the actual location is that "point" between two source code characters. This usually means that something happens from that point onwards, or that an error has been detected at that point but there is no information regarding the actual token that caused the error.
Instances of this class are immutable.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSourceCodeLocation.SourceCodePointThis describes a point in a string.
-
Constructor Summary
Constructors Constructor Description SourceCodeLocation(SourceCode sourceCode, int beginCharacterIndex, int beginLineNumber, int beginIndexInLine, int endCharacterIndex, int endLineNumber, int endIndexInLine)SourceCodeLocation(SourceCode sourceCode, SourceCodeLocation.SourceCodePoint begin, SourceCodeLocation.SourceCodePoint end)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(SourceCodeLocation o)Comparison and ordering of locations for source code in different input files is supported because we don't always preserve locations during AST mutations and yet we still want to be able to sort error reports, doing the best job we can for the errors that have known locations.booleanequals(java.lang.Object o)SourceCodeLocation.SourceCodePointgetBegin()intgetBeginCharacterIndex()intgetBeginIndexInLine()The index of the column that contains the first character of the node.intgetBeginLineNumber()The index of the line that contains the first character of the node.intgetCharacterIndex()SourceCodeLocation.SourceCodePointgetEnd()intgetEndCharacterIndex()intgetEndIndexInLine()The index of the column that comes after the last character of the node.intgetEndLineNumber()The index of the line that contains the last character of the node.intgetIndexInLine()intgetLineNumber()SourceCodegetSourceCode()static SourceCodeLocationgetUnknownLocation()Returns an unknown location.inthashCode()booleanisUnknown()static SourceCodeLocationmerge(SourceCodeLocation beginLocation, SourceCodeLocation endLocation)Returns a new SourceCodeLocation which covers everything between the beginning of the first location and the end of the second location.static SourceCodeLocationmerge(java.lang.Iterable<? extends Locatable> locations)Merges the locations of all of the given locations.static SourceCodeLocationmergeAll(java.lang.Iterable<SourceCodeLocation> locations)Merges the locations of all of the given locations.java.lang.StringtoString()
-
-
-
Constructor Detail
-
SourceCodeLocation
public SourceCodeLocation(SourceCode sourceCode, SourceCodeLocation.SourceCodePoint begin, SourceCodeLocation.SourceCodePoint end)
-
SourceCodeLocation
public SourceCodeLocation(SourceCode sourceCode, int beginCharacterIndex, int beginLineNumber, int beginIndexInLine, int endCharacterIndex, int endLineNumber, int endIndexInLine)
-
-
Method Detail
-
getUnknownLocation
public static SourceCodeLocation getUnknownLocation()
Returns an unknown location.
-
merge
public static SourceCodeLocation merge(SourceCodeLocation beginLocation, SourceCodeLocation endLocation)
Returns a new SourceCodeLocation which covers everything between the beginning of the first location and the end of the second location.
-
mergeAll
public static SourceCodeLocation mergeAll(java.lang.Iterable<SourceCodeLocation> locations)
Merges the locations of all of the given locations. If the locations spanSourceCodes, only the locations in the firstSourceCodeare used. If locations are out of order, the bounding locations are used.
-
merge
public static SourceCodeLocation merge(java.lang.Iterable<? extends Locatable> locations)
Merges the locations of all of the given locations. If the locations spanSourceCodes, only the locations in the firstSourceCodeare used.
-
getSourceCode
public SourceCode getSourceCode()
-
isUnknown
public boolean isUnknown()
-
getBeginCharacterIndex
public int getBeginCharacterIndex()
-
getBeginLineNumber
public int getBeginLineNumber()
The index of the line that contains the first character of the node. Indexes start at 1; 0 means the location is not known.
-
getBeginIndexInLine
public int getBeginIndexInLine()
The index of the column that contains the first character of the node. Indexes start at 1; 0 means the location is not known.
-
getEndCharacterIndex
public int getEndCharacterIndex()
-
getEndLineNumber
public int getEndLineNumber()
The index of the line that contains the last character of the node. Indexes start at 1; 0 means the location is not known.
-
getEndIndexInLine
public int getEndIndexInLine()
The index of the column that comes after the last character of the node. Indexes start at 1; 0 means the location is not known.
-
getCharacterIndex
public int getCharacterIndex()
-
getLineNumber
public int getLineNumber()
-
getIndexInLine
public int getIndexInLine()
-
getBegin
public SourceCodeLocation.SourceCodePoint getBegin()
-
getEnd
public SourceCodeLocation.SourceCodePoint getEnd()
-
equals
public boolean equals(@Nullable java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public int compareTo(SourceCodeLocation o)
Comparison and ordering of locations for source code in different input files is supported because we don't always preserve locations during AST mutations and yet we still want to be able to sort error reports, doing the best job we can for the errors that have known locations. For the semantics of this method, seeComparable.compareTo(Object).- Specified by:
compareToin interfacejava.lang.Comparable<SourceCodeLocation>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-