Class LineAndColumnTracker

java.lang.Object
org.codehaus.commons.compiler.util.LineAndColumnTracker

public abstract class LineAndColumnTracker extends Object
Keeps track of "line numbers" and "column numbers" while a char stream is being processed. Line breaks are identified as defined by the \R pattern of Pattern. Initially, line number and column number are 1.

This class has no public constructors, instead, use one of the static "factory methods".

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default "tab width".
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    consume(char c)
    Consumes the next character of the stream.
     
    abstract int
    Returns the column number of the previously consumed character; 1 after a line separator character has been consumed, 2 after the first non-line-separator character, and so forth.
    abstract int
    Returns the line number of the previously consumed character (starting at 1).
    abstract void
    Resets the current line number to 1 and the current column number to one.
    abstract void
    setColumnNumber(int columnNumber)
    Sets the "current column number" to the given value.
    abstract void
    setLineNumber(int lineNumber)
    Sets the "current line number" to the given value.
    abstract void
    setTabWidth(int tabWidth)
    Reconfigures the TAB width.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • LineAndColumnTracker

      public LineAndColumnTracker()
  • Method Details

    • setTabWidth

      public abstract void setTabWidth(int tabWidth)
      Reconfigures the TAB width. Value 1 will treat TAB characters just like any other (non-line-break) character. The default tab with is DEFAULT_TAB_WIDTH (8).
    • consume

      public abstract void consume(char c)
      Consumes the next character of the stream.
    • getLineNumber

      public abstract int getLineNumber()
      Returns the line number of the previously consumed character (starting at 1). Line separator characters belong to the "next" line.
    • setLineNumber

      public abstract void setLineNumber(int lineNumber)
      Sets the "current line number" to the given value.
    • getColumnNumber

      public abstract int getColumnNumber()
      Returns the column number of the previously consumed character; 1 after a line separator character has been consumed, 2 after the first non-line-separator character, and so forth.
    • setColumnNumber

      public abstract void setColumnNumber(int columnNumber)
      Sets the "current column number" to the given value.
    • reset

      public abstract void reset()
      Resets the current line number to 1 and the current column number to one. (The configured tab width remains.)
    • create

      public static LineAndColumnTracker create()
      Returns:
      A LineAndColumnTracker instance