views:

49

answers:

1

Hi,

I am using IBM Rational Software Architect for creating a UML Model and then transforming it to Java Code. Unfortunately the generated Java Souce Code format isn't the greatest, at least it is not the format I want to use. An example:

/**
 * 
 */
package net.game3.shared.entity;

/** 
 * <!-- begin-UML-doc -->
 * <!-- end-UML-doc -->
 * @author Heinrich
 * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
 */
public class Structure {
    /** 
     * <!-- begin-UML-doc -->
     * <!-- end-UML-doc -->
     * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
     */
    private String type;

    /** 
     * @return the type
     * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
     */
    public String getType() {
        // begin-user-code
        return type;
        // end-user-code
    }

    /** 
     * @param type the type to set
     * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
     */
    public void setType(String type) {
        // begin-user-code
        this.type = type;
        // end-user-code
    }

    /** 
     * <!-- begin-UML-doc -->
     * <!-- end-UML-doc -->
     * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
     */
    private Integer id;

    /** 
     * @return the id
     * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
     */
    public Integer getId() {
        // begin-user-code
        return id;
        // end-user-code
    }

    /** 
     * @param id the id to set
     * @generated "UML to Java (com.ibm.xtools.transform.uml2.java5.internal.UML2JavaTransform)"
     */
    public void setId(Integer id) {
        // begin-user-code
        this.id = id;
        // end-user-code
    }
}

One point is, I would like to see all private member variables to be declared first and then the getter/setter methods follow.

Both RSA and Eclipse are very powerful tools why I hope that someone of you knows a way to change or specify the Source Code Layout/Format.

Best Regards, Erik

+1  A: 

Preferences > Java > Editor > Save Actions. One of the "additional actions" is "Sort members". It'll reorganize the class members (like privates fields being grouped) after each save. Might also want to look into the Java > Code Style > Formatter to see if it helps.

Edit: If you're not going to edit the files and still want to Sort Members, you can do it via the Project Explorer context menu under Source > Sort Members....

Every time I've used generated code, I had to massage it a bit anyway and assumed you would too. My bad.

j flemm
Okay, that is a good option for me! Even if I think that this is still a little hack because we are not really going to change the Java File Transformation.Maybe it can be solved creating a custom transformer or something like this?
Heinrich