Issue #17052: Add support for Flexible constructor bodies#17982
Issue #17052: Add support for Flexible constructor bodies#17982mohitsatr wants to merge 1 commit into
Conversation
|
@mahfouz72, please assist in this PR. |
|
Grammar changes look good to me at this point, but performance seems to have been heavily affected. Can we rerun the job to confirm whether this slowdown is real? |
|
Restarted |
|
Still bad! |
|
code: public Invalid(int arg) {
new InputIndentationCtorCall().super(
arg
+ 1L);
} Old AST: New AST: @mahfouz72, I'm resolving failing Indentation Tests because of this change. I noticed in new AST |
| constructorBlock | ||
| : LCURLY | ||
| blockStatement* | ||
| explicitConstructorInvocation? | ||
| blockStatement* | ||
| RCURLY |
There was a problem hiding this comment.
The klenee star (*) could add a lot of lookahead because now the parser needs to match an arbitrary number of blockStatements before and after the constructor call.
I suggest that we can add hints to help the parser immediately decide.
for example:
(blockStatement { !_input.LT(1).equals("LITERAL_SUPER")}?)*
Another solution is that we can unify under a single statement rule. To move explicitConstructorInvocation into the same rule as blockStatement to eliminate nested stars
constructorBlockStatement
: blockStatement
| explicitConstructorInvocation
;
constructorBlock
: LCURLY constructorBlockStatement* RCURLY
;
The second solution will probably need changes in the JavaASTVisitor layer
There was a problem hiding this comment.
Done. Little tweaking with second approach resovled all the conflicts.
No, you need to debug Please read this doc: https://github.com/checkstyle/checkstyle/blob/master/docs/GRAMMAR_UPDATES.md |
|
@mahfouz72 while I'm figuring it out, here's some findings so far. With current grammer, the following code get evaluated in Example: public Derived(int arg) {
new Outer().super(
arg
+ 1L);
}All the token in constructor's code are the children of but after the change in checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java Lines 1337 to 1341 in 9eceb67
Outer() {}
public int size() { return super.size(); }
public boolean isEmpty() { return Outer.super.isEmpty(); }AST: I think it is not a good idea to handle these both types of ASTs from a single |
77d6696 to
61271c0
Compare
61271c0 to
ceb4316
Compare
|
Now I'm working on adding more test cases and a description |
|
@mohitsatr , we appreciate your help on this. but to clearly see that all is resolved we need to run report on local , as explained at #18079 (comment) as CI version of diff report are focused on ignoring parser problems. |
|
@mohitsatr Hello, may I ask what the progress on this is looking like/is there something I might be able to help with to move this forward when I get some spare time? |
|
@Adrijaned, this Pr is back on top priority now. Just in case you haven't noticed, there's a temporary workaround. |
|
@stoyanK7 @mahfouz72 |
|
@stoyanK7 It is here: https://mohitsatr.github.io/diff/index.html But I'm not sure what to make of it? |
|
https://mohitsatr.github.io/diff/my-checkstyle/index.html#A32 We got an exception, this is not expected, we should only see a difference in AST in files that use the new feature (flexible constructor bodies) |
|
@mahfouz72, do you mean there was a mistake in the report generation process? |
|
@stoyanK7 I'm currently having time constraints, so if you like, feel free to take this one. |
|
Guys, pls check this out: #18821. The build is green now. |
resolves #17052