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 #14620: LITERAL_CASE token support in RightCurlyCheck #14623

Merged
merged 1 commit into from Apr 17, 2024

Conversation

mahfouz72
Copy link
Member

@mahfouz72 mahfouz72 commented Mar 7, 2024

@mahfouz72 mahfouz72 changed the title Issue #14620: add LITERAL_CASE token support in RightCurlyCheck Issue #14620: LITERAL_CASE token support in RightCurlyCheck Mar 8, 2024
@mahfouz72
Copy link
Member Author

@nrmancuso @rnveach can you guide me on how to solve this CI failure related to checker I am not familiar with it

also the purpose of this function is to skip switch expressions when we getDetailsForSwitch() token why is that ? and should I do the same here in this PR

private static boolean isSwitchExpression(DetailAST switchNode) {
DetailAST currentNode = switchNode;
boolean ans = false;
while (currentNode != null) {
if (currentNode.getType() == TokenTypes.EXPR) {
ans = true;
}
currentNode = currentNode.getParent();
}
return ans;

and please review changes if all is good

@nrmancuso
Copy link
Member

@nrmancuso @rnveach can you guide me on how to solve this CI failure related to checker I am not familiar with it

Let's wait until we are getting close to merge to deal with this, code might change by then :) But what Checker is telling us is that basically it expects the DetailAST to be non-null, and you are passing in a potentially null object instead.

also the purpose of this function is to skip switch expressions when we getDetailsForSwitch() token why is that ? and should I do the same here in this PR

Ah, I had forgotten about this. I do not totally understand this "limitation", but since we have an open issue on it, let's also avoid switch expressions here. You can use git blame on this method to find the associated PR and read more if you are interested.

So, the answer to

should I do the same here in this PR

is yes. Make sure we have some in our inputs to verify this behavior.

Looking good so far!

@nrmancuso
Copy link
Member

@mahfouz72 I am going to place this PR into draft mode while you keep working :)

@nrmancuso nrmancuso marked this pull request as draft March 8, 2024 16:57
@mahfouz72 mahfouz72 force-pushed the support-case-in-rcurly branch 3 times, most recently from 63d41ef to 8119c30 Compare March 9, 2024 14:20
@mahfouz72
Copy link
Member Author

Github, generate report

@mahfouz72
Copy link
Member Author

Github, generate site

Copy link
Contributor

github-actions bot commented Mar 9, 2024

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/8215154947

@mahfouz72
Copy link
Member Author

Github, generate report

@mahfouz72
Copy link
Member Author

Github, generate report

@mahfouz72
Copy link
Member Author

Github, generate report

Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

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

@mahfouz72 let's try to make Checker happy and place @Nullable annotation on Details constructor arguments lcurly and rcurly. If this doesn't help, we can just update suppression file.

@mahfouz72
Copy link
Member Author

Github, generate report

@mahfouz72
Copy link
Member Author

If this doesn't help, we can just update suppression file.

this works but produced new survivals

<checkerFrameworkError unstable="false">
    <fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheck.java</fileName>
    <specifier>assignment</specifier>
    <message>incompatible types in assignment.</message>
    <lineContent>this.lcurly = lcurly;</lineContent>
    <details>
      found   : @Initialized @Nullable DetailAST
      required: @Initialized @NonNull DetailAST
    </details>
  </checkerFrameworkError>

  <checkerFrameworkError unstable="false">
    <fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/blocks/RightCurlyCheck.java</fileName>
    <specifier>assignment</specifier>
    <message>incompatible types in assignment.</message>
    <lineContent>this.rcurly = rcurly;</lineContent>
    <details>
      found   : @Initialized @Nullable DetailAST
      required: @Initialized @NonNull DetailAST
    </details>
  </checkerFrameworkError>

@mahfouz72 mahfouz72 force-pushed the support-case-in-rcurly branch 2 times, most recently from 8b3c959 to 3d6464f Compare March 10, 2024 08:05
@mahfouz72 mahfouz72 marked this pull request as ready for review March 10, 2024 08:18
@mahfouz72
Copy link
Member Author

mahfouz72 commented Mar 10, 2024

@nrmancuso checker is falling even after adding suppression build successbut process exit with code 1 idk why. also Please Check PR description for report and site

@mahfouz72
Copy link
Member Author

@rnveach ping

@rnveach
Copy link
Member

rnveach commented Apr 13, 2024

I see production code changes after #14623 (comment) , so we need a new report.

@mahfouz72
Copy link
Member Author

Github, generate report

@rnveach
Copy link
Member

rnveach commented Apr 13, 2024

I think I am good with the PR. I want to review the latest report first.

@mahfouz72
Copy link
Member Author

mahfouz72 commented Apr 13, 2024

@rnveach here is the latest report
to ease review for you. I reviewed it first and all lgtm expect this I am not sure about it. the thing is that according to AST both LITERAL_CASE and LITERAL_DEFAULT are under the same parent (CASE_GROUP) and the { } are for both of them

        |       |   |--CASE_GROUP -> CASE_GROUP [6:14]
        |       |   |   |--LITERAL_CASE -> case [6:14]
        |       |   |   |   |--EXPR -> EXPR [6:19]
        |       |   |   |   |   `--NUM_INT -> 1 [6:19]
        |       |   |   |   `--COLON -> : [6:21]
        |       |   |   |--LITERAL_DEFAULT -> default [7:14]
        |       |   |   |   `--COLON -> : [7:21]
        |       |   |   `--SLIST -> SLIST [7:23]
        |       |   |       `--SLIST -> { [7:23]
        |       |   |           `--RCURLY -> } [8:14]

this will be more reasonable when we add support for default. I opened an issue for this and will add support for default after merging this PR

what do you think is it normal to validate this }? As it is technically a brace for the case, not the default only

@rnveach
Copy link
Member

rnveach commented Apr 15, 2024

expect this I am not sure about it

How does LeftCurly handle this case if only LITERAL_CASE token is added? We are basing all the logic here off of duplicating Left's logic just for Rights.

@mahfouz72
Copy link
Member Author

Github, generate report

@rnveach
Copy link
Member

rnveach commented Apr 15, 2024

Please let me know what to expect from #14623 (comment) .

@mahfouz72
Copy link
Member Author

leftCurlyCheck handles it differently. the braces in our example are not considered with case they are considered with the default only and this is correct IMO, So I made a small change to handle it as leftCurlyCheck does

for leftCurlyCheck when LITERAL_CASE only is added

case 0:
default: 
{               // no violation 
} ; 

so we should expect now after the last change. that this should have no violation

@mahfouz72
Copy link
Member Author

@rnveach report is good. The violation was removed from #14623 (comment) and there are no differences between the last report and the previous one rather than this case. I think we are good to go now

@rnveach
Copy link
Member

rnveach commented Apr 16, 2024

@mahfouz72 Did you regenerate all 3 reports in #14623 (comment) ? I would want to see all 3 since this is a new token and it has many different options.

@mahfouz72
Copy link
Member Author

Github, generate report

@mahfouz72
Copy link
Member Author

Github, generate report

@mahfouz72
Copy link
Member Author

@rnveach please check #14623 (comment) reports for all 3 options has been regenerated and all lgtm
I updated PR description it has the final reports now

@rnveach rnveach merged commit 4dd8f51 into checkstyle:master Apr 17, 2024
111 of 113 checks passed
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.

LITERAL_CASE token support in RightCurlyCheck
4 participants