Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Enrich Xbase expression programatically in Inferrer
Enrich Xbase expression programatically in Inferrer [message #1713022] Thu, 29 October 2015 21:24 Go to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
Hi,

given the domainmodel example I wan't to programatically surround the expression in the Inferrer of an Operation with a try-catch-block like:

members += f.toMethod(f.name, f.type ?: inferredType) [
	documentation = f.documentation
	for (p : f.params) {
		parameters += p.toParameter(p.name, p.parameterType)
	}
	val expr = XbaseFactory.eINSTANCE.createXTryCatchFinallyExpression
	expr.expression = f.body
	expr.catchClauses += ...
	f.body = expr
	body = expr
]


But this will not work as it will not compile.
Is there any support for enriching/manipulating expressions in Xtext before compiling?
For me this is a strong need and usage of DSL's that the user don't must need to know everything about a target platform and I can analyse and manipulate the expressions at or before compile time.

Any hint is highly appreciated.

Thanks a lot for the help,

Ingo
Re: Enrich Xbase expression programatically in Inferrer [message #1713023 is a reply to message #1713022] Thu, 29 October 2015 21:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi use the delegate-method pattern for that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enrich Xbase expression programatically in Inferrer [message #1713024 is a reply to message #1713023] Thu, 29 October 2015 21:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
@ sebastian zarnekow: do we already have an enhancement to fully support this kind of ast maniplulation?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enrich Xbase expression programatically in Inferrer [message #1713025 is a reply to message #1713023] Thu, 29 October 2015 22:03 Go to previous messageGo to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
If I inferr from one Operation of the model two JvmOpration (one with the model expression and a second one with the try-catch block and a call to the first one) it will not work as the created try-catch expression has no eContainer.
That the main problem, where do I put a programatically created expression?
Or do you mean something else with the delegate-method pattern?
Re: Enrich Xbase expression programatically in Inferrer [message #1713028 is a reply to message #1713025] Thu, 29 October 2015 22:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
dont get the container point.
no programatically created expression. just text

from your source eobject derive 2 methods

1.

body = thing.bodyexpression

2.

body = '''
try {
<<namefrom1>>(....);
} ....
'''


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enrich Xbase expression programatically in Inferrer [message #1713047 is a reply to message #1713028] Fri, 30 October 2015 09:54 Go to previous messageGo to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
Ok, I understand. For this example it will work like that. Thanks.

For my next steps I really need to programatically create expressions by clone and change expressions from the model and compile those new expressions into a JvmOperation's body. I see some places in compiler where the eContainer and NodeHelper things are needed and those are null for programatically created expressions, so the XBase compiler chrashes.
Is there any possibility to compile an programatically created expression?
Should I open an Bugzilla enhancement request for that?
Re: Enrich Xbase expression programatically in Inferrer [message #1713051 is a reply to message #1713047] Fri, 30 October 2015 10:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes please do that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enrich Xbase expression programatically in Inferrer [message #1713771 is a reply to message #1713024] Fri, 06 November 2015 15:14 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
On 29.10.15 22:51, Christian Dietrich wrote:
> @ sebastian zarnekow: do we already have an enhancement to fully support
> this kind of ast maniplulation?

Yes, the feature request is already known, but I don't think we have a
ticket for that yet.

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: Enrich Xbase expression programatically in Inferrer [message #1714363 is a reply to message #1713771] Thu, 12 November 2015 08:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i have created https://bugs.eclipse.org/bugs/show_bug.cgi?id=481992 for this

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Enrich Xbase expression programatically in Inferrer [message #1715277 is a reply to message #1714363] Fri, 20 November 2015 19:35 Go to previous messageGo to next message
Michael Vorburger is currently offline Michael VorburgerFriend
Messages: 103
Registered: July 2009
Senior Member
Hello, similar related problem and found this by chance... I'd like to generate something like:

   private void updateField() {
       this.someField = (...)
   }


where the (...) is from an XExpression. Until https://bugs.eclipse.org/bugs/show_bug.cgi?id=481992 is available, I've attempted

    members += property.toMethod("updateField", typeRef(void)) [
        body = '''this.«property.name» = «property.formula»;'''
    ]


but that doesn't work, of course.. it gives a toString debug representation of the XExpression, not the "compiled" form. So, for now, I'm working around like this:

members += property.toMethod("updateField_", typeRef(String)) [
	visibility = JvmVisibility.PRIVATE
	body = property.formula
]
members += property.toMethod("updateField_, typeRef(void)) [
	visibility = JvmVisibility.PRIVATE
	body = '''this.«property.name» = «property.name»_();'''
]


which generates something like this.. works, but a big ugly, any suggestions how this could be made neater?

   private String updateField_() {
       (...)
   }

   private void updateField() {
       this.someField = updateField_();
   }

Re: Enrich Xbase expression programatically in Inferrer [message #1715299 is a reply to message #1715277] Sat, 21 November 2015 10:42 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes this is what i meant by "delegate-method pattern "

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Different hovers for same data type rule
Next Topic:Outputting to a second window / plugin from DSL plugin
Goto Forum:
  


Current Time: Fri Apr 26 08:33:24 GMT 2024

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

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

Back to the top