Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext 2.3 Static Properties
Xtext 2.3 Static Properties [message #895353] Thu, 12 July 2012 10:25 Go to next message
Eclipse UserFriend
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 11:26 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

why shouldnt this work

members += entity.toField("INSTANCE", it.newTypeRef()) [
				val Procedure1<ITreeAppendable> init = [it.append('''new «entity.name»();''')]
				initializer =  init
				^static = true
			]
Re: Xtext 2.3 Static Properties [message #895514 is a reply to message #895374] Fri, 13 July 2012 07:09 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 05:14:49 EDT 2025

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

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

Back to the top