Package com.google.googlejavaformat.java
Class JavaInput
java.lang.Object
com.google.googlejavaformat.InputOutput
com.google.googlejavaformat.Input
com.google.googlejavaformat.java.JavaInput
JavaInput extends Input to represent a Java input document.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classAJavaInputis a sequence ofJavaInput.Toks that cover the Java input.(package private) static final classAJavaInput.Tokencontains a tokenJavaInput.Tokand its associated non-tokens; each non-tokenJavaInput.Tokbelongs to oneJavaInput.Token. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final JavaInput.Token[]Map from Tok index to the associated Token.private final com.google.common.collect.ImmutableRangeMap<Integer, JavaInput.Token> private final Stringprivate final com.google.common.collect.ImmutableList<JavaInput.Token> private com.sun.tools.javac.tree.JCTree.JCCompilationUnitFields inherited from class com.google.googlejavaformat.InputOutput
EMPTY_RANGE, ranges -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static com.google.common.collect.ImmutableList<JavaInput.Token> buildTokens(List<JavaInput.Tok> toks) private com.google.common.collect.ImmutableList<JavaInput.Tok> Lex the input and build the list of toks.(package private) static com.google.common.collect.ImmutableList<JavaInput.Tok> buildToks(String text, com.google.common.collect.ImmutableSet<com.sun.tools.javac.parser.Tokens.TokenKind> stopTokens) Lex the input and build the list of toks.com.google.common.collect.RangeSet<Integer> characterRangesToTokenRanges(Collection<com.google.common.collect.Range<Integer>> characterRanges) (package private) com.google.common.collect.Range<Integer> characterRangeToTokenRange(com.google.common.collect.Range<Integer> characterRange) Convert from a character range to a token range.intgetColumnNumber(int inputPosition) Converts a character offset in the input to a 0-based column number.intgetkN()Get the number of toks.intgetLineNumber(int inputPosition) Converts a character offset in the input to a line number.com.google.common.collect.ImmutableRangeMap<Integer, JavaInput.Token> Get the navigable map from position toJavaInput.Token.getText()Get the input text.getToken(int k) Get the Token by index.com.google.common.collect.ImmutableList<? extends Input.Token> Get the input tokens.private static booleanvoidsetCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit) toString()private static intupdateColumn(int columnI, String originalTokText) Methods inherited from class com.google.googlejavaformat.Input
createDiagnosticMethods inherited from class com.google.googlejavaformat.InputOutput
computeRanges, getLine, getLineCount, getRanges, makeKToIJ, setLines
-
Field Details
-
text
-
kN
private int kN -
positionToColumnMap
-
tokens
-
positionTokenMap
-
kToToken
Map from Tok index to the associated Token. -
unit
private com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit
-
-
Constructor Details
-
JavaInput
Input constructor.- Parameters:
text- the input text- Throws:
FormatterException- if the input cannot be parsed
-
-
Method Details
-
makePositionToColumnMap
private static com.google.common.collect.ImmutableMap<Integer,Integer> makePositionToColumnMap(List<JavaInput.Tok> toks) -
getText
Get the input text. -
getPositionToColumnMap
- Specified by:
getPositionToColumnMapin classInput
-
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
-
buildTokens
private static com.google.common.collect.ImmutableList<JavaInput.Token> buildTokens(List<JavaInput.Tok> toks) -
isParamComment
-
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- the0-basedRangeof characters- Returns:
- the
0-basedRangeof tokens - Throws:
FormatterException- if the upper endpoint of the range is outside the file
-
getkN
public int getkN()Get the number of toks. -
getToken
Get the Token by index. -
getTokens
Get the input tokens. -
getPositionTokenMap
Get the navigable map from position toJavaInput.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:
getPositionTokenMapin classInput- Returns:
- the navigable map from position to
JavaInput.Token
-
toString
-
getLineNumber
public int getLineNumber(int inputPosition) Description copied from class:InputConverts a character offset in the input to a line number.- Specified by:
getLineNumberin classInput
-
getColumnNumber
public int getColumnNumber(int inputPosition) Description copied from class:InputConverts a character offset in the input to a 0-based column number.- Specified by:
getColumnNumberin classInput
-
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
-