Skip to content

Issue #13279: Support JDK 20 preview language features#13291

Merged
romani merged 1 commit intocheckstyle:masterfrom
nrmancuso:issue-13279
Aug 1, 2023
Merged

Issue #13279: Support JDK 20 preview language features#13291
romani merged 1 commit intocheckstyle:masterfrom
nrmancuso:issue-13279

Conversation

@nrmancuso nrmancuso self-assigned this Jun 22, 2023
@nrmancuso nrmancuso marked this pull request as draft June 22, 2023 05:09
@nrmancuso nrmancuso force-pushed the issue-13279 branch 14 times, most recently from a10470b to a5972c3 Compare July 21, 2023 14:06
@nrmancuso nrmancuso removed the blocked label Jul 23, 2023
@nrmancuso nrmancuso marked this pull request as ready for review July 23, 2023 02:27
if (forInitAST == null) {
if (!skipEnhancedForLoopVariable) {
final Deque<String> currentVariables = getCurrentVariables();
if (!skipEnhancedForLoopVariable && !currentVariables.isEmpty()) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to guard Deque#pop to avoid NoSuchElementException.

* @param paramDef a for-each clause variable
*/
private void leaveForEach(DetailAST paramDef) {
final DetailAST paramName = paramDef.findFirstToken(TokenTypes.IDENT);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were throwing a NPE here, so I fixed it in this PR.

Comment on lines +187 to +210
| | | |--FOR_EACH_CLAUSE -> FOR_EACH_CLAUSE [32:17]
| | | | |--RECORD_PATTERN_DEF -> RECORD_PATTERN_DEF [32:17]
| | | | | |--MODIFIERS -> MODIFIERS [32:17]
| | | | | |--TYPE -> TYPE [32:17]
| | | | | | `--IDENT -> Point [32:17]
| | | | | |--LPAREN -> ( [32:22]
| | | | | |--RECORD_PATTERN_COMPONENTS -> RECORD_PATTERN_COMPONENTS [32:23]
| | | | | | |--PATTERN_VARIABLE_DEF -> PATTERN_VARIABLE_DEF [32:23]
| | | | | | | |--MODIFIERS -> MODIFIERS [32:23]
| | | | | | | | `--FINAL -> final [32:23]
| | | | | | | |--TYPE -> TYPE [32:29]
| | | | | | | | `--IDENT -> var [32:29]
| | | | | | | `--IDENT -> x [32:33]
| | | | | | |--COMMA -> , [32:34]
| | | | | | `--PATTERN_VARIABLE_DEF -> PATTERN_VARIABLE_DEF [32:36]
| | | | | | |--MODIFIERS -> MODIFIERS [32:36]
| | | | | | | `--FINAL -> final [32:36]
| | | | | | |--TYPE -> TYPE [32:42]
| | | | | | | `--IDENT -> var [32:42]
| | | | | | `--IDENT -> y [32:46]
| | | | | `--RPAREN -> ) [32:47]
| | | | |--COLON -> : [32:49]
| | | | `--EXPR -> EXPR [32:51]
| | | | `--IDENT -> points1 [32:51]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of basic record component decomposition in enhanced for loop:

 for (Point(final var x, final var y) : points1) {
  }

@nrmancuso nrmancuso requested review from rnveach and romani July 23, 2023 02:41
@nrmancuso nrmancuso assigned romani and unassigned nrmancuso Jul 23, 2023
Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, only minors:

@romani romani assigned nrmancuso and unassigned romani Jul 23, 2023
@nrmancuso nrmancuso force-pushed the issue-13279 branch 2 times, most recently from 545212a to 417e426 Compare July 23, 2023 13:58
@nrmancuso nrmancuso force-pushed the issue-13279 branch 2 times, most recently from 1b16d33 to bf0e0a9 Compare July 23, 2023 14:11
@nrmancuso
Copy link
Copy Markdown
Contributor Author

nrmancuso commented Jul 23, 2023

Moving this back to draft, I want to double check some things at https://docs.oracle.com/javase/specs/jls/se20/preview/specs/patterns-switch-record-patterns-jls.html


Ok, I wanted to double check the switch grammar because it is not specified in the JEP (though they mention it has changed). Here it is from the JLS SE 20 preview:

...

SwitchLabel:
    case CaseConstant {, CaseConstant}
    case null [, default]
    case CasePattern
    default

CaseConstant:
    ConditionalExpression

CasePattern:
    Pattern [ Guard ]

Guard:
    when Expression

This is from the JLS SE 19 preview:

...
SwitchLabel:
    CaseOrDefaultLabel {: CaseOrDefaultLabel }

CaseOrDefaultLabel:
    case CaseElement {, CaseElement }
    default

CaseElement:
    CaseConstant
    Pattern [ Guard ]
    null
    default

CaseConstant:
    ConditionalExpression

Guard:
    when Expression

So, this was just a simplification/ clean up of the existing grammar. This does not really have any impact on us; our grammar kind of falls between the two and I am OK with this.

@nrmancuso nrmancuso marked this pull request as draft July 23, 2023 14:17
Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to merge.

@nrmancuso nrmancuso marked this pull request as ready for review July 29, 2023 17:57
@nrmancuso
Copy link
Copy Markdown
Contributor Author

@romani @rnveach ok, I have resolved my doubts, see conclusion of investigation at #13291 (comment)

@nrmancuso nrmancuso assigned rnveach and unassigned nrmancuso Jul 29, 2023
@rnveach rnveach assigned romani and unassigned rnveach Aug 1, 2023
@romani romani merged commit 34e7d5c into checkstyle:master Aug 1, 2023
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.

Record pattern causes checkstyle to fail in JDK 20 (preview)

3 participants