how can we get DataType values in Acceleo [message #1760382] |
Wed, 26 April 2017 10:23  |
Eclipse User |
|
|
|
hello,
I'm triyng to code a M2T which has a model+profile UML as input and generate java classes as output, in Acceleo.
I have a problem to manipulate a DataType.
In my profile, i have :
*a stereotype "stereotype" with 2 attributes:
- attr1:type DataType "DT",
- attr2:type Enumeration "enum"
*DataType "DT" with 2 Properties:
-L1: Boolean
- L2 : string
*Enumeration "Enum" with 2 literals
*In my model, I have 2 classes (class1, class2)
*class2 has a Property "P1" :
- type Class1,
- Profile: "Stereotype" is applied: attr1 (L1 : True, L2:"abc"). attr2 (literal1).
here is my generate.mtl file,
[template public generateClasses(aClass : Class) ]
[comment @main/]
[file (aClass.name.concat('.java'), false, 'UTF-8')]
public class [aClass.name/] {
[for (p: Property | aClass.attribute) separator('\n')]
[for (sp : Stereotype | p.getAppliedStereotypes())]
private p1=[p.getValue(str,"enum").oclAsType((EnumerationLiteral).name/];
private p2 =[p.getValue(str,"DT").oclAsType(([color=red]DataType[/color]).name/];
[/for]
[/for]
}
[/file]
[/template]
In the generated class.java, I can extract the value of the enumeration literal of my model, but not the DataType.
I need to get the value of DT-->L1.
Can Someone help me please ?
thx
[Updated on: Thu, 27 April 2017 04:52] by Moderator
|
|
|
|
|
|
Re: how can we get DataType values in Acceleo [message #1760443 is a reply to message #1760440] |
Thu, 27 April 2017 07:09   |
Eclipse User |
|
|
|
Hi,
I apologize for my quick reply.
I'll try to make more effort to be clearer as possible. I attached to my reply my model (screenshot + zipped file) as I created it in Papyrus, showed the applied stereotype with its properties as I explained in my first request.
The code I wrote is a real MTL code file, I intentionally added color=red in the first request to highlight the problem (which is data type), before I changed the [code format.
[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/uml2/5.0.0/UML')]
[template public generate(aClass : Class)]
[comment @main/]
[file (aClass.name.concat('.java'), false, 'UTF-8')]
public class [aClass.name/] {
[for (p: Property | aClass.attribute) separator('\n')]
[for (sp : Stereotype | p.getAppliedStereotypes())]
//instance stereotype - type- name :
@[sp.name/] [p.type.name/] [p.name/];
private p1=[p.getValue(sp,'enum').oclAsType(EnumerationLiteral).name/];
private p2 =[p.getValue(sp,'DT').oclAsType(DataType).name/];
[/for]
[/for]
}
[/file]
[/template]
This is the code java generated for one class:
public class Class2{
//instance stereotype - type- name :
@stereotype Class1 Property1;
private p1 = e1;
private p2 = invalid;
//instance stereotype - type- name :
@stereotype Class1 Property2;
private p1 = e2;
private p2 = invalid;
}
I would like to generate in java something like that ( instead of "invalid") :
private p2 = {{L1 :true}, {L2: "abc"}} ;
i don't know how to get The DT attributes and their values ( L1 and L2 values in the model)
Any help for this problem please?
|
|
|
|
|
Re: how can we get DataType values in Acceleo [message #1760751 is a reply to message #1760745] |
Tue, 02 May 2017 11:41   |
Eclipse User |
|
|
|
Hi
A little bit of traditional 'printf' debugging works well for M2T.
[if (sp.name.equalsIgnoreCase('stereotype1') )]
/* [p.getValue(sp,'Attribute2')/] */
/* [p.getValue(sp,'Attribute2').eClass()/] */
/* [p.getValue(sp,'Attribute2').oclAsType(EnumerationLiteral)/] */
/* [p.getValue(sp,'Attribute2').oclAsType(EnumerationLiteral).name/] */
private p1=[p.getValue(sp,'Attribute2').oclAsType(EnumerationLiteral).name/];
/* [p.getValue(sp,'Attribute1')/] */
/* [p.getValue(sp,'Attribute1').eClass()/] */
/* [p.getValue(sp,'Attribute1').oclAsType(DataType)/] */
/* [p.getValue(sp,'Attribute1').oclAsType(EClass).name/] */
private p2 =[p.getValue(sp,'Attribute1').eClass().name/];
[/if]
reveals that
/* org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@655ef322 (name: e1, visibility: <unset>) */
/* org.eclipse.emf.ecore.impl.EClassImpl@550ee7e5 (name: EnumerationLiteral) (instanceClassName: null) (abstract: false, interface: false) */
/* org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@655ef322 (name: e1, visibility: <unset>) */
/* e1 */
private p1=e1;
/* org.eclipse.emf.ecore.impl.DynamicEObjectImpl@58fb7731 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@3a6f2de3 (name: DT) (instanceClassName: null) (abstract: false, interface: false)) */
/* org.eclipse.emf.ecore.impl.EClassImpl@3a6f2de3 (name: DT) (instanceClassName: null) (abstract: false, interface: false) */
/* invalid */
/* invalid */
private p2 =DT;
Attribute1 is a DT not a DataType. DT is a profile type that doesn't seem to be known to Acceleo; presumably needs a cleverer import. Perhaps Acceleo can only cope if the profile is statically generated.
Anyway using eClass() works fine.
Regards
Ed Willink
|
|
|
|
Re: how can we get DataType values in Acceleo [message #1760914 is a reply to message #1760910] |
Thu, 04 May 2017 05:47  |
Eclipse User |
|
|
|
Hi
I don't understand the problem. It seems that you have some information in the model that you want to render. So you do a bit of navigation, querying, formatting.
You need to at least demonstrate what you are failing to do to get any help on why you are failing. And of course learn to use a debugger. That's how I learned and continue to learn.
Regards
Ed Willink
|
|
|
Powered by
FUDForum. Page generated in 0.05042 seconds