Eclipse automatically adds Chinese annotations to getter and setter

Source: Internet
Author: User

When we use eclipse for development, we often use the ability to automatically generate getter and setter for Eclipse, and most of the time, the getter and setter that eclipse generates for us are not available in the project. We also need to manually modify them.

For example, the following class. I used eclipse's ability to automatically generate getters and setters and chose to add comments. The final class is as follows

public class User {//username private string name;/** * @return the name */public string GetName () {return name;} /** * @param name the name to set */public void SetName (String name) {this.name = name;}}

But what we want is not such a comment. Want to be able to generate the following code comments

public class User {//username private string name;/** * return username *  * @return user name */public string getName () {return name;} /** * Set User name *  * @param name *            username */public void SetName (String name) {this.name = name;}}

How to do it?

Now I'll explain how I'm going to change.

1. The first step is to find the class file that eclipse automatically generates getter and setter. I'm looking for everybody. In eclipse\plugins\org.eclipse.jdt.ui_xxxxxxxx.jar\org\eclipse\jdt\internal\corext\codemanipulation\ Gettersetterutil.class

2, we modify the source code of this class and then compile and replace. This class source is generally in the corresponding eclipse\plugins\org.eclipse.jdt.ui.source__xxxxxxxx.jar\org\eclipse\jdt\internal\corext\ Codemanipulation\gettersetterutil.java

My version of Eclipse is version:4.3.1

I pass on the files that have been modified and compiled well. When you use this, remember to back up the original jar first. Lest tragedy.

The replacement process for Class I'll just say it briefly. Lest some classmates not understand.

1. Open Eclipse\plugins\org.eclipse.jdt.ui_xxxxxxxx.jar directly with compressed files

2. Find Org\eclipse\jdt\internal\corext\codemanipulation\gettersetterutil.class

3, replace the Gettersetterutil.class with our own modified Gettersetterutil.class (Eclipse is not running in a state to be replaced)

How to use

1. window-in Eclipse "Preferences->java->code style->code templates

2. Find comments

3. Expand Find Getters Click Edit to enter the following content

/** * Return bare_field_comment *  * @return bare_field_comment*/

4. Find Setters Click Edit to enter the following content

/** * Set Bare_field_comment *  * @param ${param} *            bare_field_comment * *

5. Save


Bare_field_comment: It is replaced with the comment above our attribute. If the attribute does not use annotations. Then it will output bare_field_comment directly.

Use

public class User {//username private String name;}


The Generate method is also selected when we automatically generate getter and setter comments If the attribute has a single line comment then this annotation will be used by us.

The final build effect is as follows

public class User {//username private string name;/** * return username *  * @return user name */public string getName () {return name;} /** * Set User name *  * @param name *            username */public void SetName (String name) {this.name = name;}}


Note that the

Multi-line annotations are not recognized. This was deliberately blocked.

http://download.csdn.net/detail/kongguoan/7693671




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.