[java] Rename ASTTypeTestPattern -> ASTTypePattern, remove @Experimental
With JEP 394 / Java16, this production has been renamed. Pattern Matching for Instanceof is now a standard feature, therefore the AST node is not experimental anymore.
This commit is contained in:
@ -381,8 +381,8 @@ public class JavaParser {
|
||||
}
|
||||
|
||||
private void checkforBadInstanceOfPattern() {
|
||||
if (!(jdkVersion == 14 && preview || jdkVersion == 15 && preview || jdkVersion == 16)) {
|
||||
throwParseException("Pattern Matching for instanceof is only supported with Java 14 Preview and Java 15 Preview and Java 16");
|
||||
if (!(jdkVersion == 14 && preview || jdkVersion == 15 && preview || jdkVersion >= 16)) {
|
||||
throwParseException("Pattern Matching for instanceof is only supported with Java 14 Preview and Java 15 Preview and Java >= 16");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1685,7 +1685,7 @@ void EqualityExpression() #EqualityExpression(>1):
|
||||
InstanceOfExpression() ( LOOKAHEAD(2) ( "==" {jjtThis.setImage("==");} | "!=" {jjtThis.setImage("!=");} ) InstanceOfExpression() )*
|
||||
}
|
||||
|
||||
void TypePattern() #TypeTestPattern:
|
||||
void TypePattern():
|
||||
{}
|
||||
{
|
||||
( "final" {jjtThis.setFinal(true);} | Annotation() )*
|
||||
@ -1702,7 +1702,7 @@ void InstanceOfExpression() #InstanceOfExpression(>1):
|
||||
LOOKAHEAD("final" | "@") {checkforBadInstanceOfPattern();} TypePattern()
|
||||
|
|
||||
Type()
|
||||
[ {checkforBadInstanceOfPattern();} VariableDeclaratorId() #TypeTestPattern(2) ]
|
||||
[ {checkforBadInstanceOfPattern();} VariableDeclaratorId() #TypePattern(2) ]
|
||||
)
|
||||
]
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class ASTInstanceOfExpression extends AbstractJavaTypeNode {
|
||||
public ASTType getTypeNode() {
|
||||
JavaNode child = getChild(1);
|
||||
return child instanceof ASTType ? (ASTType) child
|
||||
: ((ASTTypeTestPattern) child).getTypeNode();
|
||||
: ((ASTTypePattern) child).getTypeNode();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
|
||||
/**
|
||||
* A pattern (for pattern matching constructs like {@link ASTInstanceOfExpression InstanceOfExpression}).
|
||||
* This is a JDK 16 feature.
|
||||
@ -16,13 +14,12 @@ import net.sourceforge.pmd.annotation.Experimental;
|
||||
*
|
||||
* <pre class="grammar">
|
||||
*
|
||||
* Pattern ::= {@link ASTTypeTestPattern TypeTestPattern}
|
||||
* Pattern ::= {@link ASTTypePattern TypePattern}
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://openjdk.java.net/jeps/394">JEP 394: Pattern Matching for instanceof</a>
|
||||
*/
|
||||
@Experimental
|
||||
public interface ASTPattern extends JavaNode {
|
||||
|
||||
}
|
||||
|
@ -6,30 +6,27 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
|
||||
/**
|
||||
* A type pattern (JDK16). This can be found on
|
||||
* the right-hand side of an {@link ASTInstanceOfExpression InstanceOfExpression}.
|
||||
*
|
||||
* <pre class="grammar">
|
||||
*
|
||||
* TypeTestPattern ::= ( "final" | {@linkplain ASTAnnotation Annotation} )* {@linkplain ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
|
||||
* TypePattern ::= ( "final" | {@linkplain ASTAnnotation Annotation} )* {@linkplain ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @see <a href="https://openjdk.java.net/jeps/394">JEP 394: Pattern Matching for instanceof</a>
|
||||
*/
|
||||
@Experimental
|
||||
public final class ASTTypeTestPattern extends AbstractJavaAnnotatableNode implements ASTPattern {
|
||||
public final class ASTTypePattern extends AbstractJavaAnnotatableNode implements ASTPattern {
|
||||
|
||||
private boolean isFinal;
|
||||
|
||||
ASTTypeTestPattern(int id) {
|
||||
ASTTypePattern(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
ASTTypeTestPattern(JavaParser p, int id) {
|
||||
ASTTypePattern(JavaParser p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute;
|
||||
@ -201,8 +200,8 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getParent() instanceof ASTTypeTestPattern) {
|
||||
return ((ASTTypeTestPattern) getParent()).isFinal();
|
||||
if (getParent() instanceof ASTTypePattern) {
|
||||
return ((ASTTypePattern) getParent()).isFinal();
|
||||
}
|
||||
|
||||
if (getParent() instanceof ASTRecordComponent) {
|
||||
@ -277,7 +276,6 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim
|
||||
* Returns true if this is a binding variable in a
|
||||
* {@linkplain ASTPattern pattern}.
|
||||
*/
|
||||
@Experimental
|
||||
public boolean isPatternBinding() {
|
||||
return getParent() instanceof ASTPattern;
|
||||
}
|
||||
@ -331,8 +329,8 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim
|
||||
} else if (isTypeInferred()) {
|
||||
// lambda expression with lax types. The type is inferred...
|
||||
return null;
|
||||
} else if (getParent() instanceof ASTTypeTestPattern) {
|
||||
return ((ASTTypeTestPattern) getParent()).getTypeNode();
|
||||
} else if (getParent() instanceof ASTTypePattern) {
|
||||
return ((ASTTypePattern) getParent()).getTypeNode();
|
||||
} else if (getParent() instanceof ASTRecordComponent) {
|
||||
return ((ASTRecordComponent) getParent()).getTypeNode();
|
||||
} else {
|
||||
|
@ -903,7 +903,7 @@ public class JavaParserDecoratedVisitor implements JavaParserVisitor {
|
||||
|
||||
@Override
|
||||
@Experimental
|
||||
public Object visit(ASTTypeTestPattern node, Object data) {
|
||||
public Object visit(ASTTypePattern node, Object data) {
|
||||
visitor.visit(node, data);
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ public class JavaParserVisitorAdapter implements JavaParserVisitor {
|
||||
|
||||
@Override
|
||||
@Experimental
|
||||
public Object visit(ASTTypeTestPattern node, Object data) {
|
||||
public Object visit(ASTTypePattern node, Object data) {
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
||||
|
@ -762,7 +762,7 @@ public class JavaParserVisitorDecorator implements JavaParserControllessVisitor
|
||||
|
||||
@Override
|
||||
@Experimental
|
||||
public Object visit(ASTTypeTestPattern node, Object data) {
|
||||
public Object visit(ASTTypePattern node, Object data) {
|
||||
return visitor.visit(node, data);
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTTypeBound;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeParameter;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeParameters;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypeTestPattern;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTTypePattern;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpressionNotPlusMinus;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
|
||||
@ -839,7 +839,7 @@ public abstract class AbstractJavaRule extends AbstractRule implements JavaParse
|
||||
|
||||
@Override
|
||||
@Experimental
|
||||
public Object visit(ASTTypeTestPattern node, Object data) {
|
||||
public Object visit(ASTTypePattern node, Object data) {
|
||||
return visit((JavaNode) node, data);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class Java14PreviewTest {
|
||||
List<ASTInstanceOfExpression> instanceOfExpressions = compilationUnit.findDescendantsOfType(ASTInstanceOfExpression.class);
|
||||
Assert.assertEquals(4, instanceOfExpressions.size());
|
||||
for (ASTInstanceOfExpression expr : instanceOfExpressions) {
|
||||
Assert.assertTrue(expr.getChild(1) instanceof ASTTypeTestPattern);
|
||||
Assert.assertTrue(expr.getChild(1) instanceof ASTTypePattern);
|
||||
ASTVariableDeclaratorId variable = expr.getChild(1).getFirstChildOfType(ASTVariableDeclaratorId.class);
|
||||
Assert.assertEquals(String.class, variable.getType());
|
||||
Assert.assertEquals("s", variable.getVariableName());
|
||||
|
@ -15,7 +15,7 @@ class ASTPatternTest : ParserTestSpec({
|
||||
parserTest("Test patterns only available on JDK 14+15 (preview) and JDK16 and JDK16 (preview)",
|
||||
javaVersions = JavaVersion.values().asList().minus(J14__PREVIEW).minus(J15__PREVIEW).minus(J16).minus(J16__PREVIEW)) {
|
||||
|
||||
expectParseException("Pattern Matching for instanceof is only supported with Java 14 Preview and Java 15 Preview and Java 16") {
|
||||
expectParseException("Pattern Matching for instanceof is only supported with Java 14 Preview and Java 15 Preview and Java >= 16") {
|
||||
parseAstExpression("obj instanceof Class c")
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ class ASTPatternTest : ParserTestSpec({
|
||||
|
||||
"obj instanceof Class c" should matchExpr<ASTInstanceOfExpression> {
|
||||
unspecifiedChild()
|
||||
child<ASTTypeTestPattern> {
|
||||
child<ASTTypePattern> {
|
||||
it.isAnnotationPresent("java.lang.Deprecated") shouldBe false
|
||||
it::getTypeNode typeShouldBe child(ignoreChildren = true) {}
|
||||
|
||||
@ -40,7 +40,7 @@ class ASTPatternTest : ParserTestSpec({
|
||||
|
||||
"obj instanceof final Class c" should matchExpr<ASTInstanceOfExpression> {
|
||||
unspecifiedChild()
|
||||
child<ASTTypeTestPattern> {
|
||||
child<ASTTypePattern> {
|
||||
it.isAnnotationPresent("java.lang.Deprecated") shouldBe false
|
||||
it::getTypeNode typeShouldBe child(ignoreChildren = true) {}
|
||||
|
||||
@ -53,7 +53,7 @@ class ASTPatternTest : ParserTestSpec({
|
||||
|
||||
"obj instanceof @Deprecated Class c" should matchExpr<ASTInstanceOfExpression> {
|
||||
unspecifiedChild()
|
||||
child<ASTTypeTestPattern> {
|
||||
child<ASTTypePattern> {
|
||||
child<ASTAnnotation>(ignoreChildren = true) {
|
||||
it.annotationName shouldBe "Deprecated"
|
||||
}
|
||||
|
@ -40,7 +40,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -109,7 +109,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -175,7 +175,7 @@
|
||||
| | | | +- PrimaryExpression[]
|
||||
| | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | | +- Name[@Image = "obj"]
|
||||
| | | | +- TypeTestPattern[]
|
||||
| | | | +- TypePattern[]
|
||||
| | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -224,7 +224,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
|
@ -40,7 +40,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -150,7 +150,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -216,7 +216,7 @@
|
||||
| | | | +- PrimaryExpression[]
|
||||
| | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | | +- Name[@Image = "obj"]
|
||||
| | | | +- TypeTestPattern[]
|
||||
| | | | +- TypePattern[]
|
||||
| | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -265,7 +265,7 @@
|
||||
| | | | +- PrimaryExpression[]
|
||||
| | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | | +- Name[@Image = "obj"]
|
||||
| | | | +- TypeTestPattern[]
|
||||
| | | | +- TypePattern[]
|
||||
| | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -313,7 +313,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "String"]
|
||||
| | | | +- ReferenceType[@Array = false, @ArrayDepth = 0]
|
||||
| | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "String", @ReferenceToClassSameCompilationUnit = false]
|
||||
@ -378,7 +378,7 @@
|
||||
| | | +- PrimaryExpression[]
|
||||
| | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | | +- Name[@Image = "obj"]
|
||||
| | | +- TypeTestPattern[]
|
||||
| | | +- TypePattern[]
|
||||
| | | +- Annotation[@AnnotationName = "Deprecated"]
|
||||
| | | | +- MarkerAnnotation[@AnnotationName = "Deprecated"]
|
||||
| | | | +- Name[@Image = "Deprecated"]
|
||||
@ -446,7 +446,7 @@
|
||||
| | +- PrimaryExpression[]
|
||||
| | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false]
|
||||
| | | +- Name[@Image = "obj"]
|
||||
| | +- TypeTestPattern[]
|
||||
| | +- TypePattern[]
|
||||
| | +- Annotation[@AnnotationName = "Deprecated"]
|
||||
| | | +- MarkerAnnotation[@AnnotationName = "Deprecated"]
|
||||
| | | +- Name[@Image = "Deprecated"]
|
||||
|
Reference in New Issue
Block a user