-
Notifications
You must be signed in to change notification settings - Fork 38
Feature call of constant inline expressions #43
Comments
Solution may be to change the code of private static boolean isConstantExpression(JvmAnnotationReference reference) {
for (final JvmAnnotationValue annotationValue: reference.getValues()) {
if ("constantExpression".equals(annotationValue.getValueName())) {
return ((JvmBooleanAnnotationValue) annotationValue).getValues().get(0).booleanValue();
}
}
return false;
}
@Override
protected void featureCalltoJavaExpression(final XAbstractFeatureCall call, ITreeAppendable output,
boolean isExpressionContext) {
if (call instanceof XAssignment) {
assignmentToJavaExpression((XAssignment) call, output, isExpressionContext);
} else {
if (needMultiAssignment(call)) {
appendLeftOperand(call, output, isExpressionContext).append(" = "); //$NON-NLS-1$
}
ITreeAppendable child = output;
final JvmAnnotationReference annotationRef = this.expressionHelper.findInlineAnnotation(call);
if (annotationRef == null || !isConstantExpression(annotationRef)) {
final boolean hasReceiver = appendReceiver(call, output, isExpressionContext);
if (hasReceiver) {
output.append("."); //$NON-NLS-1$
child = appendTypeArguments(call, output);
}
}
appendFeatureCall(call, child);
}
} The idea is to skip the receiver when the inline expression is constant. May I create a pull request? |
Yes. |
This PR fixes the invalid generated code when constant inline expressions are invoked. close eclipse#43 Signed-off-by: Stéphane Galland <galland@arakhne.org>
This PR fixes the invalid generated code when constant inline expressions are invoked. close eclipse#43 Signed-off-by: Stéphane Galland <galland@arakhne.org>
This PR fixes the invalid generated code when constant inline expressions are invoked. close eclipse#43 Signed-off-by: Stéphane Galland <galland@arakhne.org>
I don't really get what your intend is here, but |
Dear @svenefftinge I am using
It should be nice to enable the use of Nevertheless, even if I'm using I have added patches for solving this in my DSL compiler, and it's working fine. |
Thank you. I wanted to understand what the purpose of your use of 'constantExpression' is, since a constant expression by definition can not come from an instance, it doesn't make sense to me to allow it on non-static members. Also see https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28 |
For an example of
|
This PR fixes the invalid generated code when constant inline expressions are invoked. close eclipse#43 Signed-off-by: Stéphane Galland <galland@arakhne.org>
This PR fixes the invalid generated code when constant inline expressions are invoked. close eclipse#43 Signed-off-by: Stéphane Galland <galland@arakhne.org>
Let a not-static function with an inline constant expression:
The generated Java code for the
test
function is:The Java code has a syntax error because
1
is not a valid member ofC1
.The text was updated successfully, but these errors were encountered: