Xbase Expressions supporting xtend extension feature call scoping [message #1705801] |
Wed, 19 August 2015 09:29 |
Bernhard Buss Messages: 13 Registered: September 2014 |
Junior Member |
|
|
Hi,
We have a DSL based on Xbase with custom expressions, and now would like to provide a feature similar to the one in Xtend that allows to call extension features of imported of locally injected extension fields.
How would this best be done using Xbase?
Here some pseudo code to illustrate:
extension A; // A is an inferred JvmDeclaredType with methods, e.g. hello(String name)
"Barnski".hello // XExpression which shall be transformed to: A.hello("Barnski")
I hope that explains it well enough. Now I see multiple ways of approaching this, but I would like to know from the xbase experts what is the most appropriate one. I see these approaches:
1. When inferring the body of above's code, transform expression "Barnski".hello to A.hello("Barnski"), using the information from the DSL model (extension A).
2. Customize Xbase FeatureCall scoping similar to static Java class Extensions registered in ImplicitlyImportedFeatures. Is this possible with a dynamically inferred JvmDelcaredType instead of a Java class?
3. Customize xbase FeatureCall scoping to look at DSL model and add additional features available for scoping. Requires additionally to change Java code compiler so that correct java code is generated.
Then, for a second use case, extensions shall be applicable to variables only, not all variables of a given type. Which approach would work for that?
String b = "Barnski"
String c = "error"
extension A for b; // A is an inferred JvmDeclaredType with methods, e.g. hello(String name)
b.hello // XExpression which shall be transformed to: A.hello("Barnski")
c.hello // should not be allowed
Thanks,
Bernhard
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02004 seconds