Class JavaInput


public final class JavaInput extends Input
JavaInput extends Input to represent a Java input document.
  • Constructor Details

    • JavaInput

      public JavaInput(String text) throws com.palantir.javaformat.java.FormatterException
      Input constructor.
      Parameters:
      text - the input text
      Throws:
      com.palantir.javaformat.java.FormatterException - if the input cannot be parsed
  • Method Details

    • getText

      public String getText()
      Get the input text.
      Specified by:
      getText in class Input
      Returns:
      the input text
    • getPositionToColumnMap

      public com.google.common.collect.ImmutableMap<Integer,Integer> getPositionToColumnMap()
      Specified by:
      getPositionToColumnMap in class Input
    • getLineSeparator

      public String getLineSeparator()
    • getTokens

      public com.google.common.collect.ImmutableList<? extends Input.Token> getTokens()
      Get the input tokens.
      Specified by:
      getTokens in class Input
      Returns:
      the input tokens
    • getPositionTokenMap

      public com.google.common.collect.ImmutableRangeMap<Integer,com.palantir.javaformat.java.JavaInput.Token> getPositionTokenMap()
      Get the navigable map from position to JavaInput.Token. Used to look for tokens following a given one, and to implement the --offset and --length flags to reformat a character range in the input file.
      Specified by:
      getPositionTokenMap in class Input
      Returns:
      the navigable map from position to JavaInput.Token
    • toString

      public String toString()
      Overrides:
      toString in class Input
    • getLineNumber

      public int getLineNumber(int inputPosition)
      Description copied from class: Input
      Converts a character offset in the input to a line number.
      Specified by:
      getLineNumber in class Input
    • getColumnNumber

      public int getColumnNumber(int inputPosition)
      Description copied from class: Input
      Converts a character offset in the input to a 0-based column number.
      Specified by:
      getColumnNumber in class Input
    • setCompilationUnit

      public void setCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit)
    • characterRangesToTokenRanges

      public com.google.common.collect.RangeSet<Integer> characterRangesToTokenRanges(Collection<com.google.common.collect.Range<Integer>> characterRanges) throws com.palantir.javaformat.java.FormatterException
      Throws:
      com.palantir.javaformat.java.FormatterException