Top Description Fields Constructors Methods
com.google.auto.value.processor

pack-priv Class JavaScanner

extends Object
Class Inheritance

A simplistic Java scanner. This scanner returns a sequence of tokens that can be used to reconstruct the source code. Since the source code is coming from a string, the scanner in fact just returns token boundaries rather than the tokens themselves.

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.

Author
Éamonn McManus

Field Summary

Modifier and TypeField and Description
private final String
s

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private int
blockCommentEnd(int start)

private int
lineCommentEnd(int start)

private int
quoteEnd(int start)

private int
spaceEnd(int start)

pack-priv String
string()

Returns the string being scanned, which is either the original input string or that string plus a newline.

pack-priv int
tokenEnd(int start)

Returns the position at which this token ends and the next token begins.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sback to summary
private final String s

Constructor Detail

JavaScannerback to summary
pack-priv JavaScanner(String s)

Method Detail

blockCommentEndback to summary
private int blockCommentEnd(int start)
lineCommentEndback to summary
private int lineCommentEnd(int start)
quoteEndback to summary
private int quoteEnd(int start)
spaceEndback to summary
private int spaceEnd(int start)
stringback to summary
pack-priv String string()

Returns the string being scanned, which is either the original input string or that string plus a newline.

tokenEndback to summary
pack-priv int tokenEnd(int start)

Returns the position at which this token ends and the next token begins.