Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xbase Expressions supporting xtend extension feature call scoping
Xbase Expressions supporting xtend extension feature call scoping [message #1705801] Wed, 19 August 2015 09:29 Go to next message
Bernhard Buss is currently offline Bernhard BussFriend
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
Re: Xbase Expressions supporting xtend extension feature call scoping [message #1705814 is a reply to message #1705801] Wed, 19 August 2015 10:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

this is not a static Extension, it is a dynamic one.
maybe you can use org.eclipse.xtext.xbase.scoping.batch.FeatureScopes.createDynamicExtensionsScope(XExpression, LightweightTypeReference, EObject, IScope, IFeatureScopeSession, IFeatureScopeSession, IResolvedTypes)
as starting Point for your digging into the code


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase Expressions supporting xtend extension feature call scoping [message #1705839 is a reply to message #1705801] Wed, 19 August 2015 12:18 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Bernard,

it should work if you infer the field with an
@org.eclipse.xtext.xbase.lib.Extension annotation.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Xbase Expressions supporting xtend extension feature call scoping [message #1705875 is a reply to message #1705839] Wed, 19 August 2015 17:14 Go to previous message
Bernhard Buss is currently offline Bernhard BussFriend
Messages: 13
Registered: September 2014
Junior Member
Thanks Sebastian

The inference of a field with Extension annotation works! So the simple use case is covered.

For the more complicated one we decided to infer interfaces for now and replace the type of the variable to use the inferred interface instead of making the feature call smart.

But I would be interested to learn if and how the variable specific extension mechanism would work... e.g:

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!
Previous Topic:Add XML outline to DSL IDE
Next Topic:Is it possible to use formatter and formatter2 both in one project
Goto Forum:
  


Current Time: Tue Mar 19 10:50:30 GMT 2024

Powered by FUDForum. Page generated in 0.02004 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top