Merge branch 'localpmd6/jdk-18' into pmd7-jdk-18

This commit is contained in:
Andreas Dangel
2022-03-10 16:08:48 +01:00
49 changed files with 3571 additions and 266 deletions

View File

@ -12,7 +12,7 @@ GEM
concurrent-ruby (1.1.9)
cork (0.3.0)
colored2 (~> 3.1)
danger (8.4.3)
danger (8.4.5)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
@ -26,7 +26,7 @@ GEM
octokit (~> 4.7)
terminal-table (>= 1, < 4)
differ (0.1.2)
et-orbi (1.2.6)
et-orbi (1.2.7)
tzinfo
faraday (1.10.0)
faraday-em_http (~> 1.0)
@ -62,7 +62,7 @@ GEM
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (5.1.0)
liquid (5.2.0)
logger-colors (1.0.0)
mini_portile2 (2.8.0)
multipart-post (2.1.1)

View File

@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.4.6)
activesupport (6.0.4.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
@ -14,8 +14,7 @@ GEM
execjs
coffee-script-source (1.11.1)
colorator (1.1.0)
commonmarker (0.17.13)
ruby-enum (~> 0.5)
commonmarker (0.23.4)
concurrent-ruby (1.1.9)
dnsruby (1.61.9)
simpleidn (~> 0.1)
@ -52,12 +51,12 @@ GEM
ffi (1.15.5)
forwardable-extended (2.6.0)
gemoji (3.0.1)
github-pages (223)
github-pages (225)
github-pages-health-check (= 1.17.9)
jekyll (= 3.9.0)
jekyll-avatar (= 0.7.0)
jekyll-coffeescript (= 1.1.1)
jekyll-commonmark-ghpages (= 0.1.6)
jekyll-commonmark-ghpages (= 0.2.0)
jekyll-default-layout (= 0.1.4)
jekyll-feed (= 0.15.1)
jekyll-gist (= 1.5.0)
@ -71,7 +70,7 @@ GEM
jekyll-relative-links (= 0.6.1)
jekyll-remote-theme (= 0.4.3)
jekyll-sass-converter (= 1.5.2)
jekyll-seo-tag (= 2.7.1)
jekyll-seo-tag (= 2.8.0)
jekyll-sitemap (= 1.4.0)
jekyll-swiss (= 1.0.0)
jekyll-theme-architect (= 0.2.0)
@ -127,12 +126,12 @@ GEM
jekyll-coffeescript (1.1.1)
coffee-script (~> 2.2)
coffee-script-source (~> 1.11.1)
jekyll-commonmark (1.3.1)
commonmarker (~> 0.14)
jekyll (>= 3.7, < 5.0)
jekyll-commonmark-ghpages (0.1.6)
commonmarker (~> 0.17.6)
jekyll-commonmark (~> 1.2)
jekyll-commonmark (1.4.0)
commonmarker (~> 0.22)
jekyll-commonmark-ghpages (0.2.0)
commonmarker (~> 0.23.4)
jekyll (~> 3.9.0)
jekyll-commonmark (~> 1.4.0)
rouge (>= 2.0, < 4.0)
jekyll-default-layout (0.1.4)
jekyll (~> 3.0)
@ -164,7 +163,7 @@ GEM
rubyzip (>= 1.3.0, < 3.0)
jekyll-sass-converter (1.5.2)
sass (~> 3.4)
jekyll-seo-tag (2.7.1)
jekyll-seo-tag (2.8.0)
jekyll (>= 3.8, < 5.0)
jekyll-sitemap (1.4.0)
jekyll (>= 3.7, < 5.0)
@ -248,8 +247,6 @@ GEM
ffi (~> 1.0)
rexml (3.2.5)
rouge (3.26.0)
ruby-enum (0.9.0)
i18n
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
safe_yaml (1.0.5)

View File

@ -355,9 +355,18 @@ entries:
- title: Apex
url: /pmd_languages_apex.html
output: web, pdf
- title: Java
url: /pmd_languages_java.html
- title: null
output: web, pdf
subfolders:
- title: Java
output: web, pdf
subfolderitems:
- title: Java Support
url: /pmd_languages_java.html
output: web, pdf
- title: Java Versions
url: /pmd_languages_java_versions.html
output: web, pdf
- title: JSP
url: /pmd_languages_jsp.html
output: web, pdf

View File

@ -0,0 +1,39 @@
---
title: Supported Java Versions
permalink: pmd_languages_java_versions.html
---
## Overview of supported Java language versions
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 |
## 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`:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 18-preview ...
Note: we only support preview language features for the latest two java versions.

View File

@ -207,8 +207,7 @@ Example:
* [apex](pmd_rules_apex.html) (Salesforce Apex)
* [java](pmd_rules_java.html)
* Supported Versions: 1.3, 1.4, 1.5, 5, 1.6, 6, 1.7, 7, 1.8, 8, 9, 1.9, 10, 1.10, 11, 12,
13, 14, 15, 16, 16-preview, 17 (default), 17-preview
* [Supported Versions](pmd_languages_java.html)
* [ecmascript](pmd_rules_ecmascript.html) (JavaScript)
* [jsp](pmd_rules_jsp.html)
* [modelica](pmd_rules_modelica.html)

View File

@ -235,9 +235,10 @@ nested element. Possible values are:
<sourceLanguage name="java" version="14"/>
<sourceLanguage name="java" version="15"/>
<sourceLanguage name="java" version="16"/>
<sourceLanguage name="java" version="16-preview"/>
<sourceLanguage name="java" version="17"/> <!-- this is the default -->
<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-preview"/>
<sourceLanguage name="jsp" version=""/>
<sourceLanguage name="modelica" version=""/>
<sourceLanguage name="pom" version=""/>

View File

@ -19,6 +19,19 @@ This is a {{ site.pmd.release_type }} release.
### New and noteworthy
#### Java 18 Support
This release of PMD brings support for Java 18. There are no new standard language features.
PMD also supports [JEP 420: Pattern Matching for switch (Second Preview)](https://openjdk.java.net/jeps/420) as a
preview language feature. In order to analyze a project with PMD that uses these language features,
you'll need to enable it via the environment variable `PMD_JAVA_OPTS` and select the new language
version `18-preview`:
export PMD_JAVA_OPTS=--enable-preview
./run.sh pmd -language java -version 18-preview ...
Note: Support for Java 16 preview language features have been removed. The version "16-preview" is no longer available.
#### New programmatic API
@ -60,6 +73,8 @@ The CLI itself remains compatible, if you run PMD via command-line, no action is
* [#3773](https://github.com/pmd/pmd/pull/3773): \[apex] EagerlyLoadedDescribeSObjectResult false positives with SObjectField.getDescribe()
* core
* [#3299](https://github.com/pmd/pmd/issues/3299): \[core] Deprecate system properties of PMDCommandLineInterface
* java
* [#3809](https://github.com/pmd/pmd/issues/3809): \[java] Support JDK 18
### API Changes

View File

@ -1,4 +1,9 @@
/**
* Support "JEP 420: Pattern Matching for switch (Second Preview)" for Java 18 Preview
* There were no grammar changes between 18-preview and 17-preview
* Remove support for Java 16 preview language features
* Andreas Dangel 03/2022
*====================================================================
* Promote "JEP 409: Sealed Classes" as permanent language feature with Java 17.
* Support "JEP 406: Pattern Matching for switch (Preview)" for Java 17 Preview.
* Remove support for Java 15 preview language features
@ -295,17 +300,13 @@ class JavaParserImpl {
private boolean isRecordTypeSupported() {
return jdkVersion == 15 && preview || jdkVersion >= 16;
return jdkVersion >= 16;
}
private boolean localTypesSupported() {
return isRecordTypeSupported();
}
private boolean isSealedClassSupported() {
return jdkVersion == 16 && preview || jdkVersion >= 17;
}
/**
* Keeps track during tree construction, whether we are currently building a switch label.
* A switch label must not contain a LambdaExpression.

View File

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

View File

@ -148,22 +148,25 @@ public class LanguageLevelChecker<T> {
/**
* @see <a href="https://openjdk.java.net/jeps/406">JEP 406: Pattern Matching for switch (Preview)</a>
* @see <a href="https://openjdk.java.net/jeps/420">JEP 420: Pattern Matching for switch (Second Preview)</a>
*/
PATTERN_MATCHING_FOR_SWITCH(17, 17, false),
PATTERN_MATCHING_FOR_SWITCH(17, 18, false),
/**
* Part of pattern matching for switch
* @see #PATTERN_MATCHING_FOR_SWITCH
* @see <a href="https://openjdk.java.net/jeps/406">JEP 406: Pattern Matching for switch (Preview)</a>
* @see <a href="https://openjdk.java.net/jeps/420">JEP 420: Pattern Matching for switch (Second Preview)</a>
*/
GUARDED_PATTERNS(17, 17, false),
GUARDED_PATTERNS(17, 18, false),
/**
* Part of pattern matching for switch
* @see #PATTERN_MATCHING_FOR_SWITCH
* @see <a href="https://openjdk.java.net/jeps/406">JEP 406: Pattern Matching for switch (Preview)</a>
* @see <a href="https://openjdk.java.net/jeps/420">JEP 420: Pattern Matching for switch (Second Preview)</a>
*/
NULL_CASE_LABELS(17, 17, false),
NULL_CASE_LABELS(17, 18, false),
; // SUPPRESS CHECKSTYLE enum trailing semi is awesome

View File

@ -68,19 +68,23 @@ public class UnnecessaryImportRule extends AbstractJavaRule {
/*
* Patterns to match the following constructs:
*
* @see package.class#member(param, param) label {@linkplain
* package.class#member(param, param) label} {@link
* package.class#member(param, param) label} {@link package.class#field}
* @see package.class#member(param, param) label
* {@linkplain package.class#member(param, param) label}
* {@link package.class#member(param, param) label}
* {@link package.class#field}
* {@value package.class#field}
*
* @throws package.class label
* @exception package.class label
*/
private static final Pattern SEE_PATTERN = Pattern
.compile("@see\\s+((?:\\p{Alpha}\\w*\\.)*(?:\\p{Alpha}\\w*))?(?:#\\w*(?:\\(([.\\w\\s,\\[\\]]*)\\))?)?");
private static final Pattern LINK_PATTERNS = Pattern
.compile("\\{@link(?:plain)?\\s+((?:\\p{Alpha}\\w*\\.)*(?:\\p{Alpha}\\w*))?(?:#\\w*(?:\\(([.\\w\\s,\\[\\]]*)\\))?)?[\\s\\}]");
/* package.class#member(param, param) */
private static final String TYPE_PART_GROUP = "((?:\\p{Alpha}\\w*\\.)*(?:\\p{Alpha}\\w*))?(?:#\\w*(?:\\(([.\\w\\s,\\[\\]]*)\\))?)?";
private static final Pattern SEE_PATTERN = Pattern.compile("@see\\s+" + TYPE_PART_GROUP);
private static final Pattern LINK_PATTERNS = Pattern.compile("\\{@link(?:plain)?\\s+" + TYPE_PART_GROUP + "[\\s\\}]");
private static final Pattern VALUE_PATTERN = Pattern.compile("\\{@value\\s+(\\p{Alpha}\\w*)[\\s#\\}]");
@ -88,7 +92,11 @@ public class UnnecessaryImportRule extends AbstractJavaRule {
private static final Pattern EXCEPTION_PATTERN = Pattern.compile("@exception\\s+(\\p{Alpha}\\w*)");
private static final Pattern[] PATTERNS = { SEE_PATTERN, LINK_PATTERNS, VALUE_PATTERN, THROWS_PATTERN, EXCEPTION_PATTERN };
/* // @link substring="a" target="package.class#member(param, param)" */
private static final Pattern LINK_IN_SNIPPET = Pattern
.compile("//\\s*@link\\s+(?:.*?)?target=[\"']?" + TYPE_PART_GROUP + "[\"']?");
private static final Pattern[] PATTERNS = { SEE_PATTERN, LINK_PATTERNS, VALUE_PATTERN, THROWS_PATTERN, EXCEPTION_PATTERN, LINK_IN_SNIPPET };
@Override
public Object visit(ASTCompilationUnit node, Object data) {

View File

@ -26,10 +26,10 @@ public class JavaLanguageModuleTest {
@Test
public void previewVersionShouldBeGreaterThanNonPreview() {
LanguageVersion java16 = javaLanguage.getVersion("16");
LanguageVersion java16p = javaLanguage.getVersion("16-preview");
LanguageVersion java18 = javaLanguage.getVersion("18");
LanguageVersion java18p = javaLanguage.getVersion("18-preview");
Assert.assertTrue("java16-preview should be greater than java16", java16p.compareTo(java16) > 0);
Assert.assertTrue("java18-preview should be greater than java18", java18p.compareTo(java18) > 0);
}
@Test

View File

@ -12,10 +12,10 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
ParserCornersTest.class,
Java15TreeDumpTest.class,
Java16PreviewTreeDumpTest.class,
Java16TreeDumpTest.class,
Java17PreviewTreeDumpTest.class,
Java17TreeDumpTest.class
Java17TreeDumpTest.class,
Java18PreviewTreeDumpTest.class
})
public class AllJavaAstTreeDumpTest {

View File

@ -1,73 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
import java.util.Arrays;
import java.util.HashSet;
import org.junit.Assert;
import org.junit.Test;
import net.sourceforge.pmd.lang.ast.ParseException;
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest;
import net.sourceforge.pmd.lang.ast.test.RelevantAttributePrinter;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
public class Java16PreviewTreeDumpTest extends BaseTreeDumpTest {
private final JavaParsingHelper java16p =
JavaParsingHelper.DEFAULT.withDefaultVersion("16-preview")
.withResourceContext(Java16PreviewTreeDumpTest.class, "jdkversiontests/java16p/");
private final JavaParsingHelper java16 = java16p.withDefaultVersion("16");
public Java16PreviewTreeDumpTest() {
super(new RelevantAttributePrinter(), ".java");
}
@Override
public BaseParsingHelper<?, ?> getParser() {
return java16p;
}
@Test(expected = ParseException.class)
public void sealedClassBeforeJava16Preview() {
java16.parseResource("geometry/Shape.java");
}
@Test
public void sealedClass() {
doTest("geometry/Shape");
ASTCompilationUnit compilationUnit = java16p.parseResource("geometry/Shape.java");
ASTClassOrInterfaceDeclaration sealedClass = compilationUnit.descendants(ASTClassOrInterfaceDeclaration.class).first();
Assert.assertEquals(new HashSet<>(Arrays.asList(JModifier.SEALED, JModifier.PUBLIC)),
sealedClass.getModifiers().getExplicitModifiers());
}
@Test
public void nonSealedClass() {
doTest("geometry/Square");
ASTCompilationUnit compilationUnit = java16p.parseResource("geometry/Square.java");
ASTClassOrInterfaceDeclaration sealedClass = compilationUnit.descendants(ASTClassOrInterfaceDeclaration.class).first();
Assert.assertEquals(new HashSet<>(Arrays.asList(JModifier.NON_SEALED, JModifier.PUBLIC)),
sealedClass.getModifiers().getExplicitModifiers());
}
@Test(expected = ParseException.class)
public void sealedInterfaceBeforeJava15Preview() {
java16.parseResource("expression/Expr.java");
}
@Test
public void sealedInterface() {
doTest("expression/Expr");
ASTCompilationUnit compilationUnit = java16p.parseResource("expression/Expr.java");
ASTClassOrInterfaceDeclaration sealedClass = compilationUnit.descendants(ASTClassOrInterfaceDeclaration.class).first();
Assert.assertEquals(new HashSet<>(Arrays.asList(JModifier.SEALED, JModifier.PUBLIC)),
sealedClass.getModifiers().getExplicitModifiers());
}
}

View File

@ -20,7 +20,6 @@ public class Java16TreeDumpTest extends BaseJavaTreeDumpTest {
private final JavaParsingHelper java16 =
JavaParsingHelper.DEFAULT.withDefaultVersion("16")
.withResourceContext(Java16TreeDumpTest.class, "jdkversiontests/java16/");
private final JavaParsingHelper java16p = java16.withDefaultVersion("16-preview");
private final JavaParsingHelper java15 = java16.withDefaultVersion("15");
@ -116,6 +115,5 @@ public class Java16TreeDumpTest extends BaseJavaTreeDumpTest {
@Test
public void sealedAndNonSealedIdentifiers() {
doTest("NonSealedIdentifier");
java16p.parseResource("NonSealedIdentifier.java"); // make sure we can parse it with preview as well
}
}

View File

@ -41,7 +41,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Pattern matching for switch is a preview feature of JDK 17, you should select your language version accordingly"));
thrown.getMessage().contains("Pattern matching for switch is a preview feature of JDK 17 or JDK 18, you should select your language version accordingly"));
}
@Test
@ -68,7 +68,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Null case labels is a preview feature of JDK 17, you should select your language version accordingly"));
thrown.getMessage().contains("Null case labels is a preview feature of JDK 17 or JDK 18, you should select your language version accordingly"));
}
@Test
@ -84,7 +84,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
java17.parseResource("GuardedAndParenthesizedPatterns.java");
}
});
assertThat(thrown.getMessage(), containsString("Pattern matching for switch is a preview feature of JDK 17, you should select your language version accordingly"));
assertThat(thrown.getMessage(), containsString("Pattern matching for switch is a preview feature of JDK 17 or JDK 18, you should select your language version accordingly"));
}
@Test

View File

@ -39,7 +39,7 @@ public class Java17TreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Sealed classes is a preview feature of JDK 16, you should select your language version accordingly"));
thrown.getMessage().contains("Sealed classes is a feature of JDK >= 17, you should select your language version accordingly"));
}
@Test
@ -69,7 +69,7 @@ public class Java17TreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Sealed classes is a preview feature of JDK 16, you should select your language version accordingly"));
thrown.getMessage().contains("Sealed classes is a feature of JDK >= 17, you should select your language version accordingly"));
}
@Test

View File

@ -0,0 +1,104 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.Assert;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import net.sourceforge.pmd.lang.ast.ParseException;
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest;
import net.sourceforge.pmd.lang.ast.test.RelevantAttributePrinter;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
public class Java18PreviewTreeDumpTest extends BaseTreeDumpTest {
private final JavaParsingHelper java18p =
JavaParsingHelper.DEFAULT.withDefaultVersion("18-preview")
.withResourceContext(Java18PreviewTreeDumpTest.class, "jdkversiontests/java17p/");
private final JavaParsingHelper java18 = java18p.withDefaultVersion("18");
public Java18PreviewTreeDumpTest() {
super(new RelevantAttributePrinter(), ".java");
}
@Override
public BaseParsingHelper<?, ?> getParser() {
return java18p;
}
@Test
public void dealingWithNullBeforeJava18Preview() {
ParseException thrown = Assert.assertThrows(ParseException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
java18.parseResource("DealingWithNull.java");
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Null case labels is a preview feature of JDK 17 or JDK 18, you should select your language version accordingly"));
}
@Test
public void dealingWithNull() {
doTest("DealingWithNull");
}
@Test
public void enhancedTypeCheckingSwitch() {
doTest("EnhancedTypeCheckingSwitch");
}
@Test
public void exhaustiveSwitch() {
doTest("ExhaustiveSwitch");
}
@Test
public void guardedAndParenthesizedPatternsBeforeJava18Preview() {
ParseException thrown = Assert.assertThrows(ParseException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
java18.parseResource("GuardedAndParenthesizedPatterns.java");
}
});
assertThat(thrown.getMessage(), containsString("Pattern matching for switch is a preview feature of JDK 17 or JDK 18, you should select your language version accordingly"));
}
@Test
public void guardedAndParenthesizedPatterns() {
doTest("GuardedAndParenthesizedPatterns");
}
@Test
public void patternsInSwitchLabelsBeforeJava18Preview() {
ParseException thrown = Assert.assertThrows(ParseException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
java18.parseResource("PatternsInSwitchLabels.java");
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Pattern matching for switch is a preview feature of JDK 17 or JDK 18, you should select your language version accordingly"));
}
@Test
public void patternsInSwitchLabels() {
doTest("PatternsInSwitchLabels");
}
@Test
public void refiningPatternsInSwitch() {
doTest("RefiningPatternsInSwitch");
}
@Test
public void scopeOfPatternVariableDeclarations() {
doTest("ScopeOfPatternVariableDeclarations");
}
}

View File

@ -14,7 +14,7 @@ class ASTPatternTest : ProcessorTestSpec({
val typePatternsVersions = JavaVersion.since(J16)
parserTest("Test patterns only available on JDK16 and JDK16 (preview) and JDK17 and JDK 17 (preview)",
parserTest("Test patterns only available on JDK16 or higher (including preview)",
javaVersions = JavaVersion.except(typePatternsVersions)) {
inContext(ExpressionParsingCtx) {

View File

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

View File

@ -1,9 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.expression;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public final class ConstantExpr implements Expr { }

View File

@ -1,10 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.expression;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public sealed interface Expr
permits ConstantExpr, PlusExpr, TimesExpr, NegExpr { }

View File

@ -1,11 +0,0 @@
+- CompilationUnit[@PackageName = "com.example.expression", @declarationsAreInDefaultPackage = "false"]
+- PackageDeclaration[@Name = "com.example.expression"]
| +- ModifierList[]
+- ClassOrInterfaceDeclaration[@Abstract = "true", @Annotation = "false", @Anonymous = "false", @BinaryName = "com.example.expression.Expr", @CanonicalName = "com.example.expression.Expr", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Image = "Expr", @Interface = "true", @Local = "false", @Native = "false", @Nested = "false", @PackageName = "com.example.expression", @PackagePrivate = "false", @Private = "false", @Protected = "false", @Public = "true", @Record = "false", @RegularClass = "false", @RegularInterface = "true", @SimpleName = "Expr", @Static = "false", @Strictfp = "false", @Synchronized = "false", @SyntacticallyAbstract = "false", @SyntacticallyFinal = "false", @SyntacticallyPublic = "true", @SyntacticallyStatic = "false", @TopLevel = "true", @Transient = "false", @Visibility = "public", @Volatile = "false"]
+- ModifierList[]
+- PermitsList[@Empty = "false", @Size = "4"]
| +- ClassOrInterfaceType[@ArrayDepth = "0", @ArrayType = "false", @ClassOrInterfaceType = "true", @FullyQualified = "false", @PrimitiveType = "false", @ReferenceToClassSameCompilationUnit = "false", @SimpleName = "ConstantExpr", @TypeImage = "ConstantExpr"]
| +- ClassOrInterfaceType[@ArrayDepth = "0", @ArrayType = "false", @ClassOrInterfaceType = "true", @FullyQualified = "false", @PrimitiveType = "false", @ReferenceToClassSameCompilationUnit = "false", @SimpleName = "PlusExpr", @TypeImage = "PlusExpr"]
| +- ClassOrInterfaceType[@ArrayDepth = "0", @ArrayType = "false", @ClassOrInterfaceType = "true", @FullyQualified = "false", @PrimitiveType = "false", @ReferenceToClassSameCompilationUnit = "false", @SimpleName = "TimesExpr", @TypeImage = "TimesExpr"]
| +- ClassOrInterfaceType[@ArrayDepth = "0", @ArrayType = "false", @ClassOrInterfaceType = "true", @FullyQualified = "false", @PrimitiveType = "false", @ReferenceToClassSameCompilationUnit = "false", @SimpleName = "NegExpr", @TypeImage = "NegExpr"]
+- ClassOrInterfaceBody[@Empty = "true", @Size = "0"]

View File

@ -1,9 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.expression;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public final class NegExpr implements Expr { }

View File

@ -1,9 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.expression;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public final class PlusExpr implements Expr { }

View File

@ -1,9 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.expression;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public final class TimesExpr implements Expr { }

View File

@ -1,9 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.geometry;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public final class Circle extends Shape { }

View File

@ -1,10 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.geometry;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public final class FilledRectangle extends Rectangle { }

View File

@ -1,11 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.geometry;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public sealed class Rectangle extends Shape
permits TransparentRectangle, FilledRectangle { }

View File

@ -1,11 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package com.example.geometry;
/**
* @see <a href="https://openjdk.java.net/jeps/397">JEP 397: Sealed Classes (Second Preview)</a>
*/
public sealed class Shape
permits Circle, Rectangle, Square { }

Some files were not shown because too many files have changed in this diff Show More