Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext 2.3 Static Properties
Xtext 2.3 Static Properties [message #895353] Thu, 12 July 2012 14:25 Go to next message
Veit Hoffmann is currently offline Veit HoffmannFriend
Messages: 20
Registered: July 2009
Junior Member
Hi,

I'm trying to infer/create .java-files for a dsl.
Appart from creating methods and properies, that are described in the
DSL I need to create additional elements that are not explicitely
modelled in the DSL.
More precise I need to create a Singleton. Thus I need to create a
static property and a static method getInstance().
As an example I tried to realize this with the DomainmodelExample
Yet I didn't manage to get a satisfactory result.
So far I tried extending the ModelInferrer that comes with the example
without success. Is this possible at all? From reading the newsgroup it
looks if creating new elements static on the fly is not supported. Does
this still count for V 2.3?

If this is not possible is there an easy way to extend the
ModelGenerator or do I have to create a complete IGenerator from scratch?

Thanks in advance

Veit
Re: Xtext 2.3 Static Properties [message #895374 is a reply to message #895353] Thu, 12 July 2012 15:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

why shouldnt this work

members += entity.toField("INSTANCE", it.newTypeRef()) [
				val Procedure1<ITreeAppendable> init = [it.append('''new «entity.name»();''')]
				initializer =  init
				^static = true
			]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext 2.3 Static Properties [message #895514 is a reply to message #895374] Fri, 13 July 2012 11:09 Go to previous message
Veit Hoffmann is currently offline Veit HoffmannFriend
Messages: 20
Registered: July 2009
Junior Member
Hi Christian,
thanks for the quick response. It works like a charm.
I tried something similar before, but i din't quite manage to get the
Closure right.


Cheers Veit

For somebody else who read this. This is the accessor method code:

members += e.toMethod("getInstance", it.newTypeRef()) [
val Procedure1<ITreeAppendable> init =
[it.append('''if(INSTANCE== null){
INSTANCE = new «e.name»();
}
return INSTANCE;''')]
body= init
^static = true
]


Am 12.07.2012 17:26, schrieb Christian Dietrich:
> members += entity.toField("INSTANCE", it.newTypeRef()) [
> val Procedure1<ITreeAppendable> init =
> [it.append('''new «entity.name»();''')]
> initializer = init
> ^static = true
> ]
Previous Topic:How to disable auto activation of content assist
Next Topic:xbase API stability?
Goto Forum:
  


Current Time: Tue Apr 23 12:13:22 GMT 2024

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

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

Back to the top