Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] Casting doesn't work
[Xtend] Casting doesn't work [message #538209] Sun, 06 June 2010 13:03 Go to next message
Michael Schmidt is currently offline Michael SchmidtFriend
Messages: 8
Registered: July 2009
Junior Member
Hi,

I'm writing a model transformation which should add standard properties to all classes. I try to cast the created Property to NamedElement because the Property interface does not contain the setName() method:

create Property testAttribute():
((uml::NamedElement) this).setName("Test");

The Workflow seems to ignore this, because it stops with following error:
2859 ERROR WorkflowRunner - Workflow interrupted. Reason: Couldn't find operation 'setName(String)' for uml::Property.

By the way: If I change the cast to something invalid like:
create Property testAttribute():
((uml::Class) this).setName("Test");
the Editor marks the error but the workflow stops with the same error message like above.

Eclipse version: 3.5
Re: [Xtend] Casting doesn't work [message #538211 is a reply to message #538209] Sun, 06 June 2010 13:33 Go to previous messageGo to next message
Michael Schmidt is currently offline Michael SchmidtFriend
Messages: 8
Registered: July 2009
Junior Member
This way doesn't work either:

Property testAttribute():
let p = new uml::Property : ((uml::NamedElement) p).setName("Test") -> p;
Re: [Xtend] Casting doesn't work [message #538332 is a reply to message #538211] Mon, 07 June 2010 12:01 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello,

maybe you forgot to configure uml in your workflow?
<bean class="org.eclipse.xtend.typesystem.uml2.Setup" standardUML2Setup="true" />
...
<component class="org.eclipse.xpand2.Generator">
  <metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel"/>     
  <metaModel class="org.eclipse.xtend.typesystem.uml2.profile.ProfileMetaModel">
    <profile value="myProfile.profile.uml2"/>
   </metaModel>


Regards
Darius
Re: [Xtend] Casting doesn't work [message #538486 is a reply to message #538209] Mon, 07 June 2010 18:04 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

uml::Property derives from uml::NamedElement, so the cast is not necessary. If used correctly setName() will be known for a Property. I bet you have misconfigured something, try Darius' hint.

~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [Xtend] Casting doesn't work [message #539801 is a reply to message #538486] Sun, 13 June 2010 13:08 Go to previous messageGo to next message
Michael Schmidt is currently offline Michael SchmidtFriend
Messages: 8
Registered: July 2009
Junior Member
I didn't get the suggested config to work yet ...

In the meantime, here is mine:

<workflow>
  <property file="myWorkflow.properties"/>

  <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
    <registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
  </bean>
  
  <component id="xmiParser" class="org.eclipse.emf.mwe.utils.Reader">
    <uri value="${modelFile}"/>
    <modelSlot value="modelSlot"/>
    <firstElementOnly value="true"/>
  </component>
  
  <component id="dirCleaner" class="org.eclipse.emf.mwe.utils.DirectoryCleaner" >
    <directory value="${srcGenPath}"/>
  </component>
  
  <component id="addBasicAttributes" class="org.eclipse.xtend.XtendComponent">
    <metaModel class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
      <metaModelPackage value="org.eclipse.uml2.uml.UMLPackage"/>
    </metaModel>
    <metaModel class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
	  <metaModelPackage value="org.eclipse.emf.ecore.EcorePackage"/>
	</metaModel>
	<invoke value="basic::addBasicAttributes(modelSlot)"/>
  </component>
Re: [Xtend] Casting doesn't work [message #539823 is a reply to message #539801] Sun, 13 June 2010 18:19 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Please try:

<workflow>
  <property file="myWorkflow.properties"/>

  <bean class="org.eclipse.xtend.typesystem.uml2.Setup" standardUML2Setup="true" />

  
  <component id="xmiParser" class="org.eclipse.emf.mwe.utils.Reader">
    <uri value="${modelFile}"/>
    <modelSlot value="modelSlot"/>
    <firstElementOnly value="true"/>
  </component>
  
  <component id="dirCleaner" class="org.eclipse.emf.mwe.utils.DirectoryCleaner" >
    <directory value="${srcGenPath}"/>
  </component>
  
  <component id="addBasicAttributes" class="org.eclipse.xtend.XtendComponent">
    <metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel"/> 
    <invoke value="basic::addBasicAttributes(modelSlot)"/>
  </component>

Re: [Xtend] Casting doesn't work [message #541624 is a reply to message #539823] Mon, 21 June 2010 20:10 Go to previous messageGo to next message
Michael Schmidt is currently offline Michael SchmidtFriend
Messages: 8
Registered: July 2009
Junior Member
Thank You!

I just had to add some missing libraries to the classpath to make it work. (What's left is an awkward feeling that I don't really understand the difference in the configuration.)

But now I have a different problem and hope you can help me too: The create extension seems to return a null value:

Class addAttributes(Class theClass):
  theClass.attribute.add( testAttribute() );
  
create Property testAttribute():
 setName("Test");


This results in this error message:

Error in Component addBasicAttributes of type org.eclipse.xtend.XtendComponent: 
	EvaluationException : null
	basic.ext[175,41] on line 8 'theClass.attribute.add(testAttribute())'     


Any ideas?
Re: [Xtend] Casting doesn't work [message #541667 is a reply to message #541624] Tue, 22 June 2010 06:34 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello,

have in mind that a create extension is a cached extension.
If you want to create an property for every class and not only once in the model,
you have to modify your extension like this:

Class addAttributes(Class theClass):
 theClass.testAttribute();
  
create Property testAttribute(Class theClass):
 setName("Test") ->
 theClass.attribute.add( this );
Re: [Xtend] Casting doesn't work [message #543580 is a reply to message #538209] Tue, 29 June 2010 20:53 Go to previous messageGo to next message
Michael Schmidt is currently offline Michael SchmidtFriend
Messages: 8
Registered: July 2009
Junior Member
Thank you for the hint. But it doesn't fix the problem.

Error in Component addBasicAttributes of type org.eclipse.xtend.XtendComponent: 
	EvaluationException : null
	basic.ext[425,30] on line 18 'theClass.attribute.add(this)'                           
	basic.ext[324,24] on line 14 'theClass.testAttribute()'


I used your code and testet it with the debugger, theClass, the List "attribute" and "this" are not null. Sad
Re: [Xtend] Casting doesn't work [message #543979 is a reply to message #543580] Thu, 01 July 2010 09:06 Go to previous messageGo to next message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hm,

maybe the property have mandatory fields like type you have to set?

Regards
Darius
Re: [Xtend] Casting doesn't work [message #544584 is a reply to message #538209] Sun, 04 July 2010 12:42 Go to previous messageGo to next message
Michael Schmidt is currently offline Michael SchmidtFriend
Messages: 8
Registered: July 2009
Junior Member
Thank you again for the hint, but I'm stuck with the next problem. I stop it here. Somehow it is to complicated to work with Xtend with nothing but the online eclipse help and I'm tired to have to ask in the forum for every new step. Sad

I simply don't know how to set the type:

create Property testAttribute(Class theClass):
 setName("Test") ->
 setType(uml::String) ->
 theClass.attribute.add( this );

Brings this error:

Couldn't find operation 'setType(xpand2::Type)' for uml::Property.
Re: [Xtend] Casting doesn't work [message #544591 is a reply to message #544584] Sun, 04 July 2010 14:54 Go to previous message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009
Member
Hello,

a model-2-model transformation is never easy,
and if you use UML it is very hard Smile

I do not know if other frameworks will have a better support for uml2 transformations.

Please take a look at the Fornax Hibernate Cartridge (it is running with oAW 4.3.1).
http:// fornax.itemis.de/confluence/display/fornax/Hibernate+%28CHB% 29
There is a Model-2-Model transformation (Adding a <<Key>> Property for every <<Entit<>>) in the org::fornax::cartridges::uml2::hibernate::extensions::ModelT ransformation.ext

Regards
Darius Jockel
Previous Topic:[Acceleo 3] Classfier VS Collaboration VS Class
Next Topic:embedded XPand tools in an application
Goto Forum:
  


Current Time: Thu Mar 28 11:41:50 GMT 2024

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

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

Back to the top