Comments (6)
Solution may be to change the code of FeatureCallCompiler
:
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?
from xtext-extras.
May I create a pull request?
Yes.
from xtext-extras.
I don't really get what your intend is here, but @Inline
is not meant to be used outside of the xbase lib and is made to work on static methods only.
Could you explain your use case?
from xtext-extras.
Dear @svenefftinge
I am using @Inline
in two contexts:
- I am using
@Inline
in my Java libraries (http://www.arakhne.org/afc) in order to enable better Java code generation when using the library functions from my DSL language. - And my DSL compiler is detecting "simple" functions (with only a return statement) for generating the
@Inline
annotation and attaching it to the generated Java function.
It should be nice to enable the use of @Inline
annotation outside xbase lib (indeed it is almost ready to be used), because it is a nice feature for helping the xbase-based generators to generate better Java code.
Nevertheless, even if I'm using @Inline
outside its planned scope, I have discovered inconsistency in the meaning of the @Inline
parameters from my point of view, as I have explained in this issue.
I have added patches for solving this in my DSL compiler, and it's working fine.
from xtext-extras.
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
from xtext-extras.
For an example of @Inline
usefull usage for non-static functions:
class X {
@Inline(value="f($1,2)")
def int f(int a) {
return f(a, 2);
}
def int f(int a, int b) {
}
}
from xtext-extras.
Related Issues (20)
- Try-With-Resource broken with Java 8 HOT 5
- Completely Deprecate old Generator + Fragments HOT 1
- Java Source Lang causes NPE HOT 8
- XcoreEcoreTest fails with Xtext 2.20
- xtext-extras compilation fails HOT 7
- Late JvmMember initialization not working HOT 7
- Type parameter in methods from generic interfaces are not translated correctly HOT 4
- Wrong scoping with inferred inner classes
- Inconsistent handling of synthetic fragment for missing obj HOT 19
- AbstractClassMirror.findMember(EObject, String) fails when inner class is used in signature of member before HOT 6
- StandaloneBuilder should provide more information in case of problems HOT 1
- testMemberCount_16 fails with java 17 (and maybe also 16) HOT 1
- Avoid empty lines with two spaces between members HOT 17
- Since Java 15: Unable to reference Java types in the same project HOT 11
- Xbase languages do not correctly track imported names HOT 3
- Support incremental builds via the StandaloneBuilder HOT 3
- XbaseCompiler should be more resilient against broken code
- StandaloneBuilderTest flaky/does not work on Linux HOT 5
- StandaloneBuilder leads to test error in xtext-eclipse with tycho 2x.
- Move to Maven/Tycho for projects and build infrastructure HOT 26
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtext-extras.