Class JavaScanner
We are not dealing with arbitrary user code so we can assume there are no exotic things like tabs or Unicode escapes that resolve into quotes. The purpose of the scanner here is to return a sequence of offsets that split the string up in a way that allows us to work with spaces without having to worry whether they are inside strings or comments. The particular properties we use are that every string and character literal and every comment is a single token; every newline plus all following indentation is a single token; and every other string of consecutive spaces outside a comment or literal is a single token. That means that we can safely compress a token that starts with a space into a single space, without falsely removing indentation or changing the contents of strings.
In addition to real Java syntax, this scanner recognizes tokens of the form `text`
,
which are used in the templates to wrap fully-qualified type names, so that they can be extracted
and replaced by imported names if possible.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int
blockCommentEnd
(int start) private int
lineCommentEnd
(int start) private int
quoteEnd
(int start) private int
spaceEnd
(int start) (package private) int
tokenEnd
(int start)
-
Field Details
-
s
-
-
Constructor Details
-
JavaScanner
JavaScanner(String s)
-
-
Method Details
-
tokenEnd
int tokenEnd(int start) -
spaceEnd
private int spaceEnd(int start) -
blockCommentEnd
private int blockCommentEnd(int start) -
lineCommentEnd
private int lineCommentEnd(int start) -
quoteEnd
private int quoteEnd(int start)
-