Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Uml to Java issue
Uml to Java issue [message #1713795] Fri, 06 November 2015 16:35 Go to next message
Eclipse UserFriend
Hi all,
I've been testing Acceleo UML to Java generator 3.0.0.
I'm using Mars.1 and last Papyrus.
When I generate the code for an association I'm not getting the expected
result.
In the sample model there are two classes (Class1 and Class2) and an
association from Class1 to Class2 (see the attached image). For Class1 I
get following code generated:

/*******************************************************************************
* 2015, All rights reserved.

*******************************************************************************/

// Start of user code (user defined imports)

// End of user code

/**
* Description of Class1.
*
* @author Victor
*/
public class Class1 {
/**
* Description of the property class2.
*/
public Class2 class2 = null;

// Start of user code (user defined attributes for Class1)

// End of user code

/**
* The constructor.
*/
public Class1() {
// Start of user code constructor for Class1)
super();
// End of user code
}

// Start of user code (user defined methods for Class1)

// End of user code
/**
* Returns class2.
* @return class2
*/
public Class2 getClass2() {
return this.class2;
}

/**
* Sets a value to attribute class2.
* @param newClass2
*/
public void setClass2(Class2 newClass2) {
if (this.class2 != null) {
this.class2.set(null);
}
this.class2.set(this);
}

}

The problem is with the method setClass2. It is using a "set" method
that actually doesn't exist in Class2. I was expecting the generator to
produce something like:

public void setClass2(Class2 newClass2) {
this.class2 = newClass2;
}

Am I doing something wrong?

Best,

Victor
[Acceleo, UML to Java] Re: Uml to Java issue [message #1715130 is a reply to message #1713795] Thu, 19 November 2015 13:18 Go to previous message
Akira Tanaka is currently offline Akira TanakaFriend
Messages: 98
Registered: March 2010
Member
Dear Acceleo and UML to Java experts,

Since I have experienced similar situations, I did the following Java code generation experiment, focusing on relationships between classes (how they are translated into Java code).

Input (class diagram created with UML Designer):
index.php/fa/24006/0/

Output (generated code, e.g. for class A1):
	/**
	 * Returns a2.
	 * @return a2 
	 */
	public A2 getA2() {
		return this.a2;
	}

	/**
	 * Sets a value to attribute a2. 
	 * @param newA2 
	 */
	public void setA2(A2 newA2) {
		if (this.a2 != null) {
			this.a2.set(null);
		}
		this.a2.set(this);
	}


The issue is on
this.a2.set(null);
and
this.a2.set(this);
. This was already reported by Victor:

- Uml to Java issue [message #1713795]
- Bug 481751 - Association generation incomplete

In my experiment, this pattern appears for class A1, B1, C1, D1 and D2. It seems something is wrong with this code generation for composition, reference, and association.

Best,
Akira
Previous Topic:[ACCELEO] Add model preprocessing before text generation
Next Topic:[Acceleo] How to register other metamodels?
Goto Forum:
  


Current Time: Thu Apr 18 23:41:42 GMT 2024

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

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

Back to the top