-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
fix: backward compatible modeling of try-with-resource #4625
Conversation
the diff is now clean here |
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.
Only some very minor style suggestions, otherwise looks good. 👍
assertEquals("resource", ((CtVariable<?>) ctResource).getSimpleName()); | ||
|
||
// contract: pretty-printing of existing resources works | ||
assertEquals("try (resource) {"+System.getProperty("line.separator")+"}", tryStmt.toString()); |
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.
You could use the LinespeparatorExtension here and \n
in the testcase.
assertTrue(ctResource instanceof CtVariableRead); | ||
assertEquals("resource", ((CtVariableRead<?>) ctResource).getVariable().getSimpleName()); | ||
assertTrue(ctResource instanceof CtVariable); | ||
assertEquals("resource", ((CtVariable<?>) ctResource).getSimpleName()); |
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.
Convert the spaces to tabs here. We are not super strict with formatting in testcases but a method should either use spaces or tabs, not both
// we have to find it manually | ||
for (ASTPair pair: this.jdtTreeBuilder.getContextBuilder().stack) { | ||
final List<CtLocalVariable> variables = pair.element.getElements(new TypeFilter<>(CtLocalVariable.class)); | ||
if (variables.size() > 0) { |
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.
if (variables.size() > 0) { | |
if (!variables.isEmpty()) { |
tryWithResource.addResource((CtLocalVariable) child); | ||
} else if (child instanceof CtVariableRead) { | ||
// special case of the resource being declared before | ||
final CtVariableReference<?> variableRef = ((CtVariableRead<?>) child).getVariable(); |
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.
Are there any reasons for the final modifiers, especially for Collections
?
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 IDE puts it automatically, and it does not hurt.
Thanks fixed all comments |
thanks @monperrus |
I confirm that the regression identified in NpeFix is solved: https://ci.inria.fr/sos/job/npefix/1861/ |
An iteration about try-with-resources on top of #4371.
Before the resource declaration was a CtVariableRead, which is not natural and breaking.
Now a resource is an implicit variable declaration. The main advantage is that it is fully backward compatible (hence we would fix https://ci.inria.fr/sos/job/npefix/)
Plus, I've added a test on pretty-printing.