Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Model inferrer assign non final content to body
Model inferrer assign non final content to body [message #1740445] Fri, 12 August 2016 21:09 Go to next message
Haniball Hanj is currently offline Haniball HanjFriend
Messages: 2
Registered: August 2016
Junior Member
I try to keep it simple... I cannot assign my generated content (kind of string concatination) to the body of my JvmModelInferrer

Pseudocode:
counter = 0 //changing content
PMethod : {
	members += feature.toMethod(feature.name, feature.newTypeRef(Void.TYPE)) [
	  documentation = feature.documentation
	  
	  body = '''«feature.name»''' //WORKS (final variable)
          ###versus###
	  body = '''«counter»''' //DOES [b]NOT[/b] WORK (two pMethods will have same content!)
	  
	  counter++
	]
}


Am I doing something completely wrong here? Didn't evven notice that something is wrong until I tried two PMethods in my final project and noticed that they have the same content.
Re: Model inferrer assign non final content to body [message #1740541 is a reply to message #1740445] Mon, 15 August 2016 14:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please share a complete minimal reproducing inferrer i wonder how this can compile at all since counter is not final

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Model inferrer assign non final content to body [message #1740969 is a reply to message #1740541] Sun, 21 August 2016 21:21 Go to previous message
Haniball Hanj is currently offline Haniball HanjFriend
Messages: 2
Registered: August 2016
Junior Member
I solved it. Seems as if you can't generate a string and just assign it to the predefined body variable inside the JvmModelInferrer. BUT you can create a feature.body variable through the *.xtext file like this
PMethod:
    'public' 'pFunction' name=ValidID '(' ')' '{' 
	    customBodies+=CustomBody*
	    body=STRING?    #<<<< I mean this
    '}';


and then assign the string to feature.body like so
feature.body = myBodyString


And assign this "helper variable" feature.body to the predefined body variable
body = '''«feature.body»'''


So instead of assigning myBodyString directly to body you assign it to feature.body and then feature.body to body.

I don't know if this workaround is intended to work this way but it does and that's all I need at this point ^^

[Updated on: Sun, 21 August 2016 21:25]

Report message to a moderator

Previous Topic:Two DSL in same project
Next Topic:RuntimeException: Cannot root twice
Goto Forum:
  


Current Time: Tue Apr 23 11:46:40 GMT 2024

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

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

Back to the top