简体   繁体   中英

Rational Software Architect: UML to Java transformation: Java Source Code Layout

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM