// Literal
return this.parseLiteral();
}
if (this.scanner.peek().isIdentifier()) {
Location location = this.location();
String[] qi = this.parseQualifiedIdentifier();
if (this.peekOperator("(")) {
// Name Arguments
return new Java.MethodInvocation(
this.location(), // location
qi.length == 1 ? null : new Java.AmbiguousName( // optionalTarget
location, // location
qi, // identifiers
qi.length - 1 // n
),
qi[qi.length - 1], // methodName
this.parseArguments() // arguments
);
}
if (
this.peekOperator("[")
&& this.scanner.peekNextButOne().isOperator("]")
) {
// Name '[]' { '[]' }
// Name '[]' { '[]' } '.' 'class'
Java.Type res = new Java.ReferenceType(
location, // location
qi // identifiers
);
int brackets = this.parseBracketsOpt();
for (int i = 0; i < brackets; ++i) res = new Java.ArrayType(res);
if (
this.peekOperator(".")
&& this.scanner.peekNextButOne().isKeyword("class")
) {
this.eatToken();
Location location2 = this.location();
this.eatToken();
return new Java.ClassLiteral(location2, res);
} else {
return res;
}
}
// Name
return new Java.AmbiguousName(
this.location(), // location
qi // identifiers
);
}
if (this.peekKeyword("this")) {
Location location = this.location();
this.eatToken();
if (this.peekOperator("(")) {
// 'this' Arguments
// Alternate constructor invocation (JLS 8.8.5.1)
return new Java.AlternateConstructorInvocation(
location, // location
this.parseArguments() // arguments
);
} else
{
// 'this'
return new Java.ThisReference(location);
}
}
if (this.peekKeyword("super")) {
this.eatToken();
if (this.peekOperator("(")) {
// 'super' Arguments
// Unqualified superclass constructor invocation (JLS 8.8.5.1)
return new Java.SuperConstructorInvocation(
this.location(), // location
(Java.Rvalue) null, // optionalQualification
this.parseArguments() // arguments
);
}
this.readOperator(".");
String name = this.readIdentifier();
if (this.peekOperator("(")) {
// 'super' '.' Identifier Arguments
return new Java.SuperclassMethodInvocation(
this.location(), // location
name, // methodName
this.parseArguments() // arguments
);
} else {
// 'super' '.' Identifier
return new Java.SuperclassFieldAccessExpression(
this.location(), // location
(Java.Type) null, // optionalQualification
name // fieldName
);
}
}
// 'new'
if (this.peekKeyword("new")) {
Location location = this.location();
this.eatToken();
Java.Type type = this.parseType();
if (type instanceof Java.ArrayType) {
// 'new' ArrayType ArrayInitializer
return new Java.NewInitializedArray(location, (Java.ArrayType) type, this.parseArrayInitializer());
}
if (
type instanceof Java.ReferenceType
&& this.peekOperator("(")
) {
// 'new' ReferenceType Arguments [ ClassBody ]
Java.Rvalue[] arguments = this.parseArguments();
if (this.peekOperator("{")) {
// 'new' ReferenceType Arguments ClassBody
final Java.AnonymousClassDeclaration anonymousClassDeclaration = new Java.AnonymousClassDeclaration(
this.location(), // location
type // baseType
);
this.parseClassBody(anonymousClassDeclaration);
return new Java.NewAnonymousClassInstance(
location, // location
(Java.Rvalue) null, // optionalQualification
anonymousClassDeclaration, // anonymousClassDeclaration
arguments // arguments
);
} else {
// 'new' ReferenceType Arguments
return new Java.NewClassInstance(
location, // location
(Java.Rvalue) null, // optionalQualification
type, // type
arguments // arguments
);
}
}
// 'new' Type DimExprs { '[]' }
return new Java.NewArray(
location, // location
type, // type
this.parseDimExprs(), // dimExprs
this.parseBracketsOpt() // dims
);
}
// BasicType
if (this.peekKeyword(new String[] { "boolean", "char", "byte", "short", "int", "long", "float", "double", })) {
Java.Type res = this.parseType();
int brackets = this.parseBracketsOpt();
for (int i = 0; i < brackets; ++i) res = new Java.ArrayType(res);
if (
this.peekOperator(".")
&& this.scanner.peekNextButOne().isKeyword("class")
) {
// BasicType { '[]' } '.' 'class'
this.eatToken();
Location location = this.location();
this.eatToken();
return new Java.ClassLiteral(location, res);
}
// BasicType { '[]' }
return res;
}
// 'void'
if (this.peekKeyword("void")) {
this.eatToken();
if (
this.peekOperator(".")
&& this.scanner.peekNextButOne().isKeyword("class")
) {
// 'void' '.' 'class'
this.eatToken();
Location location = this.location();
this.eatToken();
return new Java.ClassLiteral(location, new Java.BasicType(location, Java.BasicType.VOID));
}
this.throwCompileException("\"void\" encountered in wrong context");
}