This example describes a custom annotation template for Android programming implementations. Share to everyone for your reference, specific as follows:
As a programmer not only has the ability to write code, it is also important to develop a good writing habit. Today to give you a detailed description of how to create a note template, to each class and method of their own manual to annotate the information can also, but this is more cumbersome. Why don't we manually create an annotation template?
First: First we need to write a template XML file (codetemplates.xml)
Second, we will now write the main annotation of the XML file content information, I directly to the XML information I used directly posted
<?xml version= "1.0" encoding= "UTF-8" standalone= "no"? ><templates><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 ">/** * @ Description: * @ Method Name: ${enclosing_ Method} * $android Custom template * @ Created by: ${user} * @ creation time: ${date}${time} * @ Modified by: ${user} * @ Modified: ${date}${time} * @ Modify NOTE: * @throws */</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 ">/** * @ Description: * @ Method Name: ${enclosing_method} *
$android Custom Template * @ return type ${return_type} * @ Creator ${user} * @ creation time ${date}${time} * @ Modified by ${user} * @ Modify time ${date}${time} * @ Modify Notes * @since * @throws */</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 ">/** * <p>title: </ p> * <p>description: </p> * $android custom template */</template><template autoinsert= "false" context= "s Ettercomment_context "deleted=" false "description=" Comment for Setter Method "enabled=" true "id=" Org.eclipse.jdt.ui.text.codetemplates.settercomment "Name=" settercomment ">/** * @param ${param} ${bare_field_ Name} */</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 ">/** * $android Custom template * ${see_to_target} */</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 ">/** * @return ${bare_field_name} */</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" >/** * @ class Description: * @ Project Name: ${ PROJECT_NAME} * @ Package name: ${package_name} * @ class name: ${type_name} * @ Creator: ${user} * @ created: ${date}${time} * @ Modified by: ${user} * @ fix Change time: ${date}${time} * @ Modify NOTE: * @version v1.0 * @see [Nothing] * @bug [Nothing] * @Copyright go3c * @mail * @qq. com/ </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 name: ${package_name} * @ Feature description: ${todo} * @ Author: ${user} * @ creation time: ${date} ${time} * @version v1.0 */</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: ${field} * @: * @ Creator: ${user} * @ creation time: ${date}${time} */</template></templates>
How do we use this well-written XML file in eclipse? Now I will explain it to you!
Window--> Preferences--> Java--> code Style--> Code Templates--> Comments--> Import--> Selection Codetemplates.xml--> OK, you can modify your email address after you add it. The creator name can add a row of-duser.name= "Whateveryouwant" to the Eclipse.ini in the Eclipse directory.
How do we quickly use the annotation module information we have written in eclipse?
When you add a comment, you enter/** on the class name and the carriage return automatically generates the following format comment:
/**
* @
class Description: * @ Project Name: * @ Package Name:
* @ class Name: Appdao * @ Created by: * @
Create time: 2014-4-30 Morning 10:32:30
* Modified by:
* @ Modified by: 2014-4-30 morning 10:32:30
* @ Modified NOTE:
* @version v1.0
* @see [Nothing]
* @bug [Nothing]
* @Copyright
* @mail * *
Entering/** on the method name and then carriage return automatically generates the following format comment:
/**
*
@ Description:
* @ Method Name: Updateplayerhistory
* @param db
* @param item
* @return
* @ return type int
* Created by @ creation time 2014-4-30 Morning 10:22:36 * @ Modified by * @ Modified
2014-4-30 Morning 10:22:36
* @ Modified NOTE
* @since
* @throws * *
Descriptive content needs to be filled out manually.
I hope this article will help you with the Android program.