Eclipse Java annotation template setting explanation/copyright statement and encoding style Annotation

Source: Internet
Author: User

The entry for setting the annotation template: window-> preference-> JAVA-> code style-> code template. Then, expand the comments node to set all the elements for annotation. We will introduce each element one by one:

File (Files) annotation label:

/*** @ Title: $ {file_name} * @ package $ {package_name} * @ Description: $ {todo} (describe the file in one sentence) * @ author a18ccms a18ccms_gmail_com * @ date $ {date }$ {time} * @ version V1.0 */

Type (types) annotation label (class annotation ):

/*** @ Classname: $ {type_name} * @ Description: $ {todo} (the role of this class is described in one sentence here) * @ author a18ccms a18ccms_gmail_com * @ date $ {date }$ {time} ** $ {tags }*/

Field (fields) annotation label:

/*** @ Fields $ {field }:$ {todo} (describe what this variable represents in one sentence )*/

Constructor Tag:

/*** <p>Title: </p>* <p>Description: </p>* ${tags}*/

Method (constructor & Methods) label:

/*** @ Title: $ {enclosing_method} * @ Description: $ {todo} (here we will describe the role of this method in one sentence) * @ Param $ {tags} setting file * @ return $ {return_type} return type * @ throws */

Overriding Methods labels:

/* (Non-javadoc) * <p> title: $ {enclosing_method} </P> * <p> description: </P> * $ {tags} * $ {see_to_overridden }*/

Method label:

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

Getter method label:

/*** @return ${bare_field_name}*/

Setter method label:

/*** @ Param $ {Param} $ {bare_field_name }*/

Simple template example:

View plaincopy to clipboardprint? <? XML version = "1.0" encoding = "UTF-8"?> <Templates> <template autoinsert = "true" context = "fieldcomment_context" deleted = "false" Description = "field comment" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. fieldcomment "name =" fieldcomment ">/*** @ fields $ {field }:$ {todo} (describe what this variable represents in one sentence) */</template> <template autoinsert = "true" context = "gettercomment_context" deleted = "false" Description = "comment of the getter method" enabled = "true" id = "org. eclipse. jdt. UI. Text. codetemplates. gettercomment "name =" gettercomment ">/*** @ return $ {bare_field_name} */</template> <template autoinsert =" true "context =" constructorcomment_context "deleted =" false "Description =" comments of the created constructor "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. constructorcomment "name =" constructorcomment ">/*** <p> title: $ {file_name} </P> * <p> description: constructor </P> * $ {tags} */</template> <temp Late autoinsert = "true" context = "filecomment_context" deleted = "false" Description = "comments to created java files" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. filecomment "name =" filecomment ">/*** @ title :$ {file_name} * @ package $ {package_name} * @ description: $ {todo} (describe what the file is made in one sentence) * @ author daiguangjiu * @ date $ {date }$ {time} * @ version V1.0 */</template> <template autoinsert = "true" context = "setterc Omment_context "deleted =" false "Description =" comments of the setter method "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. settercomment "name =" settercomment ">/*** @ Param $ {Param} $ {bare_field_name} */</template> <template autoinsert =" true "context = "typecomment_context" deleted = "false" Description = "comment of the created type" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. typecomment "name =" typecomment "> /** * @ Author $ {user} ** $ {tags} */</template> <template autoinsert = "true" context = "delegatecomment_context" deleted = "false" Description = "method annotation "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. delegatecomment "name =" delegatecomment ">/*** $ {tags} * $ {see_to_target} */</template> <template autoinsert =" true "context =" overridecomment_context "Deleted = "false" Description = "override method annotation" enabled = "true "Id =" org. eclipse. jdt. UI. text. codetemplates. overridecomment "name =" overridecomment ">/** (non-javadoc) * <p> title :$ {enclosing_method} </P> * <p> description: </P> * $ {tags} * $ {see_to_overridden} */</template> <template autoinsert = "true" context = "methodcomment_context" deleted = "false" Description =" annotation of the non-override method "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. methodcomment "name =" methodcomment "> /** * $ {Tags} */</template> </templa <? XML version = "1.0" encoding = "UTF-8"?> <Templates> <template autoinsert = "true" context = "fieldcomment_context" deleted = "false" Description = "field comment" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. fieldcomment "name =" fieldcomment ">/*** @ fields $ {field }:$ {todo} (describe what this variable represents in one sentence) */</template> <template autoinsert = "true" context = "gettercomment_context" deleted = "false" Description = "comment of the getter method" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. gettercomment "name =" gettercomment ">/*** @ return $ {bare_field_name} */</template> <template autoinsert =" true "context =" constructorcomment_context "deleted =" false "Description =" comments of the created constructor "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. constructorcomment "name =" constructorcomment ">/*** <p> title: $ {file_name} </P> * <p> description: constructor </P> * $ {tags} */</template> <template autoinsert = "true" context = "filecomment_context" deleted = "false" Description = "created java file annotation "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. filecomment "name =" filecomment ">/*** @ title :$ {file_name} * @ package $ {package_name} * @ description: $ {todo} (describe what the file is made in one sentence) * @ author daiguangjiu * @ date $ {date }$ {time} * @ version V1.0 */</template> <template autoinsert = "true" context = "settercomment_context" deleted =" false "Description =" comments of the setter method "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. settercomment "name =" settercomment ">/*** @ Param $ {Param} $ {bare_field_name} */</template> <template autoinsert =" true "context = "typecomment_context" deleted = "false" Description = "comment of the created type" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. typecomment "name =" typecomment ">/*** @ author $ {user} ** $ {tags} */</template> <template autoinsert =" true "context =" delegatecomment_context "deleted =" false "Description =" indicates the comment of the method "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. delegatecomment "name =" delegatecomment ">/*** $ {tags} * $ {see_to_target} */</template> <template autoinsert =" true "context =" overridecomment_context "Deleted = "false" Description = "override method annotation" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. overridecomment "name =" overridecomment ">/** (non-javadoc) * <p> title :$ {enclosing_method} </P> * <p> description: </P> * $ {tags} * $ {see_to_overridden} */</template> <template autoinsert = "true" context = "methodcomment_context" deleted = "false" Description =" annotation of the non-override method "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. methodcomment "name =" methodcomment ">/*** $ {tags} */</template> </templa

Example 2:

View plaincopy to clipboardprint? <? XML version = "1.0" encoding = "UTF-8"?> <Templates> <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 ">/*** create a new instance $ {enclosing_type }. ** $ {tags} */</template> <template autoinsert = "true" context = "settercomment_context" deleted = "false" Description = "comme NT 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 ">/*** This method describes: * @ Author: wangxiongdx@163.com * @ version: $ {date }$ {time} */</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 =" fil Ecomment_context "deleted =" false "Description =" comment for created java files "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. filecomment "name =" filecomment ">/*** file name: $ {file_name} ** version information: * Date: $ {date} * copyright: corporation Corporation $ {year} * All Rights Reserved **/</template> <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 codingexample Ver (view the encoding example) 1.0 */</template> <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 = "false" context = "fieldcomment_context" deleted = "false" Description = "comment for fields" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. fieldcomment "name =" fieldcomment ">/*** $ {field }:$ {todo} (in one sentence, describe what this variable represents) ** @ since ver 1.1 */</template> <template autoinsert = "false" context = "typecomment_c Ontext "deleted =" false "Description =" comment for created types "enabled =" true "id =" org. eclipse. jdt. UI. text. codetemplates. typecomment "name =" typecomment ">/*** this class describes: * @ Author: wangxiongdx@163.com * @ version: $ {date }$ {time} */</template> </templates> <? XML version = "1.0" encoding = "UTF-8"?> <Templates> <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 ">/*** create a new instance $ {enclosing_type }. ** $ {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 ">/*** this method describes: * @ Author: wangxiongdx@163.com * @ version: $ {date }$ {time} */</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 =" filecomment_context "Deleted = "false" Description = "comment for created java files" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. filecomment "name =" filecomment ">/*** file name: $ {file_name} ** version information: * Date: $ {date} * copyright: corporation Corporation $ {year} * All Rights Reserved **/</template> <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 codingexample Ver (view the encoding example) 1.0 */</template> <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 = "false" context = "fieldcomment_context" deleted = "false" Description = "comment for fields" enabled = "true" id = "org. eclipse. jdt. UI. text. codetemplates. fieldcomment "name =" fieldcomment ">/*** $ {field }:$ {todo} (in one sentence, describe what this variable represents) ** @ since ver 1.1 */</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 ">/*** this class describes: * @ Author: wangxiongdx@163.com * @ version: $ {date }$ {time} */</template> </templates>

Bytes -----------------------------------------------------------------------------------

Copyright statement and coding style annotation in Java Development in eclipse

In Java project development, you often need to add some copyright statements or class comments to the encoding file. If there are many files, it will be very troublesome to manually add or modify them. Tools can be used to meet our requirements.

I. Copyright Notice

You can use jautodoc. Copy the plugin and feature directories of jautodoc to the eclipse directory, and restart eclipse with the-clean parameter (this parameter is not required later ). Go to the window-reference menu of Eclipse, Java-jautodoc and configure project specific settings, select Add file header, click Edit, enter copyright information, and save.
If you want to add copyrights later, press Alt + Shift + J.
Similar copyright information is as follows:

/*** @ Project name: $ {project_name} * @ file name: $ {file_name} * @ Date: $ {date} * @ copyright: $ {year} www.xxx.com Inc. all rights reserved. * Note: This document is only intended for internal circulation of XXX company. Leakage prohibited and used for other commercial purposes */

$ {Project_name}, $ {file_name}, $ {date}, and $ {year} are built-in variables. When editing a template, enter $, many similar variables are displayed.

Ii. Class comments and method comments

You can directly use the code style feature of Eclipse.

Class comments are displayed in window-reference-Java-code style-code templates-comments. Select types and click the edit button. Enter the class comments and save them.
To add copyrights later, press CTRL + ALT + J (shortcut can be viewed and modified in window-preference-General-keys.
Annotations for similar classes are as follows:

/***@Project: ${project_name}*@Author: Vin*@Date: ${date}*@Copyright: ${year} www.xxx.com Inc. All rights reserved.*/

Similarly, $ {date} is a predefined variable.

Window-preference-Java-code style-code templates-comments, select types and edit class comments,

Window-preference-Java-code style-code templates-comments, select files, and edit comments of class files

Window-preference-Java-code style-code templates-comments, select methods, and edit the annotation of the Method

And so on.

In window-preference-Java-code style-code templates-code, edit new class files and add

${filecomment}${package_declaration}${typecomment}${type_declaration}

You can automatically add the previously set file notes and class notes when creating a class file.

The operation of method annotation is similar to that of class annotation. You can study it on your own.

Finally, to use these annotations, select automatically add comments for new methods and types in window-preference-Java-code style to apply them to development.

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.