-
Notifications
You must be signed in to change notification settings - Fork 320
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
Xtend refactoring handling of anonymous class #2898
Xtend refactoring handling of anonymous class #2898
Conversation
there's no need to store the converter
use getNamedType instead of manually retrieving the last element of supertypes
instead of redefining _toJavaStatement we redefine constructorCallToJavaExpression and we call it also in other parts
when redefining them it's useless to make them public; when used internally, make them private
This is another working proposal for this issue that does not touch the inferred model. the changes are rather minimal:
This way, during the Xtend compilation process, anonymous classes are correctly generated as Java anonymous classes or nested local classes. All the tests are green. All the generated code is as before. No test has been touched apart from this one https://github.com/eclipse/xtext/pull/2898/files#diff-8d2c98464642a8554f494c6f4c1de6f865cbec0d6cb5b288412da41e6067cba1L222 of course. |
/** | ||
* @author Lorenzo Bettini - Initial contribution and API | ||
*/ | ||
public class XtendCompilerHelper { |
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.
Since this can only answer whether a JvmType can be compiled to an anonymous class, maybe a more restrictive name should be chosen?
AnonymousClassCompilerHelper
?
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.
Indeed that was my second choice, so I'll rename it :)
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.
By the way, we already have https://github.com/eclipse/xtext/blob/88acf1555988cd81e1756abc0d6d2c3f1f1efa11/org.eclipse.xtend.core/src/org/eclipse/xtend/core/jvmmodel/AnonymousClassUtil.java#L39
should I put the methods of XtendCompilerHelper
directly there?
@@ -320,7 +330,9 @@ class XtendGenerator extends JvmModelGenerator implements IGenerator2 { | |||
} | |||
if (declaringType.local && it instanceof JvmOperation) { | |||
val declarator = declaringType as JvmGenericType | |||
if (!declarator.anonymous) { | |||
if (!declarator.anonymous || |
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.
I'm not sure whether I like the fact that the helper doesn't check the declarator itself but this code here has to do both.
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.
Indeed I had put a Javadoc comment on the helper https://github.com/eclipse/xtext/pull/2898/files/bc766b0068465148679855a36c8c9c88e5c62065#diff-c6ea2a981e27e70dc2cd53ff982ee051ac65096607807462e10196d625518f88R35
to avoid a check there, but if you prefer we can check isAnonymous
directly in the helper, if that's what you mean.
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.
@szarnekow I've just pushed 6af742c
that check for anonymous is redundant
feature.localClasses.filter[ !anonymous ].forEach[ | ||
appendable.newLine | ||
feature.localClasses.forEach[ | ||
if (compilerHelper.canCompileToJavaAnonymousClass(it)) { |
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.
Yet this code here doesn't do both.
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.
At least in the current implementation anonymous classes are local classes
/** | ||
* @since 2.34 | ||
*/ | ||
def TreeAppendable createAppendable(ImportManager importManager, ITraceURIConverter converter, |
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.
Could this be protected?
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.
Right! I think so.
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.
Overall, I like this change. Just a few small comments / questions.
Closing and re-opening to trigger CI rebuild |
Another proposal for #2886