In the process of developing android using eclipse, the usage details of the annotation are as follows: eclipseandroid

Source: Internet
Author: User

In the process of developing android using eclipse, the usage details of the annotation are as follows: eclipseandroid
Citation

Most of the implementation processes of commercial projects are collaborative development, svn, git, and other version control software, which provides a lot of convenience in code management. However, due to collaborative development, there will be a lot of intersection in terms of business and mutual support is required. Therefore, you need to make a series of comments on your own code. In the later stage, the logic tends to be more complex due to the expansion. To facilitate tracing, a complete annotation is required. Therefore, the code and comments produced by a professional programmer account for a large proportion. Next, let's take a look at how to add annotations when using eclipse IDE to develop android-based applications.
Generation Method
! [My] (http://img.blog.csdn.net/20150511174051373) when the red area is selected, the method and file are generated, the comment is automatically added, you only need to change individual property descriptions, if not checked, enter/** after you generate the method or file, and then click enter. The comment method is automatically added. (If you cannot see it, go to the Window-> Preference-> Java-> Code Style-> Code Template directory, and there is a ticket above apply, it sets whether to automatically add comments)
Processing Method
No matter how the annotation information is configured, the operation location in eclipse is the same. Located in the eclipse Window-> Preference-> Java-> Code Style-> Code Template directory.
1. Configuration Template
Generate an xml format template and import it directly to eclipse.
2. Configure attributes
On the eclipse settings page, set annotation information for properties.
Attribute description annotation field description @ Title

This comment is generally used to fill in the description of the current java file near the package location when creating a file. The value is usually set to $ {file_name}

@ Package

Indicates the package name of the current file. Generally, the value is $ {package_name}

@ Description

Enter the description of the current file, method, and field. Generally, the $ {todo} field is added to the header. The actual generated TODO field is displayed in uppercase.

@ Author

The author, who made this file or method, usually does not change during configuration, because it is the unique identifier of your output code.

@ Date

This label indicates the time, which can be automatically generated and filled in with comments. Note that Date {Time} indicates the year, month, day, hour, minute, and second. You can remove $ {time}, so that the time will be output according to the format of year, month, and day.

@ Version

It is used to indicate version information, which is generally fixed. It is mainly used to know that the initial information of iterative version information of this resource is version 1.0.

@ ClassName

As the name suggests, the current method name setting value is $ {type_name}

@ Param

This is a description of the method parameters. After $ {tags} is set, the parameters of the generated method are automatically filled here.

@ Return

Annotation information of the returned value. The value is usually set to $ {bare_field_name}

Configure attributes
The setting directory is as follows:

(Window-> Preference-> Java-> Code Style-> Code Template)

In the current directory, you will see two directories: Comments and Code.
Next, open the Comments directory and you will see the attribute Declaration (Files, Types, Fields .....). These attribute declarations are fixed configuration directories for the files and methods we have created, and are bound to each other.

File (Files) annotation label:
/*** @ Title: $ {file_name} * @ Package $ {package_name} * @ Description: $ {todo} (the role of this class is described in one sentence here) * @ author: (add your personal information here, fixed) * @ date $ {date }$ {time} * @ version V1.0 */
Type (Types) annotation label (class annotation ):
/*** @ ClassName: $ {type_name} * @ Description: $ {todo} (Here we use a sentence to describe the role of this class) * @ author: (add your personal information here, fixed) * @ date $ {date }$ {time }*/
Field (Fields) annotation label:
/*** @ Fields $ {field }:$ {todo} (describe what this variable represents in one sentence )*/
Constructor Tag:
/*** @ Title :$ {enclosing_method} * @ Description: $ {todo} (Here we use a sentence to describe the role of this method) * @ param: $ {tags} * @ return: $ {return_type} * @ throws :**/
Method (Constructor & Methods) label:
/*** @ Title :$ {enclosing_method} * @ Description: $ {todo} (Here we use a sentence to describe the role of this method) * @ param: $ {tags} setting file * @ return: $ {return_type} return type * @ throws :*/
Overriding Methods labels:
/*** @ Title :$ {enclosing_method} * @ Description: $ {todo} (Here we use a sentence to describe the role of this method) * @ param: $ {tags} setting file * @ return: $ {return_type} return type * @ throws :*/
Method label:
/** * ${tags} * ${see_to_target} */ 
GET method label:
/** * @return ${bare_field_name} */ 
SET Method label:
/*** @ Param $ {param} $ {bare_field_name }*/
Configuration Template
<? 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 ">/*** getter method * @ return the $ {bare_field_name} */</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 ">/*** setter method * @ param $ {param} the $ {bare_field_name} to set */</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 ">/*** @ Title $ {enclosing_type }. * & lt; p & gt; Title: & lt;/p & gt; * & lt; p & gt; Description: & lt;/p & gt; * $ {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 ">/*** @ Title :$ {file_name} * @ Package $ {package_name} * @ Description: $ {todo} * @ author username * @ date $ {date} * @ version V1.0 */</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} * @ Description: $ {todo} * @ author username * @ date $ {date }$ {time} * $ {tags} */</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 ">/*** @ Fields $ {field }:$ {todo} (describe what this variable represents in one sentence) */</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 ">/*** @ Title :$ {enclosing_method} * @ Description: $ {todo} * @ param $ {tags} setting file * @ author username * @ return $ {return_type} return type * @ throws */</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 ">/*** & lt; p & gt; Description: & lt;/p & gt; * $ {tags} * $ {see_to_overridden} */</template> <template autoinsert = "false" 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 =" newtype_context "deleted = "false" description = "Newly created files" enabled = "true" id = "org. eclipse. jdt. ui. text. codetemplates. newtype "name =" newtype ">$ {filecomment }$ {package_declaration }$ {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 = "true" 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>
Instructions for use:

Copy the above data, create an xml file locally, and paste it in. Then, on the eclipse template setting interface, click the import button. After the import is successful, you can implement the batch customization of annotations. You can adjust the template as needed. You can also add the attribute information to be displayed for each comment.

Tail

At this point, the comments probably need something that has been explained clearly. For the first time I wrote a blog, if there were any mistakes, please point them out. It is recommended that you develop software developers to develop good coding habits and add comments to the codes in a timely manner to facilitate your own maintenance, facilitate the use of colleagues, and facilitate project backtracking. I hope my blog posts will, it can help you.

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.