Skip to content

[java] Support JDK 17 (LTS)#3375

Merged
adangel merged 17 commits into
pmd:masterfrom
adangel:issue-3366-support-jdk-17
Jul 30, 2021
Merged

[java] Support JDK 17 (LTS)#3375
adangel merged 17 commits into
pmd:masterfrom
adangel:issue-3366-support-jdk-17

Conversation

@adangel

@adangel adangel commented Jul 1, 2021

Copy link
Copy Markdown
Member

Describe the PR

We probably need to think a bit more about how we model the new case labels "null" and "default" and "guard patterns":

  • Right now, a Pattern can be a TypePattern or a GuardedPattern. A GuardedPattern contains a TypePattern and a Guard... not sure if that makes sense...
  • The parenthesis around a pattern are not represented in the AST anymore - which means we can't detect useless parens like in case ((o instanceof String)) -> ... ✔️ that's solved
  • The "null" switch case label is just a NullLiteral now. The default case label will set the default flag on the switch label. ✔️ that's solved

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

adangel added 5 commits July 1, 2021 09:51
"JEP 409: Sealed Classes" is now a permanent language
feature with Java 17.
JEP 406: Pattern Matching for switch (Preview)

Guarded and parenthesized patterns are not implemented yet.
More grammar changes to come.
@adangel adangel added this to the 6.37.0 milestone Jul 1, 2021
@ghost

ghost commented Jul 1, 2021

Copy link
Copy Markdown
1 Message
📖 This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset changes 0 violations,
introduces 0 new violations, 2 new errors and 0 new configuration errors,
removes 584 violations, 0 errors and 0 configuration errors.
Full report
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel marked this pull request as ready for review July 1, 2021 18:58
@oowekyala oowekyala self-requested a review July 12, 2021 15:54
Comment thread pmd-java/etc/grammar/Java.jjt Outdated
Comment thread pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTGuardedPattern.java Outdated
Comment thread pmd-java/etc/grammar/Java.jjt Outdated
@oowekyala

Copy link
Copy Markdown
Member

I think we should eventually test rules on some source code written with those new constructs... Otherwise we'll have down the line some bugs in rules that make too many assumptions...

Maybe each time we add a new language version we should also publish a small repo with sources and add that to the regression tester project list? We don't have to do this for pmd 6.37.0 though as there's not too much time left

@adangel

adangel commented Jul 27, 2021

Copy link
Copy Markdown
Member Author

We have some source code that we use for parsing tests under src/main/resources... Maybe we can let net.sourceforge.pmd.coverage.PMDCoverageTest.runAllJavaPmdOnSourceTree() simply run on this folder as well? Currently it only scans src/main/java.... Not sure how good/useful this is, since it would be without auxclasspath (uncompiled) and it will fail on the preview language features....
A separate project is probably better... (there we can compile and use e.g. jdk 17-preview)

@adangel adangel self-assigned this Jul 27, 2021
This fixes some parsing errors in java files under
src/test/resources
@adangel

adangel commented Jul 30, 2021

Copy link
Copy Markdown
Member Author

I've added a test case, which analyzes src/test/resources. However, it didn't find #3420 (or any other problems) - so the means, the test project needs a more elaborated code to trigger the assumptions made in the rules...

@adangel

adangel commented Jul 30, 2021

Copy link
Copy Markdown
Member Author

2 new errors

Both are e.g. sealed = attr.getValue(Attributes.Name.SEALED); - a local variable with the name "sealed". This is apparently still valid code - and local sealed classes are forbidden (we currently think that a local sealed class declaration is following).

I'll fix that. --> 3012462

@adangel adangel merged commit bf9058a into pmd:master Jul 30, 2021
@adangel adangel deleted the issue-3366-support-jdk-17 branch July 30, 2021 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] Support JDK 17 (LTS)

2 participants