Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » how can we get DataType values in Acceleo
how can we get DataType values in Acceleo [message #1760382] Wed, 26 April 2017 14:23 Go to next message
sana sana is currently offline sana sanaFriend
Messages: 6
Registered: April 2017
Junior Member
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 08:52]

Report message to a moderator

Re: how can we get DataType values in Acceleo [message #1760396 is a reply to message #1760382] Wed, 26 April 2017 15:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
Hi

No. You cannot expect us to debug your 100/1000 line problem when you only give us 4 lines to look at.

Regards

Ed Willink
Re: how can we get DataType values in Acceleo [message #1760439 is a reply to message #1760396] Thu, 27 April 2017 08:54 Go to previous messageGo to next message
sana sana is currently offline sana sanaFriend
Messages: 6
Registered: April 2017
Junior Member
I have juste modified my first message. I hope it's clearer than the 1st request.
thx
Re: how can we get DataType values in Acceleo [message #1760440 is a reply to message #1760439] Thu, 27 April 2017 09:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
Hi

Please do not modify your messages other than to correct trivial typos; it potentially makes the thread unreadable by anyone else.

No clearer. What you provide is certainly not your MTL file. Why is there a [color=red]? You have not provided any of your models; just hints at how you intended them to be created. Perhaps https://wiki.eclipse.org/OCL/ForumNetiquette may help you understand how to communicate more profitably.

Regards

Ed Willink
Re: how can we get DataType values in Acceleo [message #1760443 is a reply to message #1760440] Thu, 27 April 2017 11:09 Go to previous messageGo to next message
sana sana is currently offline sana sanaFriend
Messages: 6
Registered: April 2017
Junior Member
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 #1760471 is a reply to message #1760443] Thu, 27 April 2017 14:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
Hi

Your ZIP is missing at least models and transformations.

Regards

Ed Willink
Re: how can we get DataType values in Acceleo [message #1760745 is a reply to message #1760471] Tue, 02 May 2017 14:49 Go to previous messageGo to next message
sana sana is currently offline sana sanaFriend
Messages: 6
Registered: April 2017
Junior Member
Hello,
Here is a zipped file with a complete project "genMyModel":
- "models" folder contains "expmodel" and "MYprofile" : uml profile applied to the model. + graphical diagrams
- "src" folder : generate.mtl (transformation rules)
- "destinationCode": contains the generated java classes

My questions are :
1- how to generate "private p2 : L1" (DataType) as mentioned in my first msg
2- how to generate Ports and Connectors (ClientEnd, SupplierEnd) considering their stereotype properties.
eg: "ConnectorStereotype" applied on "Connector" in the Expmodel.

best regards
Re: how can we get DataType values in Acceleo [message #1760751 is a reply to message #1760745] Tue, 02 May 2017 15:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
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 #1760910 is a reply to message #1760751] Thu, 04 May 2017 09:28 Go to previous messageGo to next message
sana sana is currently offline sana sanaFriend
Messages: 6
Registered: April 2017
Junior Member
Thank you for your answer. I'm trying to change my code using EClass.
I'll post my solution if it works, may be it can help others!

However, my 2nd question was about connector generation with mtl. I have no idea how to do it. I used a stereotype "ConnectorStereotype" applied on a connector between 2 properties (as it's described in my model). I need to generate :
- connector Ends ( ClientEnd, SupplierEnd)
- "repetitive" value : a propertie of "connector stereotype".

Any example or help for that, please ?
best regards,
sana
Re: how can we get DataType values in Acceleo [message #1760914 is a reply to message #1760910] Thu, 04 May 2017 09:47 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7681
Registered: July 2009
Senior Member
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
Previous Topic:[Acceleo] How does trace block in Acceleo work
Next Topic:equivalent this code in Acceleo
Goto Forum:
  


Current Time: Fri Dec 27 03:33:04 GMT 2024

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

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

Back to the top