Class JavaInput


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

    • text

      private final String text
    • kN

      private int kN
    • positionToColumnMap

      private final com.google.common.collect.ImmutableMap<Integer,Integer> positionToColumnMap
    • tokens

      private final com.google.common.collect.ImmutableList<JavaInput.Token> tokens
    • positionTokenMap

      private final com.google.common.collect.ImmutableRangeMap<Integer,JavaInput.Token> positionTokenMap
    • kToToken

      private final JavaInput.Token[] kToToken
      Map from Tok index to the associated Token.
    • unit

      private com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit
  • Constructor Details

  • Method Details

    • makePositionToColumnMap

      private static com.google.common.collect.ImmutableMap<Integer,Integer> makePositionToColumnMap(List<JavaInput.Tok> toks)
    • 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
    • buildToks

      private com.google.common.collect.ImmutableList<JavaInput.Tok> buildToks(String text) throws FormatterException
      Lex the input and build the list of toks.
      Throws:
      FormatterException
    • buildToks

      static com.google.common.collect.ImmutableList<JavaInput.Tok> buildToks(String text, com.google.common.collect.ImmutableSet<com.sun.tools.javac.parser.Tokens.TokenKind> stopTokens) throws FormatterException
      Lex the input and build the list of toks.
      Parameters:
      text - the text to be lexed.
      stopTokens - a set of tokens which should cause lexing to stop. If one of these is found, the returned list will include tokens up to but not including that token.
      Throws:
      FormatterException
    • updateColumn

      private static int updateColumn(int columnI, String originalTokText)
    • buildTokens

      private static com.google.common.collect.ImmutableList<JavaInput.Token> buildTokens(List<JavaInput.Tok> toks)
    • isParamComment

      private static boolean isParamComment(JavaInput.Tok tok)
    • characterRangeToTokenRange

      com.google.common.collect.Range<Integer> characterRangeToTokenRange(com.google.common.collect.Range<Integer> characterRange) throws FormatterException
      Convert from a character range to a token range.
      Parameters:
      characterRange - the 0-based Range of characters
      Returns:
      the 0-based Range of tokens
      Throws:
      FormatterException - if the upper endpoint of the range is outside the file
    • getkN

      public int getkN()
      Get the number of toks.
      Specified by:
      getkN in class Input
      Returns:
      the number of toks, excluding the EOF tok
    • getToken

      public JavaInput.Token getToken(int k)
      Get the Token by index.
      Specified by:
      getToken in class Input
      Parameters:
      k - the Tok index
    • 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,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 FormatterException
      Throws:
      FormatterException