From e27e595e582ee3462db1a6bc07cd38a4476331eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 26 Feb 2022 23:56:44 +0100 Subject: [PATCH] Add back tests that disappeared by mistake --- .../pmd/lang/java/ast/ParserCornersTest.java | 14 +- .../java14/MultipleCaseLabels.java | 25 ++ .../java14/MultipleCaseLabels.txt | 113 ++++++ .../java14/SimpleSwitchExpressions.java | 35 ++ .../java14/SimpleSwitchExpressions.txt | 131 +++++++ .../java14/SwitchExpressions.java | 90 +++++ .../java14/SwitchExpressions.txt | 326 ++++++++++++++++++ .../jdkversiontests/java14/SwitchRules.java | 25 ++ .../jdkversiontests/java14/SwitchRules.txt | 113 ++++++ .../jdkversiontests/java14/TextBlocks.java | 113 ++++++ .../java14/YieldStatements.txt | 83 +++++ 11 files changed, 1061 insertions(+), 7 deletions(-) create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/TextBlocks.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java index 1c28c9c3f1..422a620615 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java @@ -136,11 +136,11 @@ public class ParserCornersTest extends BaseJavaTreeDumpTest { */ @Test public void testGenericsProblem() { - String code = "public class Test {\n" + - " public void test() {\n" + - " String o = super. doStuff(\"\");\n" + - " }\n" + - "}"; + String code = "public class Test {\n" + + " public void test() {\n" + + " String o = super. doStuff(\"\");\n" + + " }\n" + + "}"; java5.parse(code); java7.parse(code); } @@ -266,10 +266,10 @@ public class ParserCornersTest extends BaseJavaTreeDumpTest { @Test public void testMethodReferenceConfused() { ASTCompilationUnit ast = java.parseResource("MethodReferenceConfused.java", "10"); - ASTVariableDeclaratorId someVarNameSameAsMethodReference = AstTestUtil.varId(ast, "someVarNameSameAsMethodReference"); + ASTVariableDeclaratorId varWithMethodName = AstTestUtil.varId(ast, "method"); ASTVariableDeclaratorId someObject = AstTestUtil.varId(ast, "someObject"); - assertThat(someVarNameSameAsMethodReference.getLocalUsages(), empty()); + assertThat(varWithMethodName.getLocalUsages(), empty()); assertThat(someObject.getLocalUsages(), hasSize(1)); ASTNamedReferenceExpr usage = someObject.getLocalUsages().get(0); assertThat(usage.getParent(), instanceOf(ASTCastExpression.class)); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.java new file mode 100644 index 0000000000..b578e8c475 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.java @@ -0,0 +1,25 @@ +/** + * + * @see JEP 325: Switch Expressions (Preview) + */ +public class MultipleCaseLabels { + private static final int MONDAY = 1; + private static final int TUESDAY = 2; + private static final int WEDNESDAY = 3; + private static final int THURSDAY = 4; + private static final int FRIDAY = 5; + private static final int SATURDAY = 6; + private static final int SUNDAY = 7; + + + public static void main(String[] args) { + int day = THURSDAY; + + switch (day) { + case MONDAY, FRIDAY, SUNDAY: System.out.println(" 6"); break; + case TUESDAY : System.out.println(" 7"); break; + case THURSDAY, SATURDAY : System.out.println(" 8"); break; + case WEDNESDAY : System.out.println(" 9"); break; + } + } +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt new file mode 100644 index 0000000000..2c7b60fa5a --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt @@ -0,0 +1,113 @@ ++- CompilationUnit[@PackageName = ""] + +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "MultipleCaseLabels", @CanonicalName = "MultipleCaseLabels", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "false", @Record = "false", @RegularClass = "true", @RegularInterface = "false", @SimpleName = "MultipleCaseLabels", @TopLevel = "true", @Visibility = "public"] + +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] + +- ClassOrInterfaceBody[@Empty = "false", @Size = "8"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "MONDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "MONDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "TUESDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "TUESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "WEDNESDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "WEDNESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "THURSDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "THURSDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "4", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "4.0", @ValueAsFloat = "4.0", @ValueAsInt = "4", @ValueAsLong = "4"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "FRIDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "FRIDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "5", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "5.0", @ValueAsFloat = "5.0", @ValueAsInt = "5", @ValueAsLong = "5"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "SATURDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SATURDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "6", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "6.0", @ValueAsFloat = "6.0", @ValueAsInt = "6", @ValueAsLong = "6"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "SUNDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SUNDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "7", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "7.0", @ValueAsFloat = "7.0", @ValueAsInt = "7", @ValueAsLong = "7"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "public", @Image = "main", @MainMethod = "true", @Name = "main", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] + +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"] + +- VoidType[] + +- FormalParameters[@Empty = "false", @Size = "1"] + | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- ArrayType[@ArrayDepth = "1"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] + | | +- ArrayDimensions[@Empty = "false", @Size = "1"] + | | +- ArrayTypeDim[@Varargs = "false"] + | +- VariableDeclaratorId[@ArrayType = "true", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "args", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + +- Block[@Empty = "false", @Size = "2", @containsComment = "false"] + +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "day"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "day", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- SwitchStatement[@DefaultCase = "false", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "true"] + +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- SwitchFallthroughBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 6", @Empty = "false", @Image = "\" 6\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- BreakStatement[@Label = null] + +- SwitchFallthroughBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 7", @Empty = "false", @Image = "\" 7\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- BreakStatement[@Label = null] + +- SwitchFallthroughBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 8", @Empty = "false", @Image = "\" 8\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- BreakStatement[@Label = null] + +- SwitchFallthroughBranch[@Default = "false"] + +- SwitchLabel[@Default = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 9", @Empty = "false", @Image = "\" 9\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- BreakStatement[@Label = null] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.java new file mode 100644 index 0000000000..c452ab0412 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.java @@ -0,0 +1,35 @@ +/** + * + * @see JEP 325: Switch Expressions (Preview) + */ +public class SimpleSwitchExpressions { + private static final int MONDAY = 1; + private static final int TUESDAY = 2; + private static final int WEDNESDAY = 3; + private static final int THURSDAY = 4; + private static final int FRIDAY = 5; + private static final int SATURDAY = 6; + private static final int SUNDAY = 7; + + + public static void main(String[] args) { + int day = FRIDAY; + + var numLetters = switch (day) { + case MONDAY, FRIDAY, SUNDAY -> 6; + case TUESDAY -> 7; + case THURSDAY, SATURDAY -> 8; + case WEDNESDAY -> 9; + default -> { + int k = day * 2; + int result = f(k); + yield result; + } + }; + System.out.printf("NumLetters: %d%n", numLetters); + } + + private static int f(int k) { + return k*3; + } +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt new file mode 100644 index 0000000000..419f680133 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt @@ -0,0 +1,131 @@ ++- CompilationUnit[@PackageName = ""] + +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "SimpleSwitchExpressions", @CanonicalName = "SimpleSwitchExpressions", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "false", @Record = "false", @RegularClass = "true", @RegularInterface = "false", @SimpleName = "SimpleSwitchExpressions", @TopLevel = "true", @Visibility = "public"] + +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] + +- ClassOrInterfaceBody[@Empty = "false", @Size = "9"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "MONDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "MONDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "TUESDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "TUESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "WEDNESDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "WEDNESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "THURSDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "THURSDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "4", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "4.0", @ValueAsFloat = "4.0", @ValueAsInt = "4", @ValueAsLong = "4"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "FRIDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "FRIDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "5", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "5.0", @ValueAsFloat = "5.0", @ValueAsInt = "5", @ValueAsLong = "5"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "SATURDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SATURDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "6", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "6.0", @ValueAsFloat = "6.0", @ValueAsInt = "6", @ValueAsLong = "6"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "SUNDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SUNDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "7", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "7.0", @ValueAsFloat = "7.0", @ValueAsInt = "7", @ValueAsLong = "7"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "public", @Image = "main", @MainMethod = "true", @Name = "main", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] + | +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"] + | +- VoidType[] + | +- FormalParameters[@Empty = "false", @Size = "1"] + | | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- ArrayType[@ArrayDepth = "1"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] + | | | +- ArrayDimensions[@Empty = "false", @Size = "1"] + | | | +- ArrayTypeDim[@Varargs = "false"] + | | +- VariableDeclaratorId[@ArrayType = "true", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "args", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- Block[@Empty = "false", @Size = "3", @containsComment = "false"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- PrimitiveType[@Kind = "int"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "day"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "day", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "true", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "numLetters"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "numLetters", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "local"] + | | +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "true", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "6", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "6.0", @ValueAsFloat = "6.0", @ValueAsInt = "6", @ValueAsLong = "6"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "7", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "7.0", @ValueAsFloat = "7.0", @ValueAsInt = "7", @ValueAsLong = "7"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "8", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "8.0", @ValueAsFloat = "8.0", @ValueAsInt = "8", @ValueAsLong = "8"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "9", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "9.0", @ValueAsFloat = "9.0", @ValueAsInt = "9", @ValueAsLong = "9"] + | | +- SwitchArrowBranch[@Default = "true"] + | | +- SwitchLabel[@Default = "true"] + | | +- Block[@Empty = "false", @Size = "3", @containsComment = "false"] + | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | | +- PrimitiveType[@Kind = "int"] + | | | +- VariableDeclarator[@Initializer = "true", @Name = "k"] + | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "k", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "*", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | | +- PrimitiveType[@Kind = "int"] + | | | +- VariableDeclarator[@Initializer = "true", @Name = "result"] + | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "result", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "f", @MethodName = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "k", @Name = "k", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- YieldStatement[] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "result", @Name = "result", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "printf", @MethodName = "printf", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "2"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "NumLetters: %d%n", @Empty = "false", @Image = "\"NumLetters: %d%n\"", @Length = "16", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "numLetters", @Name = "numLetters", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "private", @Image = "f", @Name = "f", @Overridden = "false", @Varargs = "false", @Visibility = "private", @Void = "false"] + +- ModifierList[@EffectiveModifiers = "{private, static}", @ExplicitModifiers = "{private, static}"] + +- PrimitiveType[@Kind = "int"] + +- FormalParameters[@Empty = "false", @Size = "1"] + | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "k", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + +- Block[@Empty = "false", @Size = "1", @containsComment = "false"] + +- ReturnStatement[] + +- InfixExpression[@CompileTimeConstant = "false", @Operator = "*", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "k", @Name = "k", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.java new file mode 100644 index 0000000000..5b29acbd4a --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.java @@ -0,0 +1,90 @@ +/** + * @see JEP 361: Switch Expressions (Standard) + */ +public class SwitchExpressions { + private enum Day { + MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; + } + + public static final int BAZ = 3; + + public static void main(String[] args) { + Day day = Day.THURSDAY; + + // SwitchStatement + switch (day) { + case MONDAY, FRIDAY, SUNDAY -> System.out.println(6); + case TUESDAY -> System.out.println(7); + case THURSDAY, SATURDAY -> System.out.println(8); + case WEDNESDAY -> System.out.println(9); + } + + // SwitchExpression + int numLetters = switch (day) { + case MONDAY, FRIDAY, SUNDAY -> 6; + case TUESDAY -> 7; + case THURSDAY, SATURDAY -> 8; + case WEDNESDAY -> 9; + }; + System.out.printf("numLetters=%d%n", numLetters); + + howMany(1); + howMany(2); + howMany(3); + + howManyExpr(1); + howManyExpr(2); + howManyExpr(3); + + // SwitchExpression + int j = switch (day) { + case MONDAY -> 0; + case TUESDAY -> 1; + default -> { + int k = day.toString().length(); + int result = f(k); + yield result; + } + }; + System.out.printf("j=%d%n", j); + + String s = "Foo"; + // SwitchExpression + int result = switch (s) { + case "Foo": + yield 1; + case "Bar": + yield 2; + case "Baz": + yield SwitchExpressions.BAZ; + default: + System.out.println("Neither Foo nor Bar, hmmm..."); + yield 0; + }; + System.out.printf("result=%d%n", result); + } + + private static void howMany(int k) { + // SwitchStatement + switch (k) { + case 1 -> System.out.println("one"); + case 2 -> System.out.println("two"); + default -> System.out.println("many"); + } + } + + private static void howManyExpr(int k) { + System.out.println( + // SwitchExpression + switch (k) { + case 1 -> "one"; + case 2 -> "two"; + default -> "many"; + } + ); + } + + private static int f(int k) { + return k*2; + } +} \ No newline at end of file diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt new file mode 100644 index 0000000000..f0335fd52e --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt @@ -0,0 +1,326 @@ ++- CompilationUnit[@PackageName = ""] + +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "SwitchExpressions", @CanonicalName = "SwitchExpressions", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "false", @Record = "false", @RegularClass = "true", @RegularInterface = "false", @SimpleName = "SwitchExpressions", @TopLevel = "true", @Visibility = "public"] + +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] + +- ClassOrInterfaceBody[@Empty = "false", @Size = "6"] + +- EnumDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "SwitchExpressions$Day", @CanonicalName = "SwitchExpressions.Day", @EffectiveVisibility = "private", @Enum = "true", @Final = "true", @Interface = "false", @Local = "false", @Nested = "true", @PackageName = "", @Record = "false", @RegularClass = "false", @RegularInterface = "false", @SimpleName = "Day", @TopLevel = "false", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private}"] + | +- EnumBody[@Empty = "false", @SeparatorSemi = "true", @Size = "7", @TrailingComma = "false"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "MONDAY", @MethodName = "new", @Name = "MONDAY", @Visibility = "public"] + | | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "MONDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "TUESDAY", @MethodName = "new", @Name = "TUESDAY", @Visibility = "public"] + | | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "TUESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "WEDNESDAY", @MethodName = "new", @Name = "WEDNESDAY", @Visibility = "public"] + | | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "WEDNESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "THURSDAY", @MethodName = "new", @Name = "THURSDAY", @Visibility = "public"] + | | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "THURSDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "FRIDAY", @MethodName = "new", @Name = "FRIDAY", @Visibility = "public"] + | | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "FRIDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "SATURDAY", @MethodName = "new", @Name = "SATURDAY", @Visibility = "public"] + | | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SATURDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + | +- EnumConstant[@AnonymousClass = "false", @EffectiveVisibility = "private", @Image = "SUNDAY", @MethodName = "new", @Name = "SUNDAY", @Visibility = "public"] + | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{}"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "true", @ExceptionBlockParameter = "false", @Field = "false", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SUNDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "true", @Visibility = "public"] + +- FieldDeclaration[@EffectiveVisibility = "public", @Visibility = "public"] + | +- ModifierList[@EffectiveModifiers = "{public, static, final}", @ExplicitModifiers = "{public, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "BAZ"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "public", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "BAZ", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "public"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "public", @Image = "main", @MainMethod = "true", @Name = "main", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] + | +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"] + | +- VoidType[] + | +- FormalParameters[@Empty = "false", @Size = "1"] + | | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- ArrayType[@ArrayDepth = "1"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] + | | | +- ArrayDimensions[@Empty = "false", @Size = "1"] + | | | +- ArrayTypeDim[@Varargs = "false"] + | | +- VariableDeclaratorId[@ArrayType = "true", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "args", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- Block[@Empty = "false", @Size = "15", @containsComment = "false"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Day"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "day"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "day", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Day"] + | +- SwitchStatement[@DefaultCase = "false", @EnumSwitch = "true", @ExhaustiveEnumSwitch = "true", @FallthroughSwitch = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "6", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "6.0", @ValueAsFloat = "6.0", @ValueAsInt = "6", @ValueAsLong = "6"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "7", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "7.0", @ValueAsFloat = "7.0", @ValueAsInt = "7", @ValueAsLong = "7"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "8", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "8.0", @ValueAsFloat = "8.0", @ValueAsInt = "8", @ValueAsLong = "8"] + | | +- SwitchArrowBranch[@Default = "false"] + | | +- SwitchLabel[@Default = "false"] + | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "9", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "9.0", @ValueAsFloat = "9.0", @ValueAsInt = "9", @ValueAsLong = "9"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- PrimitiveType[@Kind = "int"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "numLetters"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "numLetters", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "false", @EnumSwitch = "true", @ExhaustiveEnumSwitch = "true", @FallthroughSwitch = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "6", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "6.0", @ValueAsFloat = "6.0", @ValueAsInt = "6", @ValueAsLong = "6"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "7", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "7.0", @ValueAsFloat = "7.0", @ValueAsInt = "7", @ValueAsLong = "7"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "8", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "8.0", @ValueAsFloat = "8.0", @ValueAsInt = "8", @ValueAsLong = "8"] + | | +- SwitchArrowBranch[@Default = "false"] + | | +- SwitchLabel[@Default = "false"] + | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "9", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "9.0", @ValueAsFloat = "9.0", @ValueAsInt = "9", @ValueAsLong = "9"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "printf", @MethodName = "printf", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "2"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "numLetters=%d%n", @Empty = "false", @Image = "\"numLetters=%d%n\"", @Length = "15", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "numLetters", @Name = "numLetters", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "howMany", @MethodName = "howMany", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "howMany", @MethodName = "howMany", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "howMany", @MethodName = "howMany", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "howManyExpr", @MethodName = "howManyExpr", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "howManyExpr", @MethodName = "howManyExpr", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "howManyExpr", @MethodName = "howManyExpr", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- PrimitiveType[@Kind = "int"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "j"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "j", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "true", @EnumSwitch = "true", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "0", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "0.0", @ValueAsFloat = "0.0", @ValueAsInt = "0", @ValueAsLong = "0"] + | | +- SwitchArrowBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + | | +- SwitchArrowBranch[@Default = "true"] + | | +- SwitchLabel[@Default = "true"] + | | +- Block[@Empty = "false", @Size = "3", @containsComment = "false"] + | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | | +- PrimitiveType[@Kind = "int"] + | | | +- VariableDeclarator[@Initializer = "true", @Name = "k"] + | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "k", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "length", @MethodName = "length", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "toString", @MethodName = "toString", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- ArgumentList[@Empty = "true", @Size = "0"] + | | | +- ArgumentList[@Empty = "true", @Size = "0"] + | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | | +- PrimitiveType[@Kind = "int"] + | | | +- VariableDeclarator[@Initializer = "true", @Name = "result"] + | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "result", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "f", @MethodName = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "k", @Name = "k", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- YieldStatement[] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "result", @Name = "result", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ExpressionStatement[] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "printf", @MethodName = "printf", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "2"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "j=%d%n", @Empty = "false", @Image = "\"j=%d%n\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "j", @Name = "j", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "s"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "s", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Foo", @Empty = "false", @Image = "\"Foo\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- PrimitiveType[@Kind = "int"] + | | +- VariableDeclarator[@Initializer = "true", @Name = "result"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "result", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | | +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "true", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "true", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- SwitchFallthroughBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Foo", @Empty = "false", @Image = "\"Foo\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- YieldStatement[] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + | | +- SwitchFallthroughBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Bar", @Empty = "false", @Image = "\"Bar\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- YieldStatement[] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | | +- SwitchFallthroughBranch[@Default = "false"] + | | | +- SwitchLabel[@Default = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Baz", @Empty = "false", @Image = "\"Baz\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- YieldStatement[] + | | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "BAZ", @Name = "BAZ", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "SwitchExpressions"] + | | +- SwitchFallthroughBranch[@Default = "true"] + | | +- SwitchLabel[@Default = "true"] + | | +- ExpressionStatement[] + | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Neither Foo nor Bar, hmmm...", @Empty = "false", @Image = "\"Neither Foo nor Bar, hmmm...\"", @Length = "28", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- YieldStatement[] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "0", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "0.0", @ValueAsFloat = "0.0", @ValueAsInt = "0", @ValueAsLong = "0"] + | +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "printf", @MethodName = "printf", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "2"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "result=%d%n", @Empty = "false", @Image = "\"result=%d%n\"", @Length = "11", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "result", @Name = "result", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "private", @Image = "howMany", @Name = "howMany", @Overridden = "false", @Varargs = "false", @Visibility = "private", @Void = "true"] + | +- ModifierList[@EffectiveModifiers = "{private, static}", @ExplicitModifiers = "{private, static}"] + | +- VoidType[] + | +- FormalParameters[@Empty = "false", @Size = "1"] + | | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- PrimitiveType[@Kind = "int"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "k", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- Block[@Empty = "false", @Size = "1", @containsComment = "false"] + | +- SwitchStatement[@DefaultCase = "true", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "k", @Name = "k", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- SwitchArrowBranch[@Default = "false"] + | | +- SwitchLabel[@Default = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "one", @Empty = "false", @Image = "\"one\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- SwitchArrowBranch[@Default = "false"] + | | +- SwitchLabel[@Default = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | | +- ArgumentList[@Empty = "false", @Size = "1"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "two", @Empty = "false", @Image = "\"two\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- SwitchArrowBranch[@Default = "true"] + | +- SwitchLabel[@Default = "true"] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "many", @Empty = "false", @Image = "\"many\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "private", @Image = "howManyExpr", @Name = "howManyExpr", @Overridden = "false", @Varargs = "false", @Visibility = "private", @Void = "true"] + | +- ModifierList[@EffectiveModifiers = "{private, static}", @ExplicitModifiers = "{private, static}"] + | +- VoidType[] + | +- FormalParameters[@Empty = "false", @Size = "1"] + | | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | | +- PrimitiveType[@Kind = "int"] + | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "k", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- Block[@Empty = "false", @Size = "1", @containsComment = "false"] + | +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "true", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "k", @Name = "k", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- SwitchArrowBranch[@Default = "false"] + | | +- SwitchLabel[@Default = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "one", @Empty = "false", @Image = "\"one\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- SwitchArrowBranch[@Default = "false"] + | | +- SwitchLabel[@Default = "false"] + | | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "two", @Empty = "false", @Image = "\"two\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- SwitchArrowBranch[@Default = "true"] + | +- SwitchLabel[@Default = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "many", @Empty = "false", @Image = "\"many\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "private", @Image = "f", @Name = "f", @Overridden = "false", @Varargs = "false", @Visibility = "private", @Void = "false"] + +- ModifierList[@EffectiveModifiers = "{private, static}", @ExplicitModifiers = "{private, static}"] + +- PrimitiveType[@Kind = "int"] + +- FormalParameters[@Empty = "false", @Size = "1"] + | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "k", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + +- Block[@Empty = "false", @Size = "1", @containsComment = "false"] + +- ReturnStatement[] + +- InfixExpression[@CompileTimeConstant = "false", @Operator = "*", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "k", @Name = "k", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.java new file mode 100644 index 0000000000..844abf6bbb --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.java @@ -0,0 +1,25 @@ +/** + * + * @see JEP 325: Switch Expressions (Preview) + */ +public class SwitchRules { + private static final int MONDAY = 1; + private static final int TUESDAY = 2; + private static final int WEDNESDAY = 3; + private static final int THURSDAY = 4; + private static final int FRIDAY = 5; + private static final int SATURDAY = 6; + private static final int SUNDAY = 7; + + public static void main(String[] args) { + int day = WEDNESDAY; + + switch (day) { + case MONDAY, FRIDAY, SUNDAY -> System.out.println(" 6"); + case TUESDAY -> System.out.println(" 7"); + case THURSDAY, SATURDAY -> System.out.println(" 8"); + case WEDNESDAY -> { System.out.println(" 9"); } + default -> throw new IllegalArgumentException(); + } + } +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt new file mode 100644 index 0000000000..1567458302 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt @@ -0,0 +1,113 @@ ++- CompilationUnit[@PackageName = ""] + +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "SwitchRules", @CanonicalName = "SwitchRules", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "false", @Record = "false", @RegularClass = "true", @RegularInterface = "false", @SimpleName = "SwitchRules", @TopLevel = "true", @Visibility = "public"] + +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] + +- ClassOrInterfaceBody[@Empty = "false", @Size = "8"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "MONDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "MONDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "TUESDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "TUESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "WEDNESDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "WEDNESDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "3", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "3.0", @ValueAsFloat = "3.0", @ValueAsInt = "3", @ValueAsLong = "3"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "THURSDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "THURSDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "4", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "4.0", @ValueAsFloat = "4.0", @ValueAsInt = "4", @ValueAsLong = "4"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "FRIDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "FRIDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "5", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "5.0", @ValueAsFloat = "5.0", @ValueAsInt = "5", @ValueAsLong = "5"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "SATURDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SATURDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "6", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "6.0", @ValueAsFloat = "6.0", @ValueAsInt = "6", @ValueAsLong = "6"] + +- FieldDeclaration[@EffectiveVisibility = "private", @Visibility = "private"] + | +- ModifierList[@EffectiveModifiers = "{private, static, final}", @ExplicitModifiers = "{private, static, final}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "SUNDAY"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "true", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "SUNDAY", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "7", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "7.0", @ValueAsFloat = "7.0", @ValueAsInt = "7", @ValueAsLong = "7"] + +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "public", @Image = "main", @MainMethod = "true", @Name = "main", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] + +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"] + +- VoidType[] + +- FormalParameters[@Empty = "false", @Size = "1"] + | +- FormalParameter[@EffectiveVisibility = "local", @Final = "false", @Varargs = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- ArrayType[@ArrayDepth = "1"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] + | | +- ArrayDimensions[@Empty = "false", @Size = "1"] + | | +- ArrayTypeDim[@Varargs = "false"] + | +- VariableDeclaratorId[@ArrayType = "true", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "true", @LambdaParameter = "false", @LocalVariable = "false", @Name = "args", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + +- Block[@Empty = "false", @Size = "2", @containsComment = "false"] + +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "day"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "day", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- SwitchStatement[@DefaultCase = "true", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false"] + +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "day", @Name = "day", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- SwitchArrowBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 6", @Empty = "false", @Image = "\" 6\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- SwitchArrowBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 7", @Empty = "false", @Image = "\" 7\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- SwitchArrowBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 8", @Empty = "false", @Image = "\" 8\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- SwitchArrowBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "true", @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- Block[@Empty = "false", @Size = "1", @containsComment = "false"] + | +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " 9", @Empty = "false", @Image = "\" 9\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- SwitchArrowBranch[@Default = "true"] + +- SwitchLabel[@Default = "true"] + +- ThrowStatement[] + +- ConstructorCall[@AnonymousClass = "false", @CompileTimeConstant = "false", @DiamondTypeArgs = "false", @MethodName = "new", @ParenthesisDepth = "0", @Parenthesized = "false", @QualifiedInstanceCreation = "false"] + +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "IllegalArgumentException"] + +- ArgumentList[@Empty = "true", @Size = "0"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/TextBlocks.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/TextBlocks.java new file mode 100644 index 0000000000..5ff553185f --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/TextBlocks.java @@ -0,0 +1,113 @@ +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; + +/** + * @see JEP 368: Text Blocks (Second Preview) + */ +public class TextBlocks { + + + public static void main(String[] args) throws Exception { + // note: there is trailing whitespace!! + String html = """ + + +

Hello, world

+ + + """; + System.out.println(html); + + String query = """ + SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE_TB` + WHERE `CITY` = 'INDIANAPOLIS' + ORDER BY `EMP_ID`, `LAST_NAME`; + """; + System.out.println(query); + + ScriptEngine engine = new ScriptEngineManager().getEngineByName("js"); + Object obj = engine.eval(""" + function hello() { + print('"Hello, world"'); + } + + hello(); + """); + + // Escape sequences + String htmlWithEscapes = """ + \r + \r +

Hello, world

\r + \r + \r + """; + System.out.println(htmlWithEscapes); + + String season = """ + winter"""; // the six characters w i n t e r + + String period = """ + winter + """; // the seven characters w i n t e r LF + + String greeting = + """ + Hi, "Bob" + """; // the ten characters H i , SP " B o b " LF + + String salutation = + """ + Hi, + "Bob" + """; // the eleven characters H i , LF SP " B o b " LF + + String empty = """ + """; // the empty string (zero length) + + String quote = """ + " + """; // the two characters " LF + + String backslash = """ + \\ + """; // the two characters \ LF + + String normalStringLiteral = "test"; + + String code = + """ + String text = \""" + A text block inside a text block + \"""; + """; + + // new escape sequences + String text = """ + Lorem ipsum dolor sit amet, consectetur adipiscing \ + elit, sed do eiusmod tempor incididunt ut labore \ + et dolore magna aliqua.\ + """; + System.out.println(text); + + String colors = """ + red \s + green\s + blue \s + """; + System.out.println(colors); + + // empty new line as first content + String emptyLine = """ + +test +"""; + System.out.println(emptyLine.replaceAll("\n", "")); + + // backslash escapes + String bs = """ + \\test + """; + System.out.println(bs.replaceAll("\n", "")); + } +} diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt new file mode 100644 index 0000000000..16419dfa5a --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt @@ -0,0 +1,83 @@ ++- CompilationUnit[@PackageName = ""] + +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "YieldStatements", @CanonicalName = "YieldStatements", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "false", @Record = "false", @RegularClass = "true", @RegularInterface = "false", @SimpleName = "YieldStatements", @TopLevel = "true", @Visibility = "public"] + +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] + +- ClassOrInterfaceBody[@Empty = "false", @Size = "1"] + +- Initializer[@Static = "false"] + +- Block[@Empty = "false", @Size = "5", @containsComment = "false"] + +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] + | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] + | +- PrimitiveType[@Kind = "int"] + | +- VariableDeclarator[@Initializer = "true", @Name = "yield"] + | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @ForLoopVariable = "false", @ForeachVariable = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "yield", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "0", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "0.0", @ValueAsFloat = "0.0", @ValueAsInt = "0", @ValueAsLong = "0"] + +- ExpressionStatement[] + | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "yield", @Name = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "yield", @MethodName = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ArgumentList[@Empty = "false", @Size = "1"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "yield", @MethodName = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ArgumentList[@Empty = "false", @Size = "2"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "a", @Name = "a", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "b", @Name = "b", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- ExpressionStatement[] + +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "yield", @Name = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "false", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "e", @Name = "e", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- SwitchArrowBranch[@Default = "false"] + +- SwitchLabel[@Default = "false"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "1", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "1.0", @ValueAsFloat = "1.0", @ValueAsInt = "1", @ValueAsLong = "1"] + +- Block[@Empty = "false", @Size = "12", @containsComment = "true"] + +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "yield", @MethodName = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ArgumentList[@Empty = "false", @Size = "2"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "a", @Name = "a", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "b", @Name = "b", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- ExpressionStatement[] + | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "yield", @Name = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- YieldStatement[] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "1", @Parenthesized = "true", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + +- YieldStatement[] + | +- UnaryExpression[@CompileTimeConstant = "false", @Operator = "++", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "bar", @Name = "bar", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- YieldStatement[] + | +- UnaryExpression[@CompileTimeConstant = "false", @Operator = "--", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "bar", @Name = "bar", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- ExpressionStatement[] + | +- UnaryExpression[@CompileTimeConstant = "false", @Operator = "++", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "yield", @Name = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- ExpressionStatement[] + | +- UnaryExpression[@CompileTimeConstant = "false", @Operator = "--", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "yield", @Name = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + +- IfStatement[@Else = "true"] + | +- BooleanLiteral[@CompileTimeConstant = "true", @ParenthesisDepth = "0", @Parenthesized = "false", @True = "true"] + | +- YieldStatement[] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "1", @Parenthesized = "true", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"] + | +- YieldStatement[] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "4", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "4.0", @ValueAsFloat = "4.0", @ValueAsInt = "4", @ValueAsLong = "4"] + +- ExpressionStatement[] + | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "yield", @Name = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- SwitchExpression[@CompileTimeConstant = "false", @DefaultCase = "false", @EnumSwitch = "false", @ExhaustiveEnumSwitch = "false", @FallthroughSwitch = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "foo", @Name = "foo", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- SwitchArrowBranch[@Default = "false"] + | +- SwitchLabel[@Default = "false"] + | | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "4", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "0", @Parenthesized = "false", @ValueAsDouble = "4.0", @ValueAsFloat = "4.0", @ValueAsInt = "4", @ValueAsLong = "4"] + | +- Block[@Empty = "false", @Size = "1", @containsComment = "false"] + | +- YieldStatement[] + | +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "5", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "1", @Parenthesized = "true", @ValueAsDouble = "5.0", @ValueAsFloat = "5.0", @ValueAsInt = "5", @ValueAsLong = "5"] + +- YieldStatement[] + | +- LambdaExpression[@BlockBody = "true", @CompileTimeConstant = "false", @ExpressionBody = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- LambdaParameterList[@Empty = "true", @Size = "0"] + | +- Block[@Empty = "true", @Size = "0", @containsComment = "false"] + +- ExpressionStatement[] + | +- MethodCall[@CompileTimeConstant = "false", @Image = "yield", @MethodName = "yield", @ParenthesisDepth = "0", @Parenthesized = "false"] + | +- ArgumentList[@Empty = "true", @Size = "0"] + +- YieldStatement[] + +- NumericLiteral[@Base = "10", @CompileTimeConstant = "true", @DoubleLiteral = "false", @FloatLiteral = "false", @Image = "2", @IntLiteral = "true", @Integral = "true", @LongLiteral = "false", @ParenthesisDepth = "1", @Parenthesized = "true", @ValueAsDouble = "2.0", @ValueAsFloat = "2.0", @ValueAsInt = "2", @ValueAsLong = "2"]