-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Issue #17052: Add support for Flexible constructor bodies #17982
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
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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
resolves #17052
very WIP
Notes:
Additional info: