Code specification: Eclipse Code templates settings

Source: Internet
Author: User

Now the project is generally a team development, and everyone has their own coding habits, in order to unify the format, the project team will develop a series of specifications before the project development. The purpose of the code templates is to unify the format of the various annotations and the template of the codes, as long as you have set up code templates and then use Eclipse to easily generate our own custom annotations . So we have to take some steps to help us unify the coding style of the project developers. Mainly includes three aspects: set up code Templates, Eclipse formatter, this article mainly describes how to set up code Templates, the following steps:

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

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

Codetemplates.xml content is our own pre-defined, here is not described in detail, we can see the Eclipse code templates interface between configure generated code and The Comments area contains two menu trees: Comment, Code, as shown in:

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

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

As shown, 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)

Java code
    1. /**
    2. * Project Name:${project_name}
    3. * File Name:${file_name}
    4. * Package Name:${package_name}
    5. * Date:${date}${time}
    6. * Copyright (c) ${year}, [email protected] All rights Reserved.
    7. *
    8. */

Comments-->types (Java class comment)

Java code
    1. /**
    2. * ClassName: ${type_name} <br/>
    3. * Function: ${todo} ADD Function. <br/>
    4. * Reason: ${todo} ADD Reason (optional). <br/>
    5. * Date: ${date} ${time} <br/>
    6. *
    7. * @author ${user}
    8. * @version ${enclosing_type}${tags}
    9. * @since JDK 1.6
    10. */

Comments-->fields (class field comment)

Java code
    1. /**
    2. * ${field}:${todo} (describe what this variable represents in a sentence).
    3. * @since JDK 1.6
    4. */

Comments-->constructors (constructor comment)

Java code
    1. /**
    2. * Creates a new instance of ${enclosing_type}.
    3. *
    4. * ${tags}
    5. */

Comments-->methods (Java method Comment)

Java code
    1. /** 
    2.  *  ${enclosing_method}:(Here is a word describing the effect of this method).  <br/> 
    3.  *  @author  ${user} 
    4. span class= "comment" > * ${tags} 
    5.  *  @since   jdk 1.6 
    6.  */  

Comments-->overriding methods (override method Comment)

Java code
    1. /**
    2. * ${todo} simply describes the implementation of the method (optional).
    3. * ${see_to_overridden}
    4. */

Comments-->delegate methods (Proxy method Comment)

Java code
    1. /**
    2. * ${tags}
    3. * ${see_to_target}
    4. */

Comments-->getters (Java getter method Comment)

Java code
    1. /**
    2. * ${bare_field_name}.
    3. *
    4. * @return The ${bare_field_name}
    5. * @since JDK 1.6
    6. */

Comments-->setters (Java Setters method Comment)

Java code
    1. /**
    2. * ${param}.
    3. *
    4. * @param ${param} The ${bare_field_name} to set
    5. * @since JDK 1.6
    6. */

code-->new Java files (new Java file Code template)

Java code
  1. /**
  2. * Project Name:${project_name}
  3. * File Name:${file_name}
  4. * Package Name:${package_name}
  5. * Date:${date}${time}
  6. * Copyright (c) ${year}, [email protected] All rights Reserved.
  7. *
  8. */
  9. ${filecomment}
  10. ${package_declaration}
  11. /**
  12. * Classname:${type_name} <br/>
  13. * Function: ${todo} ADD Function. <br/>
  14. * Reason: ${todo} ADD Reason. <br/>
  15. * Date: ${date} ${time} <br/>
  16. * @author ${user}
  17. * @version
  18. * @since JDK 1.6
  19. * @see
  20. */
  21. ${typecomment}
  22. ${type_declaration}

Code-->method body (method body template)

Java code
    1. ${todo} auto-generated Method stub
    2. ${body_statement}

Code-->constructor body (constructor template)

Java code
    1. ${body_statement}
    2. ${todo} auto-generated Constructor stub

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

Java code
    1. Return ${field};

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

Java code
    1. ${field} = ${param};

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

Java code
    1. ${todo} auto-generated Catch block
    2. ${exception_var}.printstacktrace ();

Code specification: Eclipse 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.