[java] Add new language versions 19 and 19-preview

This commit is contained in:
Andreas Dangel
2022-07-07 10:44:13 +02:00
parent 19a6b38bbd
commit eb53daa2c2
7 changed files with 43 additions and 36 deletions

View File

@ -7,33 +7,35 @@ permalink: pmd_languages_java.html
Usually the latest non-preview Java Version is the default version.
Java Version |Alias | Supported by PMD since |
-------------|------|------------------------|
18-preview | | 6.44.0 |
18 (default) | | 6.44.0 |
17-preview | | 6.37.0 |
17 | | 6.37.0 |
16 | | 6.32.0 |
15 | | 6.27.0 |
14 | | 6.22.0 |
13 | | 6.18.0 |
12 | | 6.13.0 |
11 | | 6.6.0 |
10 | 1.10 | 6.4.0 |
9 | 1.9 | 6.0.0 |
8 | 1.8 | 5.1.0 |
7 | 1.7 | 5.0.0 |
6 | 1.6 | 3.9 |
5 | 1.5 | 3.0 |
1.4 | | 1.2.2 |
1.3 | | 1.0.0 |
| Java Version | Alias | Supported by PMD since |
|--------------|-------|------------------------|
| 19-preview | | 6.48.0 |
| 19 (default) | | 6.48.0 |
| 18-preview | | 6.44.0 |
| 18 | | 6.44.0 |
| 17-preview | | 6.37.0 |
| 17 | | 6.37.0 |
| 16 | | 6.32.0 |
| 15 | | 6.27.0 |
| 14 | | 6.22.0 |
| 13 | | 6.18.0 |
| 12 | | 6.13.0 |
| 11 | | 6.6.0 |
| 10 | 1.10 | 6.4.0 |
| 9 | 1.9 | 6.0.0 |
| 8 | 1.8 | 5.1.0 |
| 7 | 1.7 | 5.0.0 |
| 6 | 1.6 | 3.9 |
| 5 | 1.5 | 3.0 |
| 1.4 | | 1.2.2 |
| 1.3 | | 1.0.0 |
## Using Java preview features
In order to analyze a project with PMD that uses preview language features, you'll need to enable
it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `18-preview`:
it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `19-preview`:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 18-preview ...
./run.sh pmd -language java -version 19-preview ...
Note: we only support preview language features for the latest two java versions.

View File

@ -237,8 +237,10 @@ nested element. Possible values are:
<sourceLanguage name="java" version="16"/>
<sourceLanguage name="java" version="17"/>
<sourceLanguage name="java" version="17-preview"/>
<sourceLanguage name="java" version="18"/> <!-- this is the default -->
<sourceLanguage name="java" version="18"/>
<sourceLanguage name="java" version="18-preview"/>
<sourceLanguage name="java" version="19"/> <!-- this is the default -->
<sourceLanguage name="java" version="19-preview"/>
<sourceLanguage name="jsp" version=""/>
<sourceLanguage name="modelica" version=""/>
<sourceLanguage name="pom" version=""/>

View File

@ -534,30 +534,30 @@ public class JavaParser {
}
private boolean isJEP406Supported() {
return (jdkVersion == 17 || jdkVersion == 18) && preview;
return (jdkVersion == 17 || jdkVersion == 18 || jdkVersion == 19) && preview;
}
private void checkForPatternMatchingInSwitch() {
if (!isJEP406Supported()) {
throwParseException("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview.");
throwParseException("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview.");
}
}
private void checkForNullCaseLabel() {
if (!isJEP406Supported()) {
throwParseException("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview.");
throwParseException("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview.");
}
}
private void checkForDefaultCaseLabel() {
if (!isJEP406Supported()) {
throwParseException("Default case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview.");
throwParseException("Default case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview.");
}
}
private void checkForGuardedPatterns() {
if (!isJEP406Supported()) {
throwParseException("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview.");
throwParseException("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview.");
}
}

View File

@ -32,8 +32,10 @@ public class JavaLanguageModule extends BaseLanguageModule {
addVersion("16", new JavaLanguageHandler(16));
addVersion("17", new JavaLanguageHandler(17));
addVersion("17-preview", new JavaLanguageHandler(17, true));
addDefaultVersion("18", new JavaLanguageHandler(18)); // 18 is the default
addVersion("18", new JavaLanguageHandler(18));
addVersion("18-preview", new JavaLanguageHandler(18, true));
addDefaultVersion("19", new JavaLanguageHandler(19)); // 19 is the default
addVersion("19-preview", new JavaLanguageHandler(19, true));
}
}

View File

@ -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 or JDK 18 Preview."));
thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 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 or JDK 18 Preview."));
thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 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 or JDK 18 Preview."));
thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview."));
}
@Test

View File

@ -38,7 +38,7 @@ public class Java18PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview."));
thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview."));
}
@Test
@ -65,7 +65,7 @@ public class Java18PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview."));
thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview."));
}
@Test
@ -82,7 +82,7 @@ public class Java18PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview."));
thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview or JDK 19 Preview."));
}
@Test

View File

@ -24,7 +24,8 @@ enum class JavaVersion : Comparable<JavaVersion> {
J15,
J16,
J17, J17__PREVIEW,
J18, J18__PREVIEW;
J18, J18__PREVIEW,
J19, J19__PREVIEW;
/** Name suitable for use with e.g. [JavaParsingHelper.parse] */
val pmdName: String = name.removePrefix("J").replaceFirst("__", "-").replace('_', '.').toLowerCase()