Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] LET statement
[Xpand] LET statement [message #506220] Wed, 06 January 2010 14:52 Go to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi,

I have a 'component' metamodel. In this metamodel a component have
ports, and each port is typed by a interface.
From a corresponding model I want to generate all referenced interfaces
by component's ports.
I want also to use PROTECT BLOCK feature with the ID generation, but I
must not generate several times the same PROTECT BLOCK.
Then I must know I a current interface in my template generation has
been already generated. To do that I think about a global variable which
keep all generated interface like this :

«LET Set[String] AS generatedInterfaces»
«»
«ENDLET»

and add generated interface in a EXPAND/FILE statement like this :
«generatedInterfaces.put(interface)»

Unfortunaly this doesn't works.

Xpand documentation only describe LET statement with the String
primitive type.

Any help would be welcome.

For more details see
http://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/v1/p lugins/fr.inria.adam.calico.models.generation.xpand.fractalT emplate/models/?root=calico
Launcher.java permits to launch the xpand template without MWE.

Best Regards.
Re: [Xpand] LET statement [message #506348 is a reply to message #506220] Thu, 07 January 2010 08:53 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg ReichertFriend
Messages: 80
Registered: July 2009
Location: Leipzig
Member
Hello Esteban,

you can use
«LET {} AS generatedInterfaces»
«»
«ENDLET»

that creates an empty list (no set, so you have to check with generatedInterfaces.contains(...) whether the element is already contained when filling the list.

Another option is to use the globalvar extension:
First you have to add org.eclipse.xtend.util.stdlib to your plugin dependencies.
Then you write an extension (existence_tester.ext):
import <your meta model>;
extension org::eclipse::xtend::util::stdlib::globalvar;

boolean hasNotBeenUsedYet(String att) :
	let atts = (List[String]) getGlobalVar("atts") :
		if(atts == null) then ( 
			storeGlobalVar("atts", { att }) ->
			true
		)	
		else (
			if(atts.contains(att)) then false
			else (
				atts.add(att) ->
				storeGlobalVar("atts", atts) ->
				true
			)
		)	
;


In your Xpand you can use it like that:
«EXTENSION existence_tester»
...
   «IF hasNotBeenUsedYet("a")»test a«ENDIF»
   «IF hasNotBeenUsedYet("b")»test b«ENDIF»
   «IF hasNotBeenUsedYet("a")»test c«ENDIF»
   «IF hasNotBeenUsedYet("b")»test d«ENDIF»
...

which should result in an output
a
b


Maybe the second solution is too complicated for your needs but it would free you from filling the generated interfaces set in the same place as checking its content.

Joerg
Re: [Xpand] LET statement [message #506359 is a reply to message #506348] Thu, 07 January 2010 09:30 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Joerg Reichert schrieb:
> Hello Esteban,
>
> you can use
>
> «LET {} AS generatedInterfaces»
> «»
> «ENDLET»
>
> that creates an empty list (no set, so you have to check with
> generatedInterfaces.contains(...) whether the element is already
> contained when filling the list.

{}.toSet() would make it a set.

Cheers,
Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: [Xpand] LET statement [message #506366 is a reply to message #506359] Thu, 07 January 2010 10:14 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Joerg & Sven,

I have tried the two solutions without success, I have always these
followings warnings :

0 [main] INFO and2.pr.ProtectedRegionResolverImpl - Source scan
started ...
6 [main] INFO and2.pr.ProtectedRegionResolverImpl - Source scan
finished in 0.004s
6 [main] INFO and2.pr.ProtectedRegionResolverImpl - Files scanned: 17
6 [main] INFO and2.pr.ProtectedRegionResolverImpl - Regions found: 10
11 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'IHM.run' referenced more than once
103 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'IHM.run' referenced more than once
104 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'PDA.run' referenced more than once
106 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'IHM.run' referenced more than once
116 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'PC.run' referenced more than once
118 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'Authentification.auth' referenced more than once
119 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'GlobalSearch.getData' referenced more than once
121 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'RevocationList.check' referenced more than once
123 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'SessionServer.newTicket' referenced more than once
123 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'SessionServer.checkTicket' referenced more than once
125 [main] WARN and2.pr.ProtectedRegionResolverImpl - Protected
region with ID 'MedicalServer.getPicture' referenced more than once
127 [main] INFO org.eclipse.xpand2.Generator - Written 25
files to outlet
[default](/home/esteban/CALICO/trunk/v1/plugins/fr.inria.ada m.calico.models.generation.xpand.fractalTemplate/src-gen)


My attempts are commited :

http://gforge.inria.fr/plugins/scmsvn/viewcvs.php/trunk/v1/p lugins/fr.inria.adam.calico.models.generation.xpand.fractalT emplate/models/?root=calico

I must notice that I execute my Xpand template from Java.

Best Regards.

Sven Efftinge wrote:
> Joerg Reichert schrieb:
>> Hello Esteban,
>>
>> you can use
>>
>> «LET {} AS generatedInterfaces»
>> «»
>> «ENDLET»
>>
>> that creates an empty list (no set, so you have to check with
>> generatedInterfaces.contains(...) whether the element is already
>> contained when filling the list.
>
> {}.toSet() would make it a set.
>
> Cheers,
> Sven
>
Re: [Xpand] LET statement [message #506440 is a reply to message #506366] Thu, 07 January 2010 14:36 Go to previous message
Joerg Reichert is currently offline Joerg ReichertFriend
Messages: 80
Registered: July 2009
Location: Leipzig
Member
Hello Esteban,

you iterate too often over the subcomponents:

in main you call

«EXPAND componentImplementation FOREACH this.subComponents»
«EXPAND componentImplementation FOR this»

and in componentImplementation you also call

«EXPAND componentImplementation FOREACH this.subComponents»


So you override already generated files and the protected region id collector emits these warn statements as it is served with already collected ids.

Cheers,
Joerg


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: [Xpand] LET statement [message #506472 is a reply to message #506440] Thu, 07 January 2010 11:18 Go to previous message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Yes you are right,

a stupid mistake on my part.

Thanks Joerg.

Joerg Reichert wrote:
> Hello Esteban,
>
> you iterate too often over the subcomponents:
>
> in main you call
>
>
> «EXPAND componentImplementation FOREACH this.subComponents»
> «EXPAND componentImplementation FOR this»
>
> and in componentImplementation you also call
>
>
> «EXPAND componentImplementation FOREACH this.subComponents»
>
>
> So you override already generated files and the protected region id
> collector emits these warn statements as it is served with already
> collected ids.
>
> Cheers,
> Joerg
>
Previous Topic:[Acceleo] Acceleo profiler hide other profiler
Next Topic:[Check] Using models referencing other models in OAW
Goto Forum:
  


Current Time: Tue Oct 16 00:06:11 GMT 2018

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

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

Back to the top