diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index b067a3678f..65d99167b2 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1770,7 +1770,7 @@ void PrimaryPattern() #void: {} { TypePattern() - | "(" Pattern() ")" + | "(" Pattern() ")" { AstImplUtil.bumpParenDepth((ASTPattern) jjtree.peekNode()); } } void TypePattern(): diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTGuardedPattern.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTGuardedPattern.java index e4701c18de..071bf5ebb6 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTGuardedPattern.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTGuardedPattern.java @@ -21,6 +21,8 @@ import net.sourceforge.pmd.annotation.Experimental; @Experimental public final class ASTGuardedPattern extends AbstractJavaNode implements ASTPattern { + private int parenDepth; + ASTGuardedPattern(int id) { super(id); } @@ -42,4 +44,14 @@ public final class ASTGuardedPattern extends AbstractJavaNode implements ASTPatt public JavaNode getGuard() { return getChild(1); } + + void bumpParenDepth() { + parenDepth++; + } + + @Override + @Experimental + public int getParenthesisDepth() { + return parenDepth; + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPattern.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPattern.java index d14f584266..122f5294dc 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPattern.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTPattern.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.java.ast; +import net.sourceforge.pmd.annotation.Experimental; + /** * A pattern (for pattern matching constructs like {@link ASTInstanceOfExpression InstanceOfExpression} * or within a {@link ASTSwitchLabel}). This is a JDK 16 feature. @@ -23,4 +25,10 @@ package net.sourceforge.pmd.lang.java.ast; */ public interface ASTPattern extends JavaNode { + /** + * Returns the number of parenthesis levels around this pattern. + * If this method returns 0, then no parentheses are present. + */ + @Experimental + int getParenthesisDepth(); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypePattern.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypePattern.java index 2c7c74d576..4994d6a278 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypePattern.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTTypePattern.java @@ -6,6 +6,8 @@ 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}. @@ -21,6 +23,7 @@ import java.util.List; public final class ASTTypePattern extends AbstractJavaAnnotatableNode implements ASTPattern { private boolean isFinal; + private int parenDepth; ASTTypePattern(int id) { super(id); @@ -60,4 +63,14 @@ public final class ASTTypePattern extends AbstractJavaAnnotatableNode implements boolean isFinal() { return isFinal; } + + void bumpParenDepth() { + parenDepth++; + } + + @Override + @Experimental + public int getParenthesisDepth() { + return parenDepth; + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstImplUtil.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstImplUtil.java new file mode 100644 index 0000000000..beef16084a --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstImplUtil.java @@ -0,0 +1,25 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.ast; + +/** + * KEEP PRIVATE + */ +final class AstImplUtil { + + private AstImplUtil() { + } + + static void bumpParenDepth(ASTPattern pattern) { + assert pattern instanceof ASTTypePattern || pattern instanceof ASTGuardedPattern + : pattern.getClass() + " doesn't have parenDepth attribute!"; + + if (pattern instanceof ASTTypePattern) { + ((ASTTypePattern) pattern).bumpParenDepth(); + } else if (pattern instanceof ASTGuardedPattern) { + ((ASTGuardedPattern) pattern).bumpParenDepth(); + } + } +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java16/PatternMatchingInstanceof.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java16/PatternMatchingInstanceof.txt index 29a891122f..07cc3abbd3 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java16/PatternMatchingInstanceof.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java16/PatternMatchingInstanceof.txt @@ -40,7 +40,7 @@ | | | +- PrimaryExpression[] | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | | | +- Name[@Image = "obj"] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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"] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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"] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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"] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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"] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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"] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Annotation[@AnnotationName = "Deprecated"] | | | | +- MarkerAnnotation[@AnnotationName = "Deprecated"] | | | | +- Name[@Image = "Deprecated"] @@ -446,7 +446,7 @@ | | +- PrimaryExpression[] | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | | +- Name[@Image = "obj"] - | | +- TypePattern[] + | | +- TypePattern[@ParenthesisDepth = 0] | | +- Annotation[@AnnotationName = "Deprecated"] | | | +- MarkerAnnotation[@AnnotationName = "Deprecated"] | | | +- Name[@Image = "Deprecated"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/DealingWithNull.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/DealingWithNull.txt index c6d7db6831..e4b4cf76e1 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/DealingWithNull.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/DealingWithNull.txt @@ -36,7 +36,7 @@ | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""null!"", @FloatLiteral = false, @Image = ""null!"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""null!"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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] @@ -95,7 +95,7 @@ | | +- Arguments[@ArgumentCount = 0, @Size = 0] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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] @@ -117,7 +117,7 @@ | | +- Name[@Image = "s"] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Integer"] | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Integer", @ReferenceToClassSameCompilationUnit = false] @@ -167,7 +167,7 @@ | | +- SwitchLabel[@Default = false] | | | +- NullLiteral[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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] @@ -215,7 +215,7 @@ | | +- SwitchLabeledExpression[] | | | +- SwitchLabel[@Default = false] | | | | +- NullLiteral[] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/EnhancedTypeCheckingSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/EnhancedTypeCheckingSwitch.txt index 3228d0f965..e14553c038 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/EnhancedTypeCheckingSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/EnhancedTypeCheckingSwitch.txt @@ -36,7 +36,7 @@ | | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""null"", @FloatLiteral = false, @Image = ""null"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""null"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | | +- SwitchLabeledExpression[] | | | +- SwitchLabel[@Default = false] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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] @@ -54,7 +54,7 @@ | | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""String"", @FloatLiteral = false, @Image = ""String"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""String"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | | +- SwitchLabeledExpression[] | | | +- SwitchLabel[@Default = false] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Color"] | | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Color", @ReferenceToClassSameCompilationUnit = true] @@ -82,7 +82,7 @@ | | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = "" values"", @FloatLiteral = false, @Image = "" values"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = "" values"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | | +- SwitchLabeledExpression[] | | | +- SwitchLabel[@Default = false] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Point"] | | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Point", @ReferenceToClassSameCompilationUnit = false] @@ -106,7 +106,7 @@ | | | +- Arguments[@ArgumentCount = 0, @Size = 0] | | +- SwitchLabeledExpression[] | | | +- SwitchLabel[@Default = false] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- Type[@Array = true, @ArrayDepth = 1, @ArrayType = true, @TypeImage = "int"] | | | | | +- ReferenceType[@Array = true, @ArrayDepth = 1] | | | | | +- PrimitiveType[@Array = false, @ArrayDepth = 0, @Boolean = false, @Image = "int"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.java index 0621da8b3e..fd4c1d58d5 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.java +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.java @@ -13,6 +13,8 @@ public class GuardedAndParenthesizedPatterns { case String s && (s.length() == 1) -> System.out.println("single char string"); case String s -> System.out.println("string"); case (Integer i && i.intValue() == 1) -> System.out.println("integer 1"); + case (((Long l && l.longValue() == 1L))) -> System.out.println("long 1 with parens"); + case (((Double d))) -> System.out.println("double with parens"); default -> System.out.println("default case"); } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.txt index a84f1f26d0..f42b450835 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/GuardedAndParenthesizedPatterns.txt @@ -22,8 +22,8 @@ | | +- Name[@Image = "o"] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- GuardedPattern[] - | | | +- TypePattern[] + | | | +- GuardedPattern[@ParenthesisDepth = 0] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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] @@ -53,7 +53,7 @@ | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""single char string"", @FloatLiteral = false, @Image = ""single char string"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""single char string"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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] @@ -71,8 +71,8 @@ | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""string"", @FloatLiteral = false, @Image = ""string"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""string"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- GuardedPattern[] - | | | +- TypePattern[] + | | | +- GuardedPattern[@ParenthesisDepth = 1] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Integer"] | | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Integer", @ReferenceToClassSameCompilationUnit = false] @@ -98,6 +98,52 @@ | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""integer 1"", @FloatLiteral = false, @Image = ""integer 1"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""integer 1"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | +- SwitchLabeledExpression[] + | | +- SwitchLabel[@Default = false] + | | | +- GuardedPattern[@ParenthesisDepth = 3] + | | | +- TypePattern[@ParenthesisDepth = 0] + | | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Long"] + | | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] + | | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Long", @ReferenceToClassSameCompilationUnit = false] + | | | | +- VariableDeclaratorId[@Array = false, @ArrayDepth = 0, @ArrayType = false, @ExceptionBlockParameter = false, @ExplicitReceiverParameter = false, @Field = false, @Final = false, @ForeachVariable = false, @FormalParameter = false, @Image = "l", @LambdaParameter = false, @LocalVariable = false, @Name = "l", @PatternBinding = true, @ResourceDeclaration = false, @TypeInferred = false, @VariableName = "l"] + | | | +- EqualityExpression[@Image = "==", @Operator = "=="] + | | | +- PrimaryExpression[] + | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] + | | | | | +- Name[@Image = "l.longValue"] + | | | | +- PrimarySuffix[@ArgumentCount = 0, @Arguments = true, @ArrayDereference = false] + | | | | +- Arguments[@ArgumentCount = 0, @Size = 0] + | | | +- PrimaryExpression[] + | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] + | | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = "1L", @FloatLiteral = false, @Image = "1L", @IntLiteral = false, @LongLiteral = true, @SingleCharacterStringLiteral = false, @StringLiteral = false, @TextBlock = false, @TextBlockContent = "1L", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 1, @ValueAsLong = 1] + | | +- Expression[@StandAlonePrimitive = false] + | | +- PrimaryExpression[] + | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] + | | | +- Name[@Image = "System.out.println"] + | | +- PrimarySuffix[@ArgumentCount = 1, @Arguments = true, @ArrayDereference = false] + | | +- Arguments[@ArgumentCount = 1, @Size = 1] + | | +- ArgumentList[@Size = 1] + | | +- Expression[@StandAlonePrimitive = false] + | | +- PrimaryExpression[] + | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] + | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""long 1 with parens"", @FloatLiteral = false, @Image = ""long 1 with parens"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""long 1 with parens"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] + | +- SwitchLabeledExpression[] + | | +- SwitchLabel[@Default = false] + | | | +- TypePattern[@ParenthesisDepth = 3] + | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Double"] + | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] + | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Double", @ReferenceToClassSameCompilationUnit = false] + | | | +- VariableDeclaratorId[@Array = false, @ArrayDepth = 0, @ArrayType = false, @ExceptionBlockParameter = false, @ExplicitReceiverParameter = false, @Field = false, @Final = false, @ForeachVariable = false, @FormalParameter = false, @Image = "d", @LambdaParameter = false, @LocalVariable = false, @Name = "d", @PatternBinding = true, @ResourceDeclaration = false, @TypeInferred = false, @VariableName = "d"] + | | +- Expression[@StandAlonePrimitive = false] + | | +- PrimaryExpression[] + | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] + | | | +- Name[@Image = "System.out.println"] + | | +- PrimarySuffix[@ArgumentCount = 1, @Arguments = true, @ArrayDereference = false] + | | +- Arguments[@ArgumentCount = 1, @Size = 1] + | | +- ArgumentList[@Size = 1] + | | +- Expression[@StandAlonePrimitive = false] + | | +- PrimaryExpression[] + | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] + | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""double with parens"", @FloatLiteral = false, @Image = ""double with parens"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""double with parens"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] + | +- SwitchLabeledExpression[] | +- SwitchLabel[@Default = true] | +- Expression[@StandAlonePrimitive = false] | +- PrimaryExpression[] @@ -130,7 +176,7 @@ | | | | +- PrimaryExpression[] | | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | | | | +- Name[@Image = "o"] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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] @@ -180,7 +226,7 @@ | | | | +- PrimaryExpression[] | | | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | | | | +- Name[@Image = "o"] - | | | | +- TypePattern[] + | | | | +- TypePattern[@ParenthesisDepth = 0] | | | | +- 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] @@ -217,8 +263,8 @@ | | +- PrimaryExpression[] | | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | | +- Name[@Image = "o"] - | | +- GuardedPattern[] - | | +- TypePattern[] + | | +- GuardedPattern[@ParenthesisDepth = 1] + | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/PatternsInSwitchLabels.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/PatternsInSwitchLabels.txt index 2d94cf8eaf..c13492cb44 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/PatternsInSwitchLabels.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/PatternsInSwitchLabels.txt @@ -41,7 +41,7 @@ | | +- Name[@Image = "o"] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Integer"] | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Integer", @ReferenceToClassSameCompilationUnit = false] @@ -63,7 +63,7 @@ | | +- Name[@Image = "i"] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Long"] | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Long", @ReferenceToClassSameCompilationUnit = false] @@ -85,7 +85,7 @@ | | +- Name[@Image = "l"] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Double"] | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Double", @ReferenceToClassSameCompilationUnit = false] @@ -107,7 +107,7 @@ | | +- Name[@Image = "d"] | +- SwitchLabeledExpression[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- 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] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/ScopeOfPatternVariableDeclarations.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/ScopeOfPatternVariableDeclarations.txt index c244483b7b..2d8dd4158e 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/ScopeOfPatternVariableDeclarations.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java17p/ScopeOfPatternVariableDeclarations.txt @@ -22,7 +22,7 @@ | | +- Name[@Image = "o"] | +- SwitchLabeledBlock[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Character"] | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Character", @ReferenceToClassSameCompilationUnit = false] @@ -71,7 +71,7 @@ | | +- Literal[@CharLiteral = false, @DoubleLiteral = false, @EscapedStringLiteral = ""Character"", @FloatLiteral = false, @Image = ""Character"", @IntLiteral = false, @LongLiteral = false, @SingleCharacterStringLiteral = false, @StringLiteral = true, @TextBlock = false, @TextBlockContent = ""Character"", @ValueAsDouble = NaN, @ValueAsFloat = NaN, @ValueAsInt = 0, @ValueAsLong = 0] | +- SwitchLabeledThrowStatement[] | | +- SwitchLabel[@Default = false] - | | | +- TypePattern[] + | | | +- TypePattern[@ParenthesisDepth = 0] | | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Integer"] | | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Integer", @ReferenceToClassSameCompilationUnit = false] @@ -119,7 +119,7 @@ | | +- PrimaryPrefix[@SuperModifier = false, @ThisModifier = false] | | +- Name[@Image = "o"] | +- SwitchLabel[@Default = false] - | | +- TypePattern[] + | | +- TypePattern[@ParenthesisDepth = 0] | | +- Type[@Array = false, @ArrayDepth = 0, @ArrayType = false, @TypeImage = "Character"] | | | +- ReferenceType[@Array = false, @ArrayDepth = 0] | | | +- ClassOrInterfaceType[@AnonymousClass = false, @Array = false, @ArrayDepth = 0, @Image = "Character", @ReferenceToClassSameCompilationUnit = false]