Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Trouble getting a list of "items" of a certain type(Xpand/Xtend)
Trouble getting a list of "items" of a certain type [message #518928] Fri, 05 March 2010 13:43 Go to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Hello,

In my metamodel, I created a NamedElement EClass, which has an EAttribute "name" of type EString.
I have a Declaration EClass which ESuper Types is NamedElement,
and an EClass Class which ESUper Types is Declaration.

(so Class extends Declaration extends NamedElement)

in my .ext, I want to create an expression which returns all Class.

I tried
List[Class] classes(NamedElement this) :
	name.typeSelect(Class);


Which doesn't work, I get "Collection type expected! was : String"

Why ?


One day I shall master M2T, but that day has yet to come...
Re: Trouble getting a list of "items" of a certain type [message #518936 is a reply to message #518928] Fri, 05 March 2010 13:57 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello Maxime,

please read the documentation of Expressions in the Xpand Docmentation.

This fragment does not work.
List[Class] classes(NamedElement this) :
	name.typeSelect(Class);

You definet an extension for the type:
'NamedElement'. The expression will first access the property 'name'
and on that property it tries to evaluate the expression '.typeSelect(Class)'.
But typeSelect is only defined for collections Wink

Regards
Darius
Re: Trouble getting a list of "items" of a certain type [message #518955 is a reply to message #518928] Fri, 05 March 2010 14:51 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
Thanks for helping.

I've tried
List[Class] classes(NamedElement this) :
	typeSelect(Class);


which does correct the error sign but I don't think I'm pointing to a Collection. I'm actually trying to get all elements of a type in a Collection, so I guess i'm not solving anything, just displacing the error.
After that I have troubles with the workflow.

When running the workflow, I got
GRAVE: Error in Component  of type org.eclipse.xpand2.Generator: 
	EvaluationException : No Definition 'template::Template::main for metamodel::Model' found!
	[23,41] on line 1 'EXPAND template::Template::main FOR model'

Which I solved(?) by turning NamedElement to not abstract (but I want it to be abstract).

I get a new error now
GRAVE: Error in Component  of type org.eclipse.xtend.check.CheckComponent: 
	EvaluationException : Type not found : Class
	metamodel::Checks.chk[53,75] on line 5 'Class "No elements defined"'


which points to my Checks.chk,
context Class ERROR "No elements defined" :
	exists(e|Class.isInstance(e));




One day I shall master M2T, but that day has yet to come...
Re: Trouble getting a list of "items" of a certain type [message #518988 is a reply to message #518955] Fri, 05 March 2010 16:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
have you tried

List[Class] classes(NamedElement this) :
	{this}.typeSelect(Class);


{this} creates a list of the given NamedElement this


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Trouble getting a list of "items" of a certain type [message #518990 is a reply to message #518955] Fri, 05 March 2010 16:00 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Maxime,

unlike OCL in Xpand the types don't know their instances (which is a
good thing).

So if you want to find all classes you'll have to pass some container or
context. For instance the following would find all classes in the passed
model:

classes(EObject ctx) :
ctx.eRootContainer.eAllContents.typeSelect(Class);

Sven


Maxime Lecourt schrieb:
> Thanks for helping.
>
> I've tried List[Class] classes(NamedElement this) :
> typeSelect(Class);
>
> which does correct the error sign but I don't think I'm pointing to a
> Collection. I'm actually trying to get all elements of a type in a
> Collection, so I guess i'm not solving anything, just displacing the error.
> After that I have troubles with the workflow.
>
> When running the workflow, I got
> GRAVE: Error in Component of type org.eclipse.xpand2.Generator:
> EvaluationException : No Definition 'template::Template::main for
> metamodel::Model' found!
> [23,41] on line 1 'EXPAND template::Template::main FOR model'
>
> Which I solved(?) by turning NamedElement to not abstract (but I want it
> to be abstract).
>
> I get a new error now
> GRAVE: Error in Component of type
> org.eclipse.xtend.check.CheckComponent: EvaluationException : Type
> not found : Class
> metamodel::Checks.chk[53,75] on line 5 'Class "No elements defined"'
>
>
> which points to my Checks.chk,
> context Class ERROR "No elements defined" :
> exists(e|Class.isInstance(e));
>
>


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Trouble getting a list of "items" of a certain type [message #519270 is a reply to message #518990] Mon, 08 March 2010 10:43 Go to previous messageGo to next message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
>unlike OCL in Xpand the types don't know their instances (which is a
>good thing).

I see. As the syntax is nearly the same, I thought it worked the same. Is it a good thing because of problems with inheritance that would have arisen ?

>So if you want to find all classes you'll have to pass some container or
>context. For instance the following would find all classes in the passed
>model:

>classes(EObject ctx) :
>ctx.eRootContainer.eAllContents.typeSelect(Class);

Thanks, I can't test it yet, but Eclipse doesn't find any error anymore.

I now have but one problem left (I hope).
When I run the workflow, I still get an error.

Quote:
INFO: Generator: generating 'template::Template::main FOR model' => src-gen
8 mars 2010 11:40:49 org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflo wComponent invokeInternal
GRAVE: Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : No Definition 'template::Template::main for metamodel::Model' found!
[23,41] on line 1 'EXPAND template::Template::main FOR model'


As my Template.xpt starts like this
«IMPORT metamodel»

«EXTENSION template::GeneratorExtensions»

«DEFINE main FOR NamedElement»
	«FILE TypeFileName ()»
		«EXPAND typedef FOREACH typedefs()»
	«ENDFILE»
	«EXPAND maStruct FOREACH classes()»
«ENDDEFINE»

I guess I'm not pointing towards the right model.

I think I have to modify my workflow (which looks like that)
Quote:
<!-- generate code -->
<component class="org.eclipse.xpand2.Generator">
<metaModel idRef="mm"/>
<expand
value="template::Template::main FOR model" />
<outlet path="${src-gen}" >
<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
</outlet>
<!-- globalVarDef name="TypeFileName" value="'types.h'"/ -->
</component>



Regards
Maxime


One day I shall master M2T, but that day has yet to come...
Re: Trouble getting a list of "items" of a certain type [message #519333 is a reply to message #519270] Mon, 08 March 2010 14:30 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Maxime,

> Quote:
>> INFO: Generator: generating 'template::Template::main FOR model' =>
>> src-gen
>> 8 mars 2010 11:40:49
>> org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflo
>> wComponent invokeInternal
>> GRAVE: Error in Component of type org.eclipse.xpand2.Generator:
>> EvaluationException : No Definition 'template::Template::main for
>> metamodel::Model' found!
>> [23,41] on line 1 'EXPAND template::Template::main FOR model'
>
>
> As my Template.xpt starts like this
> «IMPORT metamodel»
>
> «EXTENSION template::GeneratorExtensions»
>
> «DEFINE main FOR NamedElement»
> «FILE TypeFileName ()»
> «EXPAND typedef FOREACH typedefs()»
> «ENDFILE»
> «EXPAND maStruct FOREACH classes()»
> «ENDDEFINE»

You're passing an instance of metamodel::Model not and instance of
NamedElement. Assumed that the model contains named elements, you could
write

<expand value="template::Template::main FOREACH model.eContents" />

Or you could introduce a definition for metamodel::Model:

<<DEFINE main FOR Model>>
<<EXPAND main FOREACH this.eContents>>
<<ENDDEFINE>>

Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Trouble getting a list of "items" of a certain type [message #519340 is a reply to message #518928] Mon, 08 March 2010 14:54 Go to previous message
MaximeLecourt  is currently offline MaximeLecourt Friend
Messages: 108
Registered: February 2010
Location: France
Senior Member
The problem was with my definitions, I didn't point to the right thing.

Thank you

Regards,

Maxime


One day I shall master M2T, but that day has yet to come...
Previous Topic:Xpand: could not find the property exception
Next Topic:how to link xpand in workflow file
Goto Forum:
  


Current Time: Sat Apr 20 08:52:21 GMT 2024

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

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

Back to the top