Custom annotation template instance implemented by android programming

  • 2020-10-31 21:59:30
  • OfStack

This article provides an example of a custom annotation template implemented by android programming. To share for your reference, the details are as follows:

As a programmer, it is not only necessary to have the ability to write code, it is also important to have a good writing habit. Today I'm going to show you in detail how to create annotation templates. You can manually annotate the information for each class and method, but this is a bit tedious. Why don't we manually create a comment template?

First, we need to write an xml file for the 1 template (codetemplates.xml)

2. Let's write the content information of the main comments for the xml file now, and I will post the xml information directly for my own 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="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/**
 * @ describe :
 * @ The method name : ${enclosing_method}
 * $
  • android
  • The custom
  • The template
  • * @ The founders: ${user} * @ Creation time: ${date}${time} * @ The modifier: ${user} * @ Modification time: ${date}${time} * @ Modification remarks: * @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">/** * @ describe : * @ The method name : ${enclosing_method} * $
  • android
  • The custom
  • The template
  • * @ The return type ${return_type} * @ founder ${user} * @ Creation time ${date}${time} * @ The modifier ${user} * @ Modify the time ${date}${time} * @ Modify the remark * @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">/** * &lt;p&gt;Title: &lt;/p&gt; * &lt;p&gt;Description: &lt;/p&gt; * $
  • android
  • The custom
  • The template
  • */</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">/** * @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
  • The custom
  • The 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} * @ The class name: ${type_name} * @ The founders: ${user} * @ Creation time: ${date}${time} * @ The modifier: ${user} * @ Modification time: ${date}${time} * @ Modification remarks: * @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">/** * @ The title : ${file_name} * @ Package name: ${package_name} * @ Function Description: ${todo} * @ The 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">/** * @ Fields: ${field} * @ Function Description: * @ The founders: ${user} * @ Creation time: ${date}${time} */</template></templates>

    3. How do we use the xml file in eclipse? Now I will give you the analysis of 1 next!

    Window -- > Preferences -- > Java -- > Code Style -- > Code Templates -- > Comments -- > Import -- > Choose codetemplates. xml -- -- > When OK is added, you can change the email address yourself. The creator name can be added to eclipse.ini in the eclipse directory by adding a line - Duser.name ="whateveryouwant".

    4. How do we quickly use the annotation module information we wrote in eclipse?

    When adding a comment, type /** on the class name and press enter to automatically generate the following format comment:

    
    /**
    * 
    * @ Class description: 
    * @ Project Name: 
    * @ Package name:  
    * @ The class name: AppDao  
    * @ The founders: 
    * @ Creation time: 2014-4-30 In the morning 10:32:30  
    * @ The modifier: 
    * @ Modification time: 2014-4-30 In the morning 10:32:30  
    * @ Modification remarks: 
    * @version v1.0
    * @see [nothing]
    * @bug [nothing]
    * @Copyright 
    * @mail */
    
    

    Enter /** on the method name and a return will automatically generate the following format comment:

    
    /**
    * 
    * @ describe :
    * @ The method name : UpdatePlayerHistory
    * @param db
    * @param item
    * @return
    * @ The return type  int
    * @ founder  
    * @ Creation time  2014-4-30 In the morning 10:22:36  
    * @ The modifier  
    * @ Modify the time  2014-4-30 In the morning 10:22:36  
    * @ Modify the remark  
    * @since
    * @throws
    */

    The description should be filled out manually by yourself.

    I hope this article has been helpful to you in Android programming.


    Related articles: