Method from com.sun.tools.javac.parser.Scanner Detail: |
public boolean deprecatedFlag() {
return deprecatedFlag;
}
Has a @deprecated been encountered in last doc comment?
This needs to be reset by client with resetDeprecatedFlag. |
public String docComment() {
return null;
}
Returns the documentation string of the current token. |
public int endPos() {
return endPos;
}
Return the last character position of the current token. |
public int errPos() {
return errPos;
}
Return the position where a lexical error occurred; |
public void errPos(int pos) {
errPos = pos;
}
Set the position where a lexical error occurred; |
public LineMap getLineMap() {
return Position.makeLineMap(buf, buflen, false);
}
Build a map for translating between line numbers and
positions in the input. |
public char[] getRawCharacters() {
char[] chars = new char[buflen];
System.arraycopy(buf, 0, chars, 0, buflen);
return chars;
}
Returns a copy of the input buffer, up to its inputLength.
Unicode escape sequences are not translated. |
public char[] getRawCharacters(int beginIndex,
int endIndex) {
int length = endIndex - beginIndex;
char[] chars = new char[length];
System.arraycopy(buf, beginIndex, chars, 0, length);
return chars;
}
Returns a copy of a character array subset of the input buffer.
The returned array begins at the beginIndex and
extends to the character at index endIndex - 1 .
Thus the length of the substring is endIndex-beginIndex .
This behavior is like
String.substring(beginIndex, endIndex) .
Unicode escape sequences are not translated. |
public Name name() {
return name;
}
Return the name of an identifier or token for the current token. |
public void nextToken() {
try {
prevEndPos = endPos;
sp = 0;
while (true) {
pos = bp;
switch (ch) {
case ' ': // (Spec 3.6)
case '\t': // (Spec 3.6)
case FF: // (Spec 3.6)
do {
scanChar();
} while (ch == ' ' || ch == '\t' || ch == FF);
endPos = bp;
processWhiteSpace();
break;
case LF: // (Spec 3.4)
scanChar();
endPos = bp;
processLineTerminator();
break;
case CR: // (Spec 3.4)
scanChar();
if (ch == LF) {
scanChar();
}
endPos = bp;
processLineTerminator();
break;
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y':
case 'Z':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z':
case '$': case '_':
scanIdent();
return;
case '0':
scanChar();
if (ch == 'x' || ch == 'X') {
scanChar();
skipIllegalUnderscores();
if (ch == '.') {
scanHexFractionAndSuffix(false);
} else if (digit(16) < 0) {
lexError("invalid.hex.number");
} else {
scanNumber(16);
}
} else if (ch == 'b' || ch == 'B') {
if (!allowBinaryLiterals) {
lexError("unsupported.binary.lit", source.name);
allowBinaryLiterals = true;
}
scanChar();
skipIllegalUnderscores();
if (digit(2) < 0) {
lexError("invalid.binary.number");
} else {
scanNumber(2);
}
} else {
putChar('0');
if (ch == '_') {
int savePos = bp;
do {
scanChar();
} while (ch == '_');
if (digit(10) < 0) {
lexError(savePos, "illegal.underscore");
}
}
scanNumber(8);
}
return;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
scanNumber(10);
return;
case '.':
scanChar();
if ('0' < = ch && ch < = '9') {
putChar('.');
scanFractionAndSuffix();
} else if (ch == '.') {
putChar('.'); putChar('.');
scanChar();
if (ch == '.') {
scanChar();
putChar('.');
token = ELLIPSIS;
} else {
lexError("malformed.fp.lit");
}
} else {
token = DOT;
}
return;
case ',':
scanChar(); token = COMMA; return;
case ';':
scanChar(); token = SEMI; return;
case '(':
scanChar(); token = LPAREN; return;
case ')':
scanChar(); token = RPAREN; return;
case '[':
scanChar(); token = LBRACKET; return;
case ']':
scanChar(); token = RBRACKET; return;
case '{':
scanChar(); token = LBRACE; return;
case '}':
scanChar(); token = RBRACE; return;
case '/':
scanChar();
if (ch == '/') {
do {
scanCommentChar();
} while (ch != CR && ch != LF && bp < buflen);
if (bp < buflen) {
endPos = bp;
processComment(CommentStyle.LINE);
}
break;
} else if (ch == '*') {
scanChar();
CommentStyle style;
if (ch == '*') {
style = CommentStyle.JAVADOC;
scanDocComment();
} else {
style = CommentStyle.BLOCK;
while (bp < buflen) {
if (ch == '*') {
scanChar();
if (ch == '/') break;
} else {
scanCommentChar();
}
}
}
if (ch == '/') {
scanChar();
endPos = bp;
processComment(style);
break;
} else {
lexError("unclosed.comment");
return;
}
} else if (ch == '=') {
name = names.slashequals;
token = SLASHEQ;
scanChar();
} else {
name = names.slash;
token = SLASH;
}
return;
case '\'':
scanChar();
if (ch == '\'') {
lexError("empty.char.lit");
} else {
if (ch == CR || ch == LF)
lexError(pos, "illegal.line.end.in.char.lit");
scanLitChar();
if (ch == '\'') {
scanChar();
token = CHARLITERAL;
} else {
lexError(pos, "unclosed.char.lit");
}
}
return;
case '\"':
scanChar();
while (ch != '\"' && ch != CR && ch != LF && bp < buflen)
scanLitChar();
if (ch == '\"') {
token = STRINGLITERAL;
scanChar();
} else {
lexError(pos, "unclosed.str.lit");
}
return;
default:
if (isSpecial(ch)) {
scanOperator();
} else {
boolean isJavaIdentifierStart;
if (ch < '\u0080') {
// all ASCII range chars already handled, above
isJavaIdentifierStart = false;
} else {
char high = scanSurrogates();
if (high != 0) {
if (sp == sbuf.length) {
putChar(high);
} else {
sbuf[sp++] = high;
}
isJavaIdentifierStart = Character.isJavaIdentifierStart(
Character.toCodePoint(high, ch));
} else {
isJavaIdentifierStart = Character.isJavaIdentifierStart(ch);
}
}
if (isJavaIdentifierStart) {
scanIdent();
} else if (bp == buflen || ch == EOI && bp+1 == buflen) { // JLS 3.5
token = EOF;
pos = bp = eofPos;
} else {
lexError("illegal.char", String.valueOf((int)ch));
scanChar();
}
}
return;
}
}
} finally {
endPos = bp;
if (scannerDebug)
System.out.println("nextToken(" + pos
+ "," + endPos + ")=|" +
new String(getRawCharacters(pos, endPos))
+ "|");
}
}
|
public int pos() {
return pos;
}
Return the current token's position: a 0-based
offset from beginning of the raw input stream
(before unicode translation) |
public int prevEndPos() {
return prevEndPos;
}
Return the last character position of the previous token. |
protected void processComment(CommentStyle style) {
if (scannerDebug)
System.out.println("processComment(" + pos
+ "," + endPos + "," + style + ")=|"
+ new String(getRawCharacters(pos, endPos))
+ "|");
}
Called when a complete comment has been scanned. pos and endPos
will mark the comment boundary. |
protected void processLineTerminator() {
if (scannerDebug)
System.out.println("processTerminator(" + pos
+ "," + endPos + ")=|" +
new String(getRawCharacters(pos, endPos))
+ "|");
}
Called when a line terminator has been processed. |
protected void processWhiteSpace() {
if (scannerDebug)
System.out.println("processWhitespace(" + pos
+ "," + endPos + ")=|" +
new String(getRawCharacters(pos, endPos))
+ "|");
}
Called when a complete whitespace run has been scanned. pos and endPos
will mark the whitespace boundary. |
public int radix() {
return radix;
}
Return the radix of a numeric literal token. |
public void resetDeprecatedFlag() {
deprecatedFlag = false;
}
|
public String stringVal() {
return new String(sbuf, 0, sp);
}
The value of a literal token, recorded as a string.
For integers, leading 0x and 'l' suffixes are suppressed. |
public Token token() {
return token;
}
Return the current token, set by nextToken(). |
public void token(Token token) {
this.token = token;
}
|