Fix some corner cases found in jdk12 sources
This commit is contained in:
@ -2521,14 +2521,13 @@ void PrimaryPrefix() #void :
|
||||
// This describes the cases where the PrimaryPrefix may fall
|
||||
// into PrimaryStep2. Notice that type arguments is still possible,
|
||||
// as well as annotations ("@") before an annotated array type.
|
||||
// If we are in an explicit constructor invocation, then super or
|
||||
// this are disallowed.
|
||||
// If we are in an explicit constructor invocation, then super is disallowed.
|
||||
private void Step2Lahead() #void:
|
||||
{}
|
||||
{
|
||||
"::" | "(" | "@" | "[" | TypeArguments()
|
||||
| LOOKAHEAD({!inExplicitConstructorInvoc}) "."
|
||||
| LOOKAHEAD({inExplicitConstructorInvoc}) "." ("class" | <IDENTIFIER> | TypeArguments() <IDENTIFIER> | "new") // not super or this in this case
|
||||
| LOOKAHEAD({inExplicitConstructorInvoc}) "." ("class" | <IDENTIFIER> | TypeArguments() <IDENTIFIER> | "new" | "this") // not super in this case
|
||||
}
|
||||
|
||||
private void SuffixLAhead() #void:
|
||||
@ -2548,8 +2547,8 @@ private void SuffixLAhead() #void:
|
||||
void PrimaryStep2() #void:
|
||||
{}
|
||||
{
|
||||
// Can't be followed by array dims, because it would raise an error for generic array creation
|
||||
{forceTypeContext();} TypeArguments() {injectTop();} ( "." ClassTypeSegment() )* MethodReference()
|
||||
// If the class is a parameterised type, then we can only expect a method reference
|
||||
{forceTypeContext();} TypeArguments() {injectTop();} ( "." ClassTypeSegment() )* [ Dims() #ArrayType(2) ] MethodReference()
|
||||
| MethodReference()
|
||||
| ArgumentList() #MethodCall(2)
|
||||
| "." (
|
||||
|
@ -41,7 +41,9 @@ public enum BinaryOp {
|
||||
|
||||
// shift
|
||||
LEFT_SHIFT("<<"),
|
||||
/** Token {@code >> } */
|
||||
RIGHT_SHIFT(">>"),
|
||||
/** Token {@code >>>} */
|
||||
UNSIGNED_RIGHT_SHIFT(">>>"),
|
||||
|
||||
// additive
|
||||
|
@ -147,6 +147,24 @@ class ASTExplicitConstructorInvocationTest : ParserTestSpec({
|
||||
}
|
||||
}
|
||||
|
||||
"public TabbedPaneLayout() { MetalTabbedPaneUI.this.super(); }" should matchDeclaration<ASTConstructorDeclaration> {
|
||||
|
||||
child<ASTFormalParameters> { }
|
||||
|
||||
child<ASTExplicitConstructorInvocation> {
|
||||
it::isThis shouldBe false
|
||||
it::isSuper shouldBe true
|
||||
it::isQualified shouldBe true
|
||||
it::getExplicitTypeArguments shouldBe null
|
||||
it::getArgumentCount shouldBe 0
|
||||
|
||||
it::getLhsExpression shouldBe child<ASTThisExpression>(ignoreChildren = true) { }
|
||||
|
||||
|
||||
it::getArgumentsList shouldBe child { }
|
||||
}
|
||||
}
|
||||
|
||||
// An explicit constructor invocation statement in a constructor body may not refer to any instance
|
||||
// variables or instance methods or inner classes declared in this class or any superclass, or use
|
||||
// this or super in any expression; otherwise, a compile-time error occurs.
|
||||
|
@ -78,7 +78,7 @@ class ASTMethodCallTest : ParserTestSpec({
|
||||
child<ASTLambdaExpression>(ignoreChildren = true) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"foo.bar(foo::bar).foreach(System.out::println)" should matchExpr<ASTMethodCall> {
|
||||
|
||||
it::getMethodName shouldBe "foreach"
|
||||
|
@ -165,6 +165,23 @@ class ASTMethodReferenceTest : ParserTestSpec({
|
||||
}
|
||||
}
|
||||
|
||||
"Class<?>[]::new" should parseAs {
|
||||
constructorRef {
|
||||
it::getTypeArguments shouldBe null
|
||||
|
||||
arrayType {
|
||||
classType("Class") {
|
||||
typeArgList {
|
||||
child<ASTWildcardType> { }
|
||||
}
|
||||
}
|
||||
it::getDimensions shouldBe child {
|
||||
arrayDim()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"ArrayList::<String>new" should parseAs {
|
||||
constructorRef {
|
||||
val lhs = classType("ArrayList")
|
||||
|
@ -36,6 +36,19 @@ class ASTShiftExpressionTest : ParserTestSpec({
|
||||
child<ASTNumericLiteral> {}
|
||||
}
|
||||
|
||||
"i < width >> 1" should matchExpr<ASTRelationalExpression> {
|
||||
it::getOp shouldBe BinaryOp.LE
|
||||
|
||||
variableRef("i")
|
||||
|
||||
child<ASTShiftExpression> {
|
||||
it::getOp shouldBe BinaryOp.RIGHT_SHIFT
|
||||
|
||||
variableRef("width")
|
||||
int(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parserTest("Changing operators should push a new node") {
|
||||
|
Reference in New Issue
Block a user