From 1e042ce4d05eb5d3b0c58e1412f8fef203d1a868 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 10 Mar 2022 12:22:24 +0100 Subject: [PATCH] [java] Fix unit tests for new version 18 --- pmd-java/etc/grammar/Java.jjt | 10 +++++----- .../pmd/lang/java/ast/Java17PreviewTreeDumpTest.java | 6 +++--- .../sourceforge/pmd/lang/java/ast/ASTPatternTest.kt | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index ed32a5bae5..6bd184c7d4 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -529,30 +529,30 @@ public class JavaParser { } private boolean isJEP406Supported() { - return jdkVersion == 17 && preview; + return (jdkVersion == 17 || jdkVersion == 18) && preview; } private void checkForPatternMatchingInSwitch() { if (!isJEP406Supported()) { - throwParseException("Pattern Matching in Switch is only supported with JDK 17 Preview."); + throwParseException("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview."); } } private void checkForNullCaseLabel() { if (!isJEP406Supported()) { - throwParseException("Null case labels in switch are only supported with JDK 17 Preview."); + throwParseException("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview."); } } private void checkForDefaultCaseLabel() { if (!isJEP406Supported()) { - throwParseException("Default case labels in switch are only supported with JDK 17 Preview."); + throwParseException("Default case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview."); } } private void checkForGuardedPatterns() { if (!isJEP406Supported()) { - throwParseException("Guarded patterns are only supported with JDK 17 Preview."); + throwParseException("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview."); } } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java17PreviewTreeDumpTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java17PreviewTreeDumpTest.java index ce7d7d779b..4f8d583872 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java17PreviewTreeDumpTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java17PreviewTreeDumpTest.java @@ -38,7 +38,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest { } }); Assert.assertTrue("Unexpected message: " + thrown.getMessage(), - thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview.")); + thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview.")); } @Test @@ -65,7 +65,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest { } }); Assert.assertTrue("Unexpected message: " + thrown.getMessage(), - thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview.")); + thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview.")); } @Test @@ -82,7 +82,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest { } }); Assert.assertTrue("Unexpected message: " + thrown.getMessage(), - thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview.")); + thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview.")); } @Test diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt index 4d01bc1f4a..6558e336a4 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt @@ -12,8 +12,10 @@ import java.io.IOException class ASTPatternTest : ParserTestSpec({ - parserTest("Test patterns only available on JDK16 and JDK16 (preview) and JDK17 and JDK 17 (preview)", - javaVersions = JavaVersion.values().asList().minus(J16).minus(J16__PREVIEW).minus(J17).minus(J17__PREVIEW)) { + parserTest("Test patterns only available on JDK16 or higher (including preview)", + javaVersions = JavaVersion.values().asList().minus(J16).minus(J16__PREVIEW) + .minus(J17).minus(J17__PREVIEW) + .minus(J18).minus(J18__PREVIEW)) { expectParseException("Pattern Matching for instanceof is only supported with JDK >= 16") { parseAstExpression("obj instanceof Class c") @@ -21,7 +23,7 @@ class ASTPatternTest : ParserTestSpec({ } - parserTest("Test simple patterns", javaVersions = listOf(J16, J17)) { + parserTest("Test simple patterns", javaVersions = listOf(J16, J17, J18)) { importedTypes += IOException::class.java