Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #3095: Add COMPILATION_UNIT token in Ast Tree, remove EOF token #10574

Merged
merged 1 commit into from
Aug 19, 2021

Conversation

nrmancuso
Copy link
Member

@nrmancuso nrmancuso commented Aug 5, 2021

Closes #3095.

Check Regression Reports

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_checks-nonjavadoc-error/index.html


https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_checks-only-javadoc-error/index.html


https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_part1/index.html

  • Clean

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_part2/index.html

  • Clean

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_part3/index.html

  • Clean

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_part4/index.html

  • Clean

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_part5/index.html

  • Clean

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_part6/index.html

  • Clean

https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_sevntu-check-regression_part_1/index.html


https://nmancus1.github.io/issue-3095-b_check_diff_reports_2021_08_11/diff_sevntu-check-regression_part_2/index.html


AST Regression Reports

It will be very challenging to share or view AST regresion report for this PR:
image

File size of report folder is 4.5 GB; every line of printed AST in the entire repo will have a diff, since we are adding a root node.

@nrmancuso nrmancuso marked this pull request as draft August 5, 2021 17:58
@nrmancuso nrmancuso force-pushed the issue-3095-b branch 2 times, most recently from 3ed91e2 to 0a76220 Compare August 6, 2021 04:34
@nrmancuso nrmancuso force-pushed the issue-3095-b branch 4 times, most recently from 52b6875 to a1603a6 Compare August 9, 2021 17:14
@nrmancuso nrmancuso marked this pull request as ready for review August 10, 2021 12:59
@romani
Copy link
Member

romani commented Aug 11, 2021

@nmancus1 , please resolve conflict

@nrmancuso nrmancuso force-pushed the issue-3095-b branch 2 times, most recently from cb13ecc to 0468727 Compare August 11, 2021 04:24
Copy link
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.

Items

config/checkstyle_checks.xml Outdated Show resolved Hide resolved
@romani
Copy link
Member

romani commented Aug 13, 2021

I did not expect updates in Checks a lot, but we have affect on a lot of them.
Lets double check that introduction of root token have enough benefits, as whole world of thirdparty checks might be affected in same way.

most interesting update:

✔ ~/java/github/romani/checkstyle [nmancus1/issue-3095-b L|✔] 
$ git show --stat | grep -v "XpathReg" | grep -v ".txt" | grep -v ".xml" | grep -v "gression" | grep -v "Input" | grep ".../"
 .../tools/checkstyle/JavaAstVisitor.java           |   15 +-
 .../puppycrawl/tools/checkstyle/JavaParser.java    |   10 +-
 .../checkstyle/JavadocPropertiesGenerator.java     |    2 +-
 .../tools/checkstyle/api/TokenTypes.java           |   50 +-
 .../checkstyle/checks/OuterTypeFilenameCheck.java  |    2 +-
 .../checks/annotation/MissingDeprecatedCheck.java  |    2 +-
 .../checkstyle/checks/blocks/LeftCurlyCheck.java   |    9 +-
 .../checks/coding/OneStatementPerLineCheck.java    |    7 +-
 .../checks/design/InnerTypeLastCheck.java          |    2 +-
 .../checks/design/OneTopLevelClassCheck.java       |   14 +-
 .../checks/imports/UnusedImportsCheck.java         |    3 +-
 .../indentation/CommentsIndentationCheck.java      |    6 +-
 .../checks/javadoc/AtclauseOrderCheck.java         |   17 +-
 .../checks/modifier/RedundantModifierCheck.java    |    7 +-
 .../checks/whitespace/GenericWhitespaceCheck.java  |    3 +-
 .../checkstyle/filters/SuppressionXpathFilter.java |   10 +-
 .../filters/SuppressionXpathSingleFilter.java      |   22 +-
 .../tools/checkstyle/gui/ParseTreeTableModel.java  |    2 +-
 .../checkstyle/gui/ParseTreeTablePresentation.java |   28 +-
 .../checkstyle/utils/BlockCommentPosition.java     |   31 +-
 .../tools/checkstyle/utils/CheckUtil.java          |    2 +-
 .../tools/checkstyle/xpath/RootNode.java           |    2 +-
 .../checkstyle/xpath/XpathQueryGenerator.java      |    6 +-
 .../tools/checkstyle/grammar/java/JavaLexer.g4     |    7 +-
 .../tools/checkstyle/AstTreeStringPrinterTest.java |   13 +-
 .../tools/checkstyle/JavaAstVisitorTest.java       |    2 +-
 .../checkstyle/JavadocDetailNodeParserTest.java    |    2 +-
 .../com/puppycrawl/tools/checkstyle/MainTest.java  |  253 +-
 .../checkstyle/SuppressionsStringPrinterTest.java  |   19 +-
 .../XpathFileGeneratorAstFilterTest.java           |    7 +-
 .../XpathFileGeneratorAuditListenerTest.java       |   12 +-
 .../tools/checkstyle/api/FullIdentTest.java        |   18 +-
 .../checks/design/FinalClassCheckTest.java         |    2 +-
 .../checks/design/OneTopLevelClassCheckTest.java   |   24 +-
 .../checks/design/VisibilityModifierCheckTest.java |    2 +-
 .../checks/javadoc/JavadocMethodCheckTest.java     |    8 +
 .../filters/SuppressionXpathSingleFilterTest.java  |   15 +-
 .../checkstyle/filters/SuppressionsLoaderTest.java |    4 +-
 .../checkstyle/filters/XpathFilterElementTest.java |   15 +-
 .../grammar/GeneratedJavaTokenTypesTest.java       |    3 +-
 .../gui/ParseTreeTablePresentationTest.java        |   14 +-
 .../tools/checkstyle/utils/TokenUtilTest.java      |   11 +-
 .../tools/checkstyle/utils/XpathUtilTest.java      |   55 +-
 .../tools/checkstyle/xpath/ElementNodeTest.java    |    2 +-
 .../tools/checkstyle/xpath/RootNodeTest.java       |    2 +-
 .../tools/checkstyle/xpath/XpathMapperTest.java    |  152 +-
 .../checkstyle/xpath/XpathQueryGeneratorTest.java  |  150 +-

@rnveach
Copy link
Member

rnveach commented Aug 14, 2021

Since this is for the 9.0 version, I more for breaking compatibility.

I am not very sure on the benefit part, but its a change that makes sense. It is weird to be given a node that is not a root and having to do next sibling on it to get the rest of the CU when dealing with the beginTree/endTree methods.

I don't see a reason not to do this.

@nrmancuso
Copy link
Member Author

nrmancuso commented Aug 14, 2021

I really did not see a great deal of value in this issue when I started on this, but, after working on check updates, I think that adding a root node makes a lot of sense:

  1. It helps to maintain consistency in API; when writing checks, one of the first considerations should be which tokens to check. This change would allow top level checks to now specify a token.

  2. Having a check traverse the tree itself is discouraged. From https://checkstyle.sourceforge.io/writingchecks.html#Understanding_the_visitor_pattern:

It is important to understand that the individual Checks do not drive the AST traversal (it possible to traverse itself, but not recommended).

  1. As you can see from the changes to existing checks (all are minor), it is more informative to write if (ast.getType() == TokenTypes.COMPILATION_UNIT) than if (ast == null) or while (parent.getType() != TokenTypes.COMPILATION_UNIT) instead of while (parent != null). This helps the code to be more self-documenting, because we are explicitly stating that we want to check to see if this is a top level node in the AST.
  2. As @rnveach states above, it seems nonsensical to have a tree with no "root".

as whole world of thirdparty checks might be affected in same way.

Yes, but update is simple: either get the first child of COMPILATION_UNIT in beginTree()and let the check function as it did previously, or add the COMPILATION_UNIT token to your check and treat it like other checks now (with visitToken()). Also, we have the isRootNode() method to check for top level nodes now when ascending to the top of the tree.

@nrmancuso nrmancuso force-pushed the issue-3095-b branch 2 times, most recently from ae57d83 to 4e7f3da Compare August 14, 2021 14:44
Copy link
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.

items:

Copy link
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.

OkOk to merge

@pbludov pbludov requested a review from rnveach August 19, 2021 14:17
@pbludov pbludov assigned rnveach and unassigned pbludov Aug 19, 2021
@romani
Copy link
Member

romani commented Aug 19, 2021

@nmancus1 , please resolve conflict

Copy link
Member

@rnveach rnveach left a comment

Choose a reason for hiding this comment

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

Has any regression been done to sevntu? This will also be a breaking change for it.
EDIT: There is a blocked PR for that in sevntu.

config/suppressions-xpath.xml Show resolved Hide resolved
src/xdocs/config_filters.xml Show resolved Hide resolved
@rnveach rnveach merged commit 5f1f940 into checkstyle:master Aug 19, 2021
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.

Add COMPILATION_UNIT token in Ast Tree, remove EOF token
5 participants