Issue with assignment of a String [message #1844024] |
Fri, 27 August 2021 16:41 |
Yves BERNARD Messages: 146 Registered: July 2014 |
Senior Member |
|
|
Hi all,
I've to write a transformation where the input metamodel is UML and the output one is an Ecore metamodel (TGTMM)
At the time being, in this transformation I just have this simple rule:
module MyModule;
create OUT: TGTMM from IN: UML;
rule fromClass {
from src: UML!Class
to tgt: TGTMM!TClass (name <- src.name)
}
When I try to execute this transformation on a simple model I get the following error:
org.eclipse.m2m.atl.emftvm.util.VMException: java.lang.ClassCastException: The value of type 'class java.lang.String' must be of type 'org.eclipse.emf.ecore.impl.EDataTypeImpl@12b5b511 (eProxyURI: platform:/resource/org.eclipse.uml2.types/model/Types.ecore#//String)'
If, in the assignment, I replace src.name by a constant string (e.g. 'myname'), I get the same. If I remove the assignment completely. The transformation runs without error.
Note: in the TGTMM.ecore file, which is generated by Eclipse from an UML file the attribute "name of TClass has the type: java.lang.String, which it a bit surprising to me.
How can I fix that?
Yves
Yves
|
|
|
|
|
Re: Issue with assignment of a String [message #1844118 is a reply to message #1844077] |
Wed, 01 September 2021 21:06 |
|
The problem lies in the reference to Types.ecore in TGTMM.ecore: this refers to another Eclipse project "org.eclipse.uml2.types":
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false"
eType="ecore:EDataType ../org.eclipse.uml2.types/model/Types.ecore#//String"/>
The exception is thrown if EMF cannot resolve the reference to the EDataType, so it doesn't known that its instanceClass is java.lang.String. You've included "types.ecore", and if I reference that file directly, the transformation works:
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false"
eType="ecore:EDataType types.ecore#//String"/>
However, you say that TGTMM.ecore was generated from UML. I'm surprised that a "platform:/resource/..." type of reference is generated, which is a workspace resource (e.g. Eclipse project), instead of "http://www.eclipse.org/uml2/5.0.0/Types", which is a globally registered EMF resource.
I tried out generating my own Ecore model from M000.uml, and found that it also generates the "types.ecore" model, and includes a direct reference to it:
<eStructuralFeatures xsi:type="ecore:EAttribute" name="p2" ordered="false" eType="ecore:EDataType types.ecore#//Integer"/>
so it's not trying to navigate to another Eclipse project first. Somehow, you must have changed TGTMM.ecore after it was generated...?
Cheers,
Dennis
|
|
|
Re: Issue with assignment of a String [message #1844152 is a reply to message #1844118] |
Fri, 03 September 2021 09:30 |
Yves BERNARD Messages: 146 Registered: July 2014 |
Senior Member |
|
|
Hi Denis,
Thanks for your time in investigating this.
The TGTMM model is just a small extract of the (bigger) model on which I'm actually working. I created it for the sake of this exchange. But actually, I did edit the generated file but the purpose was to change the package name only. However I should have done something else by inadvertence because the problem has disappear with the new version of the generated file, despite the name change that I did as well.
Checking the generated ecore file, I confirm that the reference to the type is actually made as you describe.
So, I cannot explain what happened with my previous generated model but in any case it looks fine now.
Thank you again.
Yves
Yves
|
|
|
Powered by
FUDForum. Page generated in 0.02077 seconds