• 使用MyEclipse生成Java注释时,使用的Code Template


    设置注释模板的入口: Window->Preference->Java->Code Style->Code Template,

    然后展开Comments节点就是所有需设置注释的元素。

    以下是部分示例,同时文章最后有两种Code Template可供大家参考使用。


    文件(Files)注释标签:

    /**
     * @projectName SpringMVC
     * @package com.candy.candy.test.CodeStyleTemplate.java
     * @Copyright Copyright(c) 2014 Candy工会
     * @author Candy czx
     * @date 2014-10-24 上午12:06:02
     * @version V1.0
     */
    package com.candy.candy.test;

    类型(Types)注释标签(类的注释):

    /**
     * TODO
     * @author Candy czx
     * @date 2014-10-24 上午12:06:02
     * @version V1.0
     */
    public class CodeStyleTemplate {}

    方法(Constructor & Methods)标签:

        /**
         * TODO
         * @author Candy czx
         * @date 2014-10-24 上午12:07:06
         * @version V1.0
         * @param arg1
         * @param arg2
         * @return
         */
        public String testCodeStyleTemplate(String arg1, String arg2) {
            return null;
        }

    其他方法、属性等标签的Code Style的模板按照默认值进行配置。


    附1:以上配置的codetemplates.xml,直接进行复制粘贴即可。

    <?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/* (non-Javadoc)
     * ${see_to_overridden}
     */</template><template autoinsert="true" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
     * 
     */</template><template autoinsert="true" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
     * ${tags}
     */</template><template autoinsert="true" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/**
     * @param ${param} the ${bare_field_name} to set
     */</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
     * ${tags}
     * ${see_to_target}
     */</template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
     * ${todo}
     * @author Candy czx
     * @date ${date} ${time}
     * @version V1.0
     * ${tags}
     */</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
     * ${tags}
     * ${todo}
     * @author Candy czx
     * @date ${date} ${time}
     * @version V1.0
     */</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/**
     * @projectName ${project_name}
     * @package ${package_name}.${file_name}
     * @Copyright Copyright(c) ${year} Candy工会
     * @author Candy czx
     * @date ${date} ${time}
     * @version V1.0
     */</template><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
     * @return the ${bare_field_name}
     */</template></templates>

    附2:在公司使用的codetemplates.xml,直接进行复制粘贴即可。

    <?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/* (non-Javadoc)
     * ${see_to_overridden}
     */</template><template autoinsert="true" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
     * @return the ${bare_field_name}
     */</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
     * @Package ${package_name}
     * @Description ${todo}
     * @author ${user}
     * @date ${date}
     * ${tags}
     */</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment"/><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
     * ${tags}
     * ${see_to_target}
     */</template><template autoinsert="true" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
     * 
     */</template><template autoinsert="true" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
     * ${tags}
     */</template><template autoinsert="true" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/**
     * @param ${param} the ${bare_field_name} to set
     */</template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
     * @author ${user}
     * @date ${date}
     * ${tags}
     */</template></templates>
  • 相关阅读:
    今天实现了 沿路径移动
    enum类型的本质(转)
    (转)成为优秀技术人员的两点建议
    深入理解 C# 协变和逆变
    web通信
    ajax入门(复习)
    git版本管理工具的使用
    在asp.net 中使用httpmodules对网页进行处理
    asp.net http概念原理复习
    web page复习笔记
  • 原文地址:https://www.cnblogs.com/Candies/p/4047230.html
Copyright © 2020-2023  润新知