Package com.google.googlejavaformat.java
Class JavaInput
- java.lang.Object
-
- com.google.googlejavaformat.InputOutput
-
- com.google.googlejavaformat.Input
-
- com.google.googlejavaformat.java.JavaInput
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classJavaInput.TokAJavaInputis a sequence ofJavaInput.Toks that cover the Java input.(package private) static classJavaInput.TokenAJavaInput.Tokencontains a tokenJavaInput.Tokand its associated non-tokens; each non-tokenJavaInput.Tokbelongs to oneJavaInput.Token.
-
Field Summary
Fields Modifier and Type Field Description private intkNprivate JavaInput.Token[]kToTokenMap from Tok index to the associated Token.private com.google.common.collect.ImmutableMap<java.lang.Integer,java.lang.Integer>positionToColumnMapprivate com.google.common.collect.ImmutableRangeMap<java.lang.Integer,JavaInput.Token>positionTokenMapprivate java.lang.Stringtextprivate com.google.common.collect.ImmutableList<JavaInput.Token>tokensprivate com.sun.tools.javac.tree.JCTree.JCCompilationUnitunit-
Fields inherited from class com.google.googlejavaformat.InputOutput
EMPTY_RANGE, ranges
-
-
Constructor Summary
Constructors Constructor Description JavaInput(java.lang.String text)Input constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static com.google.common.collect.ImmutableList<JavaInput.Token>buildTokens(java.util.List<JavaInput.Tok> toks)private com.google.common.collect.ImmutableList<JavaInput.Tok>buildToks(java.lang.String text)Lex the input and build the list of toks.(package private) 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)Lex the input and build the list of toks.com.google.common.collect.RangeSet<java.lang.Integer>characterRangesToTokenRanges(java.util.Collection<com.google.common.collect.Range<java.lang.Integer>> characterRanges)(package private) com.google.common.collect.Range<java.lang.Integer>characterRangeToTokenRange(com.google.common.collect.Range<java.lang.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.ImmutableMap<java.lang.Integer,java.lang.Integer>getPositionToColumnMap()com.google.common.collect.ImmutableRangeMap<java.lang.Integer,JavaInput.Token>getPositionTokenMap()Get the navigable map from position toJavaInput.Token.java.lang.StringgetText()Get the input text.JavaInput.TokengetToken(int k)Get the Token by index.com.google.common.collect.ImmutableList<? extends Input.Token>getTokens()Get the input tokens.private static booleanisParamComment(JavaInput.Tok tok)private static com.google.common.collect.ImmutableMap<java.lang.Integer,java.lang.Integer>makePositionToColumnMap(java.util.List<JavaInput.Tok> toks)voidsetCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit)java.lang.StringtoString()private static intupdateColumn(int columnI, java.lang.String originalTokText)-
Methods inherited from class com.google.googlejavaformat.Input
createDiagnostic
-
Methods inherited from class com.google.googlejavaformat.InputOutput
computeRanges, getLine, getLineCount, getRanges, makeKToIJ, setLines
-
-
-
-
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 FormatterExceptionInput 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.
-
getPositionToColumnMap
public com.google.common.collect.ImmutableMap<java.lang.Integer,java.lang.Integer> getPositionToColumnMap()
- Specified by:
getPositionToColumnMapin classInput
-
buildToks
private com.google.common.collect.ImmutableList<JavaInput.Tok> buildToks(java.lang.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(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)
-
buildTokens
private static com.google.common.collect.ImmutableList<JavaInput.Token> buildTokens(java.util.List<JavaInput.Tok> toks)
-
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 FormatterExceptionConvert 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
public JavaInput.Token getToken(int k)
Get the Token by index.
-
getTokens
public com.google.common.collect.ImmutableList<? extends Input.Token> getTokens()
Get the input tokens.
-
getPositionTokenMap
public com.google.common.collect.ImmutableRangeMap<java.lang.Integer,JavaInput.Token> 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
-
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<java.lang.Integer> characterRangesToTokenRanges(java.util.Collection<com.google.common.collect.Range<java.lang.Integer>> characterRanges) throws FormatterException- Throws:
FormatterException
-
-