import net.sourceforge.phpdt.core.compiler.CharOperation;
import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
+import net.sourceforge.phpdt.core.compiler.ITerminalSymbols.TokenName;
import net.sourceforge.phpdt.core.compiler.InvalidInputException;
/**
protected int[] lineEnds;
// Private fields
- private int currentTokenType = -1;
+ private TokenName currentTokenType = ITerminalSymbols.TokenName.NONE;
// Line pointers
private int linePtr, lastLinePtr;
// Init local variables
this.astLengthPtr = -1;
this.astPtr = -1;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
this.inlineTagStarted = false;
this.inlineTagStart = -1;
this.lineStarted = false;
}
// Read next char only if token was consumed
- if (this.currentTokenType < 0) {
+ if (this.currentTokenType.compareTo (ITerminalSymbols.TokenName.NONE) <= 0) {
nextCharacter = readChar(); // consider unicodes
} else {
previousPosition = this.scanner
.getCurrentTokenStartPosition();
switch (this.currentTokenType) {
- case ITerminalSymbols.TokenNameRBRACE:
+ case RBRACE:
nextCharacter = '}';
break;
- case ITerminalSymbols.TokenNameMULTIPLY:
+ case MULTIPLY:
nextCharacter = '*';
break;
default:
pushText(this.textStart, invalidTagLineEnd);
}
this.scanner.resetTo(this.index, this.endComment);
- this.currentTokenType = -1; // flush token cache at line
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // flush token cache at line
// begin
try {
- int token = readTokenAndConsume();
+ TokenName token = readTokenAndConsume();
this.tagSourceStart = this.scanner
.getCurrentTokenStartPosition();
this.tagSourceEnd = this.scanner
// than java identifier
// (see bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=51660)
- int tk = token;
+ TokenName tk = token;
int le = this.lineEnd;
char pc = peekChar();
- tagNameToken: while (tk != ITerminalSymbols.TokenNameEOF) {
+ tagNameToken: while (tk != ITerminalSymbols.TokenName.EOF) {
this.tagSourceEnd = this.scanner
.getCurrentTokenEndPosition();
token = tk;
this.lineEnd = le;
}
switch (token) {
- case ITerminalSymbols.TokenNameIdentifier:
+ case IDENTIFIER:
if (CharOperation.equals(tag, TAG_DEPRECATED)) {
this.deprecated = true;
if (this.kind == DOM_PARSER) {
valid = parseTag();
}
break;
- case ITerminalSymbols.TokenNamereturn:
+ case RETURN:
valid = parseReturn();
// verify characters after return tag (we're
// expecting text description)
}
}
break;
- // case ITerminalSymbols.TokenNamethrows :
+ // case ITerminalSymbols.TokenName.throws :
// valid = parseThrows(true);
// break;
default:
if (this.kind == DOM_PARSER) {
switch (token) {
- case ITerminalSymbols.TokenNameabstract:
+ case ABSTRACT:
// case
- // ITerminalSymbols.TokenNameassert:
+ // ITerminalSymbols.TokenName.assert:
// case
- // ITerminalSymbols.TokenNameboolean:
- case ITerminalSymbols.TokenNamebreak:
- // case ITerminalSymbols.TokenNamebyte:
- case ITerminalSymbols.TokenNamecase:
- case ITerminalSymbols.TokenNamecatch:
- // case ITerminalSymbols.TokenNamechar:
- case ITerminalSymbols.TokenNameclass:
- case ITerminalSymbols.TokenNamecontinue:
- case ITerminalSymbols.TokenNamedefault:
- case ITerminalSymbols.TokenNamedo:
+ // ITerminalSymbols.TokenName.boolean:
+ case BREAK:
+ // case byte:
+ case CASE:
+ case CATCH:
+ // case char:
+ case CLASS:
+ case CONTINUE:
+ case DEFAULT:
+ case DO:
// case
- // ITerminalSymbols.TokenNamedouble:
- case ITerminalSymbols.TokenNameelse:
- case ITerminalSymbols.TokenNameextends:
- // case ITerminalSymbols.TokenNamefalse:
- case ITerminalSymbols.TokenNamefinal:
- case ITerminalSymbols.TokenNamefinally:
- // case ITerminalSymbols.TokenNamefloat:
- case ITerminalSymbols.TokenNamefor:
- case ITerminalSymbols.TokenNameif:
- case ITerminalSymbols.TokenNameimplements:
+ // double:
+ case ELSE:
+ case EXTENDS:
+ // case false:
+ case FINAL:
+ case FINALLY:
+ // case float:
+ case FOR:
+ case IF:
+ case IMPLEMENTS:
// case
- // ITerminalSymbols.TokenNameimport:
- case ITerminalSymbols.TokenNameinstanceof:
- // case ITerminalSymbols.TokenNameint:
- case ITerminalSymbols.TokenNameinterface:
- // case ITerminalSymbols.TokenNamelong:
+ // import:
+ case INSTANCEOF:
+ // case int:
+ case INTERFACE:
+ // case long:
// case
- // ITerminalSymbols.TokenNamenative:
- case ITerminalSymbols.TokenNamenew:
- // case ITerminalSymbols.TokenNamenull:
+ // native:
+ case NEW:
+ // case null:
// case
- // ITerminalSymbols.TokenNamepackage:
- case ITerminalSymbols.TokenNameprivate:
- case ITerminalSymbols.TokenNameprotected:
- case ITerminalSymbols.TokenNamepublic:
- // case ITerminalSymbols.TokenNameshort:
- case ITerminalSymbols.TokenNamestatic:
+ // package:
+ case PRIVATE:
+ case PROTECTED:
+ case PUBLIC:
+ // case short:
+ case STATIC:
// case
- // ITerminalSymbols.TokenNamestrictfp:
- case ITerminalSymbols.TokenNamesuper:
- case ITerminalSymbols.TokenNameswitch:
+ // strictfp:
+ case SUPER:
+ case SWITCH:
// case
- // ITerminalSymbols.TokenNamesynchronized:
- // case ITerminalSymbols.TokenNamethis:
- case ITerminalSymbols.TokenNamethrow:
+ // synchronized:
+ // case this:
+ case THROW:
// case
- // ITerminalSymbols.TokenNametransient:
- // case ITerminalSymbols.TokenNametrue:
- case ITerminalSymbols.TokenNametry:
- // case ITerminalSymbols.TokenNamevoid:
+ // transient:
+ // case true:
+ case TRY:
+ // case void:
// case
- // ITerminalSymbols.TokenNamevolatile:
- case ITerminalSymbols.TokenNamewhile:
+ // volatile:
+ case WHILE:
valid = parseTag();
break;
}
}
private void consumeToken() {
- this.currentTokenType = -1; // flush token cache
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // flush token cache
updateLineEnd();
}
}
if (typeRef == null) {
if (firstArg
- && this.currentTokenType == ITerminalSymbols.TokenNameRPAREN) {
+ && this.currentTokenType == ITerminalSymbols.TokenName.RPAREN) {
// verify characters after arguments declaration (expecting
// white space or end comment)
if (!verifySpaceOrEndComment()) {
int dim = 0;
long[] dimPositions = new long[20]; // assume that there won't be
// more than 20 dimensions...
- if (readToken() == ITerminalSymbols.TokenNameLBRACKET) {
+ if (readToken() == ITerminalSymbols.TokenName.LBRACKET) {
int dimStart = this.scanner.getCurrentTokenStartPosition();
- while (readToken() == ITerminalSymbols.TokenNameLBRACKET) {
+ while (readToken() == ITerminalSymbols.TokenName.LBRACKET) {
consumeToken();
- if (readToken() != ITerminalSymbols.TokenNameRBRACKET) {
+ if (readToken() != ITerminalSymbols.TokenName.RBRACKET) {
break nextArg;
}
consumeToken();
// Read argument name
long argNamePos = -1;
- if (readToken() == ITerminalSymbols.TokenNameIdentifier) {
+ if (readToken() == ITerminalSymbols.TokenName.IDENTIFIER) {
consumeToken();
if (firstArg) { // verify position
if (iToken != 1)
}
// Read separator or end arguments declaration
- int token = readToken();
+ TokenName token = readToken();
char[] name = argName == null ? new char[0] : argName;
- if (token == ITerminalSymbols.TokenNameCOMMA) {
+ if (token == ITerminalSymbols.TokenName.COMMA) {
// Create new argument
Object argument = createArgumentReference(name, dim, typeRef,
dimPositions, argNamePos);
arguments.add(argument);
consumeToken();
iToken++;
- } else if (token == ITerminalSymbols.TokenNameRPAREN) {
+ } else if (token == ITerminalSymbols.TokenName.RPAREN) {
// verify characters after arguments declaration (expecting
// white space or end comment)
if (!verifySpaceOrEndComment()) {
int start = this.scanner.getCurrentTokenStartPosition();
if (Character.toLowerCase(readChar()) == 'a') {
this.scanner.currentPosition = this.index;
- if (readToken() == ITerminalSymbols.TokenNameIdentifier) {
- this.currentTokenType = -1; // do not update line end
+ if (readToken() == ITerminalSymbols.TokenName.IDENTIFIER) {
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // do not update line end
try {
if (CharOperation.equals(this.scanner
.getCurrentIdentifierSource(), new char[] { 'h',
'r', 'e', 'f' }, false)
- && readToken() == ITerminalSymbols.TokenNameEQUAL) {
- this.currentTokenType = -1; // do not update line end
- if (readToken() == ITerminalSymbols.TokenNameStringDoubleQuote
- || readToken() == ITerminalSymbols.TokenNameStringSingleQuote) {
- this.currentTokenType = -1; // do not update line
+ && readToken() == ITerminalSymbols.TokenName.EQUAL) {
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // do not update line end
+ if (readToken() == ITerminalSymbols.TokenName.STRINGDOUBLEQUOTE
+ || readToken() == ITerminalSymbols.TokenName.STRINGSINGLEQUOTE) {
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // do not update line
// end
// Skip all characters after string literal until
// closing '>' (see bug 68726)
while (this.index <= this.lineEnd
- && readToken() != ITerminalSymbols.TokenNameGREATER) {
- this.currentTokenType = -1; // do not update
+ && readToken() != ITerminalSymbols.TokenName.GREATER) {
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // do not update
// line end
}
- if (this.currentTokenType == ITerminalSymbols.TokenNameGREATER) {
+ if (this.currentTokenType == ITerminalSymbols.TokenName.GREATER) {
consumeToken(); // update line end as new lines
// are allowed in URL
// description
- while (readToken() != ITerminalSymbols.TokenNameLESS) {
+ while (readToken() != ITerminalSymbols.TokenName.LESS) {
if (this.scanner.currentPosition >= this.scanner.eofPosition
|| this.scanner.currentCharacter == '@') {
// Reset position: we want to rescan
// last token
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
// Signal syntax error
if (this.sourceParser != null)
this.sourceParser
}
consumeToken();
}
- this.currentTokenType = -1; // do not update
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE; // do not update
// line end
if (readChar() == '/') {
if (Character.toLowerCase(readChar()) == 'a') {
// Reset position: we want to rescan last token
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
// Signal syntax error
if (this.sourceParser != null)
this.sourceParser.problemReporter().javadocInvalidSeeUrlReference(
this.memberStart = start;
// Get member identifier
- if (readToken() == ITerminalSymbols.TokenNameIdentifier) {
+ if (readToken() == ITerminalSymbols.TokenName.IDENTIFIER) {
consumeToken();
pushIdentifier(true);
// Look for next token to know whether it's a field or method
// reference
int previousPosition = this.index;
- if (readToken() == ITerminalSymbols.TokenNameLPAREN) {
+ if (readToken() == ITerminalSymbols.TokenName.LPAREN) {
consumeToken();
start = this.scanner.getCurrentTokenStartPosition();
try {
// Reset position: we want to rescan last token
this.index = previousPosition;
this.scanner.currentPosition = previousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
// Verify character(s) after identifier (expecting space or end
// comment)
// Reset position: we want to rescan last token
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
return null;
}
try {
// Push identifier next
- int token = readToken();
+ TokenName token = readToken();
switch (token) {
- case ITerminalSymbols.TokenNameIdentifier:
+ case IDENTIFIER:
consumeToken();
return pushParamName();
- case ITerminalSymbols.TokenNameEOF:
+ case EOF:
break;
default:
start = this.scanner.getCurrentTokenStartPosition();
// Reset position to avoid missing tokens when new line was encountered
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
// Report problem
if (this.sourceParser != null)
// Scan tokens
int primitiveToken = -1;
nextToken: for (int iToken = 0;; iToken++) {
- int token = readToken();
+ TokenName token = readToken();
switch (token) {
- case ITerminalSymbols.TokenNameIdentifier:
+ case IDENTIFIER:
if (((iToken % 2) > 0)) { // identifiers must be odd tokens
break nextToken;
}
consumeToken();
break;
- case ITerminalSymbols.TokenNameDOT:
+ case DOT:
if ((iToken % 2) == 0) { // dots must be even tokens
throw new InvalidInputException();
}
consumeToken();
break;
- // case ITerminalSymbols.TokenNamevoid :
- // case ITerminalSymbols.TokenNameboolean :
- // case ITerminalSymbols.TokenNamebyte :
- // case ITerminalSymbols.TokenNamechar :
- // case ITerminalSymbols.TokenNamedouble :
- // case ITerminalSymbols.TokenNamefloat :
- // case ITerminalSymbols.TokenNameint :
- // case ITerminalSymbols.TokenNamelong :
- // case ITerminalSymbols.TokenNameshort :
+ // case ITerminalSymbols.TokenName.void :
+ // case ITerminalSymbols.TokenName.boolean :
+ // case ITerminalSymbols.TokenName.byte :
+ // case ITerminalSymbols.TokenName.char :
+ // case ITerminalSymbols.TokenName.double :
+ // case ITerminalSymbols.TokenName.float :
+ // case ITerminalSymbols.TokenName.int :
+ // case ITerminalSymbols.TokenName.long :
+ // case ITerminalSymbols.TokenName.short :
// if (iToken > 0) {
// throw new InvalidInputException();
// }
}
if ((iToken % 2) == 0) { // cannot leave on a dot
// Reset position: we want to rescan last token
- if (this.kind == DOM_PARSER && this.currentTokenType != -1) {
+ if (this.kind == DOM_PARSER && this.currentTokenType.compareTo (ITerminalSymbols.TokenName.NONE) > 0) {
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
}
throw new InvalidInputException();
}
}
}
// Reset position: we want to rescan last token
- if (this.currentTokenType != -1) {
+ if (this.currentTokenType.compareTo (ITerminalSymbols.TokenName.NONE) > 0) {
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
}
this.lastIdentifierEndPosition = (int) this.identifierPositionStack[this.identifierPtr];
return createTypeReference(primitiveToken);
int typeRefStartPosition = -1;
nextToken: while (this.index < this.scanner.eofPosition) {
previousPosition = this.index;
- int token = readToken();
+ TokenName token = readToken();
switch (token) {
- case ITerminalSymbols.TokenNameStringDoubleQuote: // @see "string"
- case ITerminalSymbols.TokenNameStringSingleQuote:
+ case STRINGDOUBLEQUOTE: // @see "string"
+ case STRINGSINGLEQUOTE:
int start = this.scanner.getCurrentTokenStartPosition();
consumeToken();
// If typeRef != null we may raise a warning here to let user
this.sourceParser.problemReporter()
.javadocInvalidSeeReference(start, this.lineEnd);
return false;
- case ITerminalSymbols.TokenNameLESS: // @see "<a
- // href="URL#Value">label</a>
+ case LESS: // @see "<a href="URL#Value">label</a>
consumeToken();
start = this.scanner.getCurrentTokenStartPosition();
if (parseHref()) {
.javadocInvalidSeeReference(start, this.lineEnd);
}
return false;
- case ITerminalSymbols.TokenNameERROR:
+ case ERROR:
if (this.scanner.currentCharacter == '#') { // @see ...#member
consumeToken();
reference = parseMember(typeRef);
return false;
}
break nextToken;
- case ITerminalSymbols.TokenNameIdentifier:
+ case IDENTIFIER:
if (typeRef == null) {
typeRefStartPosition = this.scanner
.getCurrentTokenStartPosition();
if (reference == null) {
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
if (this.sourceParser != null)
this.sourceParser.problemReporter().javadocMissingSeeReference(
this.tagSourceStart, this.tagSourceEnd);
// Reset position at the end of type reference
this.index = this.lastIdentifierEndPosition + 1;
this.scanner.currentPosition = this.index;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
// Verify that line end does not start with an open parenthese (which
// could be a constructor reference wrongly written...)
if (!verifySpaceOrEndComment()) {
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
int end = this.starPosition == -1 ? this.lineEnd
: this.starPosition;
if (this.source[end] == '\n')
// Reset position to avoid missing tokens when new line was encountered
this.index = this.tokenPreviousPosition;
this.scanner.currentPosition = this.tokenPreviousPosition;
- this.currentTokenType = -1;
+ this.currentTokenType = ITerminalSymbols.TokenName.NONE;
return false;
}
/*
* Read token only if previous was consumed
*/
- private int readToken() throws InvalidInputException {
- if (this.currentTokenType < 0) {
+ private TokenName readToken() throws InvalidInputException {
+ if (this.currentTokenType.compareTo (ITerminalSymbols.TokenName.NONE) <= 0) {
this.tokenPreviousPosition = this.scanner.currentPosition;
this.currentTokenType = this.scanner.getNextToken();
if (this.scanner.currentPosition > (this.lineEnd + 1)) { // be
// same
// line)
this.lineStarted = false;
- while (this.currentTokenType == ITerminalSymbols.TokenNameMULTIPLY) {
+ while (this.currentTokenType == ITerminalSymbols.TokenName.MULTIPLY) {
this.currentTokenType = this.scanner.getNextToken();
}
}
return this.currentTokenType;
}
- private int readTokenAndConsume() throws InvalidInputException {
- int token = readToken();
+ private TokenName readTokenAndConsume() throws InvalidInputException {
+ TokenName token = readToken();
consumeToken();
return token;
}