Skip to content

Conversation

mahfouz72
Copy link
Member

closes #15055

@nrmancuso nrmancuso self-assigned this Jul 1, 2024
@nrmancuso
Copy link
Contributor

@mahfouz72 CI is failing

@mahfouz72
Copy link
Member Author

falling on master because of release notes violation

@mahfouz72
Copy link
Member Author

@nrmancuso #15178

@mahfouz72 mahfouz72 force-pushed the indentation branch 2 times, most recently from e8d4822 to 27548bc Compare July 1, 2024 12:27
@mahfouz72
Copy link
Member Author

@rnveach rnveach requested review from rnveach and nrmancuso July 2, 2024 03:05
Copy link
Member Author

@mahfouz72 mahfouz72 left a comment

Choose a reason for hiding this comment

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

.

Comment on lines +38 to +54
if (obj instanceof //indent:8 exp:8
ColoredPoint( //indent:0 exp:12 warn
_, //indent:0 exp:12 warn
_, //indent:0 exp:12 warn
_)) {} //indent:0 exp:12 warn

if (obj instanceof //indent:8 exp:8
ColoredPoint( //indent:12 exp:12
_, //indent:12 exp:12
_, //indent:12 exp:12
_)) {} //indent:12 exp:12

if (obj instanceof ColoredPoint( //indent:8 exp:8
_, //indent:12 exp:12
_, //indent:12 exp:12
_)) {} //indent:12 exp:12

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, This is a bit odd I feel like the unnamed patterns should be indented further we can treat it as a RECORD_PATTERN_DEF child. So I think it should be indented a bit after the pattern. like the pattern is indented a bit after if

Copy link
Contributor

@rnveach rnveach Jul 3, 2024

Choose a reason for hiding this comment

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

Show a snippet of what you think better indentation is (current versus yours).

I don't see an issue here (last example) since this is a wrapping of the previous line and all the _, are on the same level.

I could see

            ColoredPoint( //indent:12 exp:12
            _,  //indent:12 exp:12

needing to be indented more to:

            ColoredPoint( //indent:12 exp:12
                _,  //indent:16 exp:16

But indentation check has issues with double line wrapping. It doesn't understand nested expressions should be indented a second time and only do them one time.

Copy link
Member Author

Choose a reason for hiding this comment

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

        if (obj instanceof 
            ColoredPoint( //indent:12 exp:12
                _,  //indent:16 exp:16
                _,  //indent:16 exp:16
                _)) {} //indent:16 exp:16

I wanted it to be like this so basically a double-line wrapping yes, because it is nested inside the record pattern not the if.

But indentation check has issues with double line wrapping. It doesn't understand nested expressions should be indented a second time and only do them one time.

Then I think the current behavior is acceptable if we can't achieve a double line wrapping

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok to leave it as it is for now.

Comment on lines +55 to +81
if (obj instanceof //indent:8 exp:8
Rectangle( //indent:16 exp:12 warn
ColoredPoint( //indent:16 exp:12 warn
boolean x, //indent:24 exp:12 warn
int y, //indent:16 exp:12 warn
_), //indent:24 exp:12 warn
ColoredPoint(_,_,_) //indent:16 exp:12 warn
) //indent:16 exp:8 warn
) {} //indent:8 exp:8

if (obj instanceof //indent:8 exp:8
Rectangle( //indent:0 exp:12 warn
ColoredPoint( //indent:0 exp:12 warn
boolean x, //indent:8 exp:12 warn
int y, //indent:8 exp:12 warn
_), //indent:8 exp:12 warn
ColoredPoint(_,_,_) //indent:0 exp:12 warn
)) {} //indent:8 exp:12 warn

if (obj instanceof //indent:8 exp:8
Rectangle( //indent:12 exp:12
ColoredPoint( //indent:12 exp:12
boolean x, //indent:12 exp:12
int y, //indent:12 exp:12
_), //indent:12 exp:12
ColoredPoint(_,_,_) //indent:12 exp:12
)) {} //indent:12 exp:8 warn
Copy link
Member Author

@mahfouz72 mahfouz72 Jul 3, 2024

Choose a reason for hiding this comment

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

same here for the record pattern components named or unnamed.

I think there is a conflict here ? ( 8 -> 12) then (12 -> 8)

ColoredPoint(_,_,_)  //indent:0 exp:12 warn
        )) {}  //indent:8 exp:12 warn
        ColoredPoint(_,_,_)  //indent:12 exp:12
            )) {}    //indent:8 exp:12 warn ( never satisified)

Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be a new issue if it can never be satisfied.

Copy link
Member Author

Choose a reason for hiding this comment

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

After looking carefully for this example.I think the problem is we have two parens on this line. one paren for the if and one for the record pattern.

The record pattern paren has to be on indent 12 and the if paren has to be on 8. so putting them on the same level will always produce a violation on one of them.

Sorry, there is no conflict here the check just requires a different indentation for each paren.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you can never satisfy this so there is no violations then this IS an issue. All violations should be valid and should be solvable to some extent. Indentation is to guide users to correct indentation. It can't be correct if it is always wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just thought that if this conflict has a valid reason then this is not an issue.but yes users still face a violation that can't be solved
#15193

@rnveach
Copy link
Contributor

rnveach commented Jul 3, 2024

I am good to approve after new issue at #15176 (comment)

@rnveach rnveach merged commit 6271b96 into checkstyle:master Jul 3, 2024
@mahfouz72 mahfouz72 deleted the indentation branch May 9, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Add Check Support for Java 21 Record Pattern Syntax: Indentation
3 participants