Eclipse Encoding specification--code templates settings

Source: Internet
Author: User

Eclipse Encoding specification--code templates settings

The eclipse coding specification consists of three main areas: setting up code Templates, Eclipse formatter, Checkstyle,

This article mainly describes how to set up code Templates, the following steps:

Open Window->preferences->java->code Style->code Templates:

We can see the Eclipse Code templates interface middle Configure generated code and comments area contains two menu trees: Comment, Code,

Comments represents a comment template, and code represents a template for a tag, where each submenu represents a child item.

When we click on the Files submenu under comments, the following pattern shows the header comment for the Java file.

The following is a detailed list of the template formats for each subkey:

Comments-->files (Java file comment)

/**   * Project name:${project_name}  * File name:${file_name}  * Package Name:${package_name}  * date:${ Date}${time}  * Copyright (c) ${year} All rights Reserved.  *  */  

Comments-->types (Java class comment)

/**   * ClassName: ${type_name} <br/>  * function: ${todo} ADD Function. <br/>  * Reason: ${ TODO} ADD REASON <br/>  * Date: ${date} ${time} <br/>  *  @author  @version ${enclosing_type}${tags}   @since JDK 1.6   */  

Comments-->fields (class field comment)

/**   @since JDK 1.6* /    

Comments-->constructors (constructor comment)

/**   * Creates a new instance of ${enclosing_type}.  *  * ${tags}  */  

Comments-->methods (Java method Comment)

/**   * ${enclosing_method}:(here in a word describing the function of this method) * ${todo} (This method is described here to apply conditions – optional) * ${todo} (This method is described in the execution process – optional) * ${todo} (this Describe how this method is used – optional) * ${todo} (This method is described here for considerations – optional)  *  @author  ${user}  * ${tags}    @since  JDK 1.6  * /

Comments-->overriding methods (override method Comment)

/**   * ${todo} simply describes the implementation of the method (optional).  * ${see_to_overridden}  */  

Comments-->delegate methods (Proxy method Comment)

/**   * ${tags}  * ${see_to_target}  */  

Comments-->getters (Java getter method Comment)

/**   * ${bare_field_name}.  *  @returnthe  ${bare_field_name}  @since   JDK 1.6  */  

Comments-->setters (Java Setters method Comment)

/**   * ${param}.  *  @param   ${param} The    ${bare_field_name} to set  @since    JDK 1.6  * /  

code-->new Java files (new Java file Code template /**

* Project Name:${project_name}  * File name:${file_name}  * Package Name:${package_name}  * Date:${date} ${time}  * Copyright (c) ${year}, [email protected] All rights Reserved.   */   ${filecomment}    ${package_declaration}  /**  * Classname:${type_name} * Function: ${todo}  * Reason:   ${todo}   * Date:     ${date} ${time}  @author    ${user}      @since JDK 1.6  */             ${typecomment}  

Code-->method body (method body template)

// ${todo} auto-generated method Stub   ${body_statement}  

Code-->constructor body (constructor template)

${body_statement}   // ${todo} auto-generated constructor stub  

Code-->getter Body (field Getter method template)

return ${field};  

Code-->setter Body (field Setter method template)

Code-->catch Block Body (Exception Catch code block template)

// ${todo} auto-generated catch block   ${exception_var}.printstacktrace ();  

Another way is to directly import the set of template file Codetemplates.xml,

The contents of Codetemplates.xml are as follows:

<?xml version= "1.0" encoding= "UTF-8" standalone= "no"? ><templates><template autoinsert= "false" context= "Gettercomment_context" deleted= "false" description= "Comment for getter Method" enabled= "true" id= " Org.eclipse.jdt.ui.text.codetemplates.gettercomment "name=" Gettercomment ">/*** ${bare_field_name}. *   * @returnThe ${bare_field_name} *@sinceJDK 1.6*/</template><template autoinsert= "false" context= "Settercomment_context" deleted= "false" description= " Comment for Setter method "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.settercomment "Name=" Settercomment ">/*** ${param}. *   * @param${param} The ${bare_field_name} to set *@sinceJDK 1.6*/</template><template autoinsert= "false" context= "Constructorcomment_context" deleted= "false" description= "Comment for created constructors" enabled= "true" id= "org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name = "Constructorcomment" >/*** Creates a new instance of ${enclosing_type}. * * ${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 ">/*** Project name:${project_name} * File name:${file_name} * Package Name:${package_name} * Date:${date}${time}   * Copyright (c) ${year}, [email protected] All rights Reserved. *   */</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 " >/*** ClassName: ${type_name} &lt;br/&gt; * Function: ${todo} ADD Function.   &lt;br/&gt; * Reason: ${todo} ADD Reason (optional).   &lt;br/&gt;   * Date: ${date} ${time} &lt;br/&gt; *   * @author${user} *@version${enclosing_type}${tags} *@sinceJDK 1.6*/</template><template autoinsert= "false" context= "Fieldcomment_context" deleted= "false" description= " Comment for Fields "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.fieldcomment "name=" Fieldcomment ">/*** ${field}:${todo} (describe what this variable represents in a sentence). * @sinceJDK 1.6*/</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 ">/*** ${enclosing_method}:(here to describe the effect of this method). &lt;br/&gt;   * ${todo} (This method is described here to apply the condition – optional) .&lt;br/&gt;   * ${todo} (This method is described here for the execution process – optional) .&lt;br/&gt;   * ${todo} (here is a description of how this method is used – optional) .&lt;br/&gt;   * ${todo} (This method is described here for considerations – optional) .&lt;br/&gt; *   * @author${user} * ${tags} *@sinceJDK 1.6*/</template><template autoinsert= "false" context= "Overridecomment_context" deleted= "false" description= " Comment for overriding methods "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.overridecomment "Name=" Overridecomment ">/*** ${todo} simply describes the implementation of the method (optional). * ${see_to_overridden}*/</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= "Newtype_context" deleted= "false" description= "Newly Created files "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.newtype "name=" Newtype ">/*** Project name:${project_name} * File name:${file_name} * Package Name:${package_name} * Date:${date}${time}   * Copyright (c) ${year}, [email protected] All rights Reserved. *  */${filecomment} ${package_declaration}/*** Classname:${type_name} &lt;br/&gt; * Function: ${todo} ADD Function.   &lt;br/&gt; * Reason: ${todo} ADD Reason.   &lt;br/&gt;   * Date: ${date} ${time} &lt;br/&gt; * @author${user} *@version     * @sinceJDK 1.6 *@see         */${typecomment} ${type_declaration}</template><template autoinsert= "true" context= "Classbody_context" deleted= "false" description= "Code in New Class type Bodies "Enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.classbody "name=" Classbody "> </ Template><template autoinsert= "true" context= "Interfacebody_context" deleted= "false" description= "Code in New Interface type Bodies "Enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.interfacebody "name=" Interfacebody " > </template><template autoinsert= "true" context= "Enumbody_context" deleted= "false" description= "Code in New enum type Bodies "Enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.enumbody "name=" Enumbody "> </ Template><template autoinsert= "true" context= "Annotationbody_context" deleted= "false" description= "Code in New Annotation type bodies "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.annotationbody "Name=" Annotationbody "> </template><template autoinsert=" true "context=" CATCHBLOck_context "deleted=" false "description=" Code in new catch blocks "enabled=" true "id="   Org.eclipse.jdt.ui.text.codetemplates.catchblock "name=" Catchblock ">//${todo} auto-generated catch block${exception_var}.printstacktrace (); </template><template autoinsert= "false" context= "Methodbody_context" deleted= "false" description= "Code in Created method stubs "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.methodbody "name=" MethodBody ">//${todo} auto-generated method Stub${body_statement}</template><template autoinsert= "true" context= "Constructorbody_context" deleted= "false "Description=" Code in created constructor stubs "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.constructorbody "name=" Constructorbody ">${body_statement}//${todo} auto-generated constructor stub</template><template autoinsert= "true" context= "Getterbody_context" deleted= "false" description= "Code in Created getters "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.getterbody "name=" Getterbody ">return${field};</template><template autoinsert= "true" context= "Setterbody_context" deleted= "false" description= "Code in created Setters" enabled= "true" id= "Org.eclipse.jdt.ui.text.codetemplates.setterbody" name= "Setterbody" > ${field} = ${param};</template></templates>

The purpose of setting code templates is to unify the format of various annotations and the template of code;

Eclipse Encoding specification--code templates settings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.