Eclipse Annotation template function Annotation class annotation file comment Code template__eclipse

Source: Internet
Author: User
Tags reserved stub

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

Click "Import" to import the template Codetemplates.xml file.

The Codetemplates.xml content is our own predefined, not described here first, we can see the Eclipse code templates interface between the Configure generated code and The Comments area contains two menu trees: Comment, Code, as shown in the following illustration:

The comments represents the annotation template, and code represents the template for it, where each submenu represents the template for the subkey.

As soon as we click on a subkey, we see the template content and format that we defined in the pattern area below the interface, as shown in the following illustration:

As shown in the figure above, when we click the Files submenu under comments, the following pattern shows the header annotation for the Java file.

The template format for each subkey is listed below in detail:

Comments-->files (Java file annotation) Java code/** * Project name:${project_name} * File name:${file_name} * Package name:${   Package_name} * Date:${date}${time} * Copyright (c) ${year}, chenzhou1025@126.com all Rights Reserved. *   */

Comments-->types (Java class note) Java code/** * ClassName: ${type_name} <br/> * function: ${todo} ADD function. <br/> * Reason: ${todo} ADD Reason (optional).  <br/> * Date: ${date} ${time} <br/> * * @author ${user} * @version ${enclosing_type}${tags} * @since JDK 1.6 */

Comments-->fields (class field comment) Java code/** * ${field}:${todo} (describe what this variable represents in one sentence). * @since JDK 1.6 * *

Comments-->constructors (constructor annotation) Java code/** * Creates a new instance of ${enclosing_type}. * * ${tags} * *

Comments-->methods (Java method Comment) Java code/** * ${enclosing_method}:(here to describe the effect of this method in one sentence). <br/> * ${todo} (here describes the criteria for this method-optional) .<br/> * ${todo} (this describes the process of execution of this method-optional) .<br/> * ${todo} (describes the use of this method   Method – optional) .<br/> * ${todo} (Note for this method is described here – optional) .<br/> * * @author ${user} * ${tags} * @since JDK 1.6 */

Comments-->overriding methods (override method Annotation) Java code/** * ${todo} simply describes the implementation of the method (optional). * ${see_to_overridden} * *

Comments-->delegate methods (proxy method comment) Java code/** * ${tags} * ${see_to_target} * *

Comments-->getters (Java Getter method Comment) Java code/** * ${bare_field_name}. * * @return The ${bare_field_name} * @since JDK 1.6 * *

Comments-->setters (Java Setters method Comment) Java code/** * ${param}. * * @param ${param} The ${bare_field_name} to set * @since JDK 1.6 * *

code-->new Java files (new Java file Code template)   Java code  /**   * project name:${project_name}& nbsp  * File Name:${file_name}   * Package Name:${package_name}   *  Date:${date}${time}   * Copyright  (c)  ${year}, chenzhou1025@126.com  all rights reserved.   *  */   ${filecomment}      ${package _declaration}  /**   * ClassName:${type_name} <br/>   *  function: ${todo} add function. <br/>   * reason:   ${ todo} add reason. <br/>   * date:     ${date}  ${time} <br/>   *  @author    ${user}   *  @version      *  @since     JDK 1.6   *  @see &NBSP;&NBSP;&Nbsp;      */   ${typecomment}   ${type_declaration}  

Code-->method body (method Template) Java code//${todo} auto-generated methods stub ${body_statement}

Code-->constructor body (constructor template) Java code ${body_statement}//${todo} auto-generated constructor stub

Code-->getter Body (field Getter method template) Java code return ${field};

Code-->setter Body (field Setter method template) Java code ${field} = ${param};

Code-->catch blocks Body (Exception Catch code block template) Java Code//${todo} auto-generated Catch block ${exception_var}.printstacktra CE ();

The codetemplates.xml contents are as follows: XML code   <?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}.    *    *  @return   the ${bare_field_name}     *  @since    JDK 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    *   @since    JDK 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}, chenzhou1025@126.com 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}    *   @since  JDK 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 one sentence) .    *  @since  jdk 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 in a word describing the effect of this method) . &lt;br/&gt;    * ${todo} ( This describes the application of this method to the condition  –  optional) .&lt;br/&gt;    * ${todo} (this describes the execution process  –  optional) of this method. &lt;br/&gt ;    * ${todo} (here describes how to use this method  –  optional) .&lt;br/&gt;    * ${ TODO} (here is a note for this method  –  optional) .&lt;br/&gt;    *    *  @author  ${user}    * ${tags}    *  @since  JDK 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}  simple description of 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}, chenzhou1025@126.com all rights  Reserved.    *   */   ${filecomment}      ${package_ declaration}  /**   &NBSP;*&NBSp 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       *  @since     JDK 1.6    *  @see           */   ${typecomment}    ${type_declaration}   </template><template autoinsert= "true"  context= " Classbody_context " deleted=" false " description=" code in new class type  Bodies " enabled=&

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.