Class 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
    • Method Detail

      • getUnknownLocation

        public static SourceCodeLocation getUnknownLocation()
        Returns an unknown location.
      • mergeAll

        public static SourceCodeLocation mergeAll​(java.lang.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​(java.lang.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()
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object