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

This commit is contained in:
Andreas Dangel 2024-02-15 09:12:47 +01:00
parent 9e900a2c70
commit 73dbd56ec4
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
7 changed files with 19 additions and 11 deletions

View File

@ -15,8 +15,10 @@ Usually the latest non-preview Java Version is the default version.
| Java Version | Alias | Supported by PMD since |
|--------------|-------|------------------------|
| 22-preview | | 7.0.0 |
| 22 (default) | | 7.0.0 |
| 21-preview | | 7.0.0 |
| 21 (default) | | 7.0.0 |
| 21 | | 7.0.0 |
| 20-preview | | 6.55.0 |
| 20 | | 6.55.0 |
| 19 | | 6.48.0 |
@ -40,10 +42,10 @@ Usually the latest non-preview Java Version is the default version.
## 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. `21-preview`:
it via the environment variable `PMD_JAVA_OPTS` and select the new language version, e.g. `22-preview`:
export PMD_JAVA_OPTS=--enable-preview
pmd check --use-version java-21-preview ...
pmd check --use-version java-22-preview ...
Note: we only support preview language features for the latest two java versions.

View File

@ -212,7 +212,7 @@ accordingly and this rule won't be executed.
The specific version of a language to be used is selected via the `sourceLanguage`
nested element. Example:
<sourceLanguage name="java" version="21"/>
<sourceLanguage name="java" version="22"/>
The available versions depend on the language. You can get a list of the currently supported language versions
via the CLI option `--help`.

View File

@ -51,6 +51,7 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest {
"java-16", "java-17", "java-18", "java-19",
"java-20", "java-20-preview",
"java-21", "java-21-preview",
"java-22", "java-22-preview",
"java-5", "java-6", "java-7",
"java-8", "java-9", "jsp-2", "jsp-3", "kotlin-1.6",
"kotlin-1.7", "kotlin-1.8", "modelica-3.4", "modelica-3.5",

View File

@ -43,8 +43,10 @@ public class JavaLanguageModule extends LanguageModuleBase implements PmdCapable
.addVersion("19")
.addVersion("20")
.addVersion("20-preview")
.addDefaultVersion("21") // 21 is the default
.addVersion("21-preview"));
.addVersion("21")
.addVersion("21-preview")
.addDefaultVersion("22") // 22 is the default
.addVersion("22-preview"));
}
public static JavaLanguageModule getInstance() {

View File

@ -24,10 +24,10 @@ class JavaLanguageModuleTest {
@Test
void previewVersionShouldBeGreaterThanNonPreview() {
LanguageVersion java20 = JavaLanguageModule.getInstance().getVersion("20");
LanguageVersion java20p = JavaLanguageModule.getInstance().getVersion("20-preview");
LanguageVersion java = JavaLanguageModule.getInstance().getVersion("22");
LanguageVersion javaPreview = JavaLanguageModule.getInstance().getVersion("22-preview");
assertTrue(java20p.compareTo(java20) > 0, "java20-preview should be greater than java20");
assertTrue(javaPreview.compareTo(java) > 0, "java-preview should be greater than java");
}
@Test

View File

@ -40,8 +40,10 @@ class LanguageVersionTest extends AbstractLanguageVersionTest {
new TestDescriptor(java, "20-preview"),
new TestDescriptor(java, "21"),
new TestDescriptor(java, "21-preview"),
new TestDescriptor(java, "22"),
new TestDescriptor(java, "22-preview"),
defaultVersionIs(java, "21"),
defaultVersionIs(java, "22"),
// this one won't be found: case-sensitive!
versionDoesNotExist("JAVA", "JAVA", "1.7"),

View File

@ -35,7 +35,8 @@ enum class JavaVersion : Comparable<JavaVersion> {
J18,
J19,
J20, J20__PREVIEW,
J21, J21__PREVIEW;
J21, J21__PREVIEW,
J22, J22__PREVIEW;
/** Name suitable for use with e.g. [JavaParsingHelper.parse] */
val pmdName: String = name.removePrefix("J").replaceFirst("__", "-").replace('_', '.').lowercase()