This article describes the custom annotation template implemented by Android programming. Share it for your reference, as follows:
As a programmer, it is also important to have the ability to write code, but it is also important to develop good writing habits. Today I will introduce you in detail how to create annotation templates. It is also OK to manually comment information for each class and method, but this is more cumbersome. Why don’t we create a comment template manually?
First: First we need to write an XML file () of a template
Second, we will now write the content information of the main annotations for the xml file, and I will directly post the xml information I use.
<?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="" name="overridecomment">/**
* @describe:
* @Method name: ${enclosing_method}
* $
android
Customize
template* @Created by: ${user}
* @Creation time: ${date}${time}
* @Modified by: ${user}
* @Modification time: ${date}${time}
* @Modify Note:
* @throws
*/</template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="" name="methodcomment">/**
* @describe:
* @Method Name: ${enclosing_method}
* $
android
Customize
template* @Return type ${return_type}
* @creator ${user}
* @Creation time ${date}${time}
* @Modified ${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="" name="constructorcomment">/**
* <p>Title: </p>
* <p>Description: </p>
* $
android
Customize
template
*/</template><template autoinsert="false" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="" name="settercomment">/**
* @param ${param} ${bare_field_name}
*/</template><template autoinsert="false" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="" name="delegatecomment">/**
* $
android
Customize
template* ${see_to_target}
*/</template><template autoinsert="false" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="" name="gettercomment">/**
* @return ${bare_field_name}
*/</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="" name="typecomment">/**
* @Class Description:
* @Project name: ${project_name}
* @ package name: ${package_name}
* @Class name: ${type_name}
* @Created by: ${user}
* @Creation time: ${date}${time}
* @Modified by: ${user}
* @Modification time: ${date}${time}
* @Modify Note:
* @version v1.0
* @see [nothing]
* @bug [nothing]
* @Copyright go3c
* @mail *@
*/</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="" name="filecomment">/**
* @Title: ${file_name}
* @ package name: ${package_name}
* @Function 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="" name="fieldcomment">/**
* @field: ${field}
* @Function Description:
* @Created by: ${user}
* @Creation time: ${date}${time}
*/</template></templates>
3. How do we use this well-written XML file in eclipse? Now I will analyze it for you!
Window --> Preferences --> Java --> Code Style --> Code Templates --> Comments --> Import --> Select --> OK You can modify your email address yourself after adding. The creator name can add a line -="whateveryouwant" to the eclipse directory.
4. How do we quickly use the annotation module information we wrote in eclipse?
When adding comments, enter /** on the class name and then enter Enter to automatically generate the following format comment:
/**
*
* @Class Description:
* @Project name:
* @Bank Name:
* @Class Name: AppDao
* @Created by:
* @Creation time: 2014-4-30 10:32:30 AM
* @Modified by:
* @Modification time: 2014-4-30 10:32:30 AM
* @Modify Note:
* @version v1.0
* @see [nothing]
* @bug [nothing]
* @Copyright
* @mail */
Enter /** on the method name and then enter the carriage to automatically generate the following format comment:
/**
*
* @describe:
* @Method Name: UpdatePlayerHistory
* @param db
* @param item
* @return
* @Return type int
* @Creator
* @Creation time 2014-4-30 10:22:36 AM
* @Modify
* @Modification time 2014-4-30 10:22:36 AM
* @Modify Notes
* @since
* @throws
*/
The description needs to be filled in manually.
I hope this article will be helpful to everyone's Android programming design.