Class JavaInput


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

      • text

        private final java.lang.String text
      • kN

        private int kN
      • positionToColumnMap

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

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

        private final com.google.common.collect.ImmutableRangeMap<java.lang.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 Detail

      • JavaInput

        public JavaInput​(java.lang.String text)
                  throws FormatterException
        Input constructor.
        Parameters:
        text - the input text
        Throws:
        FormatterException - if the input cannot be parsed
    • Method Detail

      • makePositionToColumnMap

        private static com.google.common.collect.ImmutableMap<java.lang.Integer,​java.lang.Integer> makePositionToColumnMap​(java.util.List<JavaInput.Tok> toks)
      • getText

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

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

        static com.google.common.collect.ImmutableList<JavaInput.Tok> buildToks​(java.lang.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,
                                        java.lang.String originalTokText)
      • isParamComment

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

        com.google.common.collect.Range<java.lang.Integer> characterRangeToTokenRange​(com.google.common.collect.Range<java.lang.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<java.lang.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 java.lang.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<java.lang.Integer> characterRangesToTokenRanges​(java.util.Collection<com.google.common.collect.Range<java.lang.Integer>> characterRanges)
                                                                                           throws FormatterException
        Throws:
        FormatterException