Class SourceCodeLocation

java.lang.Object
com.google.common.css.SourceCodeLocation
All Implemented Interfaces:
Serializable, Comparable<SourceCodeLocation>

public class SourceCodeLocation extends Object implements Comparable<SourceCodeLocation>, 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:
  • Constructor Details

  • Method Details

    • 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(Iterable<SourceCodeLocation> locations)
      Merges the locations of all of the given locations. If the locations span SourceCodes, only the locations in the first SourceCode are used. If locations are out of order, the bounding locations are used.
    • merge

      public static SourceCodeLocation merge(Iterable<? extends Locatable> locations)
      Merges the locations of all of the given locations. If the locations span SourceCodes, only the locations in the first SourceCode are 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

    • getEnd

    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class 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, see Comparable.compareTo(Object).
      Specified by:
      compareTo in interface Comparable<SourceCodeLocation>
    • toString

      public String toString()
      Overrides:
      toString in class Object