Rational Software Architect:UML 到 Java 转换:Java 源代码布局

发布于 2024-09-08 18:08:23 字数 1973 浏览 5 评论 0原文

我正在使用 IBM Rational Software Architect 创建 UML 模型,然后将其转换为 Java 代码。 不幸的是,生成的 Java 源代码格式不是最好的,至少不是我想要使用的格式。举个例子:

/**
 * 
 */
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
    }
}

一点是,我希望首先声明所有私有成员变量,然后是 getter/setter 方法。

RSA 和 Eclipse 都是非常强大的工具,因此我希望你们中的某个人知道更改或指定源代码布局/格式的方法。

此致, 埃里克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窗影残 2024-09-15 18:08:23

首选项>爪哇>编辑>保存操作。 “附加操作”之一是“对成员进行排序”。每次保存后,它都会重新组织类成员(如分组的私有字段)。可能还想看看 Java >代码风格>格式化程序看看是否有帮助。

编辑:如果您不打算编辑文件但仍想对成员进行排序,则可以通过 Source > 下的 Project Explorer 上下文菜单来完成此操作。对成员进行排序...

每次我使用生成的代码时,我都必须对它进行一些修改,并假设您也会这样做。我的不好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文