Skip to content

Issue #8267: Implement full records support#8422

Merged
rnveach merged 1 commit intocheckstyle:masterfrom
nrmancuso:full-records-support
Jul 27, 2020
Merged

Issue #8267: Implement full records support#8422
rnveach merged 1 commit intocheckstyle:masterfrom
nrmancuso:full-records-support

Conversation

@nrmancuso
Copy link
Copy Markdown
Contributor

@nrmancuso nrmancuso commented Jul 8, 2020

Issue #8267: Implement full records support

This PR will add full support for the Java 14 records syntax.

From JEP:
Java Grammar
RecordDeclaration:
{ClassModifier} record TypeIdentifier [TypeParameters]
RecordHeader [SuperInterfaces] RecordBody

RecordHeader:
( [RecordComponentList] )

RecordComponentList:
RecordComponent { , RecordComponent}

RecordComponent:
{Annotation} UnannType Identifier
VariableArityRecordComponent

VariableArityRecordComponent:
{Annotation} UnannType {Annotation} ... Identifier

RecordBody:
{ {RecordBodyDeclaration} }

RecordBodyDeclaration:
ClassBodyDeclaration
CompactConstructorDeclaration

CompactConstructorDeclaration:
{Annotation} {ConstructorModifier} SimpleTypeName ConstructorBody

Note that I've taken some liberties with the java grammar, in order to reuse existing code and reduce extraneous rules in the grammar file.

Reviewers, please note that the commits from #8293 are temporarily on this PR, since I built from them. Once #8293 is merged, I will rebase.

@nrmancuso
Copy link
Copy Markdown
Contributor Author

nrmancuso commented Jul 8, 2020

Reports

Report on similar java constructs in Checkstyle
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full_records_report/index.html

Abstract Syntax Tree Regression Reports
my-checkstyle project:
https://checkstyle-reports-java14.s3.amazonaws.com/reports/diff_AST_full-records_my-checkstyle/index.html
openjdk14:
https://checkstyle-reports-java14.s3.amazonaws.com/reports/diff_antlr_full-records-support_jdk14/index.html

Check Regression Reports
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part1/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part2/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part3/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part4/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part5/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part6/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_checks-nonjavadoc-error/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_checks-only-javadoc-error/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_seventu-check-regression_part_1/index.html
https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_seventu-check-regression_part_2/index.html

Github links for same reports:
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_checks-nonjavadoc-error
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_checks-only-javadoc-error
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_part1
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_part2
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_part3
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_part4
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_part5
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_part6
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_seventu-check-regression_part_1
https://nmancus1.github.io/full-records-support_check_diff_reports_2020_07_08/diff_seventu-check-regression_part_2

@nrmancuso
Copy link
Copy Markdown
Contributor Author

nrmancuso commented Jul 8, 2020

Possibly affected checks

➜  checks git:(master) grep -l -H "TokenTypes.CLASS_DEF" **/**/*.* | sort -u >> affected.checks
➜  checks git:(master) ✗ grep -l -H "TokenTypes.INTERFACE_DEF" **/**/*.* | sort -u >> affected.checks
➜  checks git:(master) ✗ grep -l -H "TokenTypes.ENUM_DEF" **/**/*.* | sort -u >> affected.checks
➜  checks git:(master) ✗ grep -l -H "TokenTypes.CTOR_DEF" **/**/*.* | sort -u >> affected.checks 
➜  checks git:(master) ✗ cat affected.checks | sort -u
annotation/AnnotationLocationCheck.java
annotation/AnnotationOnSameLineCheck.java
annotation/SuppressWarningsCheck.java
blocks/LeftCurlyCheck.java
blocks/RightCurlyCheck.java
coding/AbstractSuperCheck.java
coding/CovariantEqualsCheck.java
coding/DeclarationOrderCheck.java
coding/EqualsAvoidNullCheck.java
coding/FinalLocalVariableCheck.java
coding/HiddenFieldCheck.java
coding/IllegalInstantiationCheck.java
coding/IllegalTypeCheck.java
coding/MagicNumberCheck.java
coding/MissingCtorCheck.java
coding/OverloadMethodsDeclarationOrderCheck.java
coding/ParameterAssignmentCheck.java
coding/RequireThisCheck.java
coding/ReturnCountCheck.java
coding/UnnecessarySemicolonAfterOuterTypeDeclarationCheck.java
coding/UnnecessarySemicolonAfterTypeMemberDeclarationCheck.java
coding/UnnecessarySemicolonInEnumerationCheck.java
design/DesignForExtensionCheck.java
design/FinalClassCheck.java
design/HideUtilityClassConstructorCheck.java
design/InnerTypeLastCheck.java
design/InterfaceIsTypeCheck.java
design/MutableExceptionCheck.java
design/OneTopLevelClassCheck.java
design/VisibilityModifierCheck.java
FinalParametersCheck.java
imports/UnusedImportsCheck.java
indentation/ClassDefHandler.java
indentation/CommentsIndentationCheck.java
indentation/HandlerFactory.java
indentation/MethodDefHandler.java
indentation/SlistHandler.java
javadoc/AtclauseOrderCheck.java
javadoc/JavadocMethodCheck.java
javadoc/JavadocStyleCheck.java
javadoc/JavadocTagInfo.java
javadoc/JavadocTypeCheck.java
javadoc/MissingJavadocMethodCheck.java
javadoc/MissingJavadocTypeCheck.java
javadoc/WriteTagCheck.java
metrics/AbstractClassCouplingCheck.java
metrics/BooleanExpressionComplexityCheck.java
metrics/ClassDataAbstractionCouplingCheck.java
metrics/ClassFanOutComplexityCheck.java
metrics/CyclomaticComplexityCheck.java
metrics/JavaNCSSCheck.java
metrics/NPathComplexityCheck.java
modifier/ClassMemberImpliedModifierCheck.java
modifier/InterfaceMemberImpliedModifierCheck.java
modifier/ModifierOrderCheck.java
modifier/RedundantModifierCheck.java
naming/AbbreviationAsWordInNameCheck.java
naming/AbstractClassNameCheck.java
naming/ClassTypeParameterNameCheck.java
naming/InterfaceTypeParameterNameCheck.java
naming/TypeNameCheck.java
OuterTypeFilenameCheck.java
sizes/ExecutableStatementCountCheck.java
sizes/MethodCountCheck.java
sizes/MethodLengthCheck.java
sizes/OuterTypeNumberCheck.java
sizes/ParameterNumberCheck.java
UncommentedMainCheck.java
whitespace/EmptyLineSeparatorCheck.java
whitespace/GenericWhitespaceCheck.java
whitespace/MethodParamPadCheck.java
whitespace/NoLineWrapCheck.java
whitespace/ParenPadCheck.java
whitespace/WhitespaceAroundCheck.java

@nrmancuso nrmancuso force-pushed the full-records-support branch 4 times, most recently from cf85009 to d52227b Compare July 9, 2020 10:29
@pbludov pbludov requested review from esilkensen, pbludov and romani and removed request for esilkensen July 9, 2020 12:01
@pbludov
Copy link
Copy Markdown
Member

pbludov commented Jul 10, 2020

@nmancus1 please fix ACL for the regression reports. Some of them are inaccessible.

$ curl -s https://checkstyle-reports-java14.s3.amazonaws.com/reports/full-records-support_check_diff_reports_2020_07_08/diff_part2/apache-struts/xref/home/nick/development/contribution/checkstyle-tester/repositories/apache-struts/plugins/plexus/src/main/java/org/apache/struts2/plexus/PlexusLifecycleListener.java.html#L33

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>23540C1B2840C8AB</RequestId><HostId>rdZhmgHVa5YNyVeNgzu742UFHMytj8DflZiJnFAm5s0IQnng3RCYZq6WGpYAX4ndkESzHLedKnM=</HostId></Error>

Copy link
Copy Markdown
Member

@esilkensen esilkensen left a comment

Choose a reason for hiding this comment

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

Nice, I think this worked out really well splitting it into two PR's

@esilkensen
Copy link
Copy Markdown
Member

Hi @rnveach, friendly ping for this PR - if it looks good to you, would be great to get it merged so @nmancus1 can have a clean base to build from for the follow-up PR's addressing the affects checks.

@nrmancuso nrmancuso force-pushed the full-records-support branch from d52227b to d6ef3bc Compare July 26, 2020 16:13
@romani
Copy link
Copy Markdown
Member

romani commented Jul 27, 2020

from JEP:

A record can be declared top level ....

please create such input.
Or fix indentation at

(indentation fix is separate commit.)

CompactConstructorDeclaration:
{Annotation} {ConstructorModifier} SimpleTypeName ConstructorBody

Please put in Input different(all possible) modifiers for CompactConstructorDeclaration.
example of multiple c-tors that call each other.

@nrmancuso nrmancuso force-pushed the full-records-support branch from d6ef3bc to 98bc4c0 Compare July 27, 2020 15:54
@nrmancuso
Copy link
Copy Markdown
Contributor Author

nrmancuso commented Jul 27, 2020

Please put in Input different(all possible) modifiers for CompactConstructorDeclaration.

From JLS:

The compact constructor must be declared public.

example of multiple c-tors that call each other.

I'm not sure if you're referring to compact constructors, but if so:

From JLS:

It is a compile-time error if a record declaration contains more than one compact constructor declaration.

@romani
Copy link
Copy Markdown
Member

romani commented Jul 27, 2020

please fix indentation of

they should not be indented, in separate commit of this PR or separate PR

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.

@rnveach , please finalize.

* The {@code record} keyword. This element appears
* as part of a record declaration.
*
* @since 8.35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

8.35 was just released so this needs to be upped to 36

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.

This was added in 8.35 with the preliminary record support. Should I make this a separate PR or commit?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, didn't make the connection.

@rnveach rnveach merged commit 534a166 into checkstyle:master Jul 27, 2020
@nrmancuso nrmancuso deleted the full-records-support branch July 27, 2020 19:33
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.

5 participants