Let MyEclipse automatically generate a Get set method that automatically adds text annotations, and the annotation content contains the document comments we add in the field _eclipse

Source: Internet
Author: User

When coding a realistic class, it is found that an entity class has a lot of fields to annotate, they're all private, they can't be accessed directly, and the documentation comments we added when we wrote it didn't work, but the documentation comments for the auto-generated Get,set method did not meet our requirements (no documentation comments in the containing fields) So it's very tangled. On the Internet to see some of the great God has a solution to try the next can, take out and share with you.


Modified Effect Chart:


Steps:

1: Search in Myeclipse/eclisp to find Org.eclipse.jdt.ui_*.jar (* is version number)

2: Change the jar file to a. rar format and open (it is best to back up this jar file before modifying it)

3: Find \org\eclipse\jdt\internal\corext\ Codemanipulation This directory under the Gettersetterutil.class this file, and download me to provide compressed files under the file replace this one file on it

4: Open the development tool to find Window->preferences->java->codestyle->code templates->comments->getters/setters

Specific code Modifications:

By recompiling the technology, you modify the Org.eclipse.jdt.ui_3.3.1.r331_v20070906.jar package in the eclipse

Org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil class
The getsetterstub and GETGETTERSTUB functions below to implement the build Getter/setter, the annotation uses the annotation of the member (if the member's comment is there, if not, use the annotation template to generate, if the build getter/is selected Setter needs to generate code comment.)

The Getsetterstub function is modified in the following places:
The original:
if (addcomments)
{
String comment = codegeneration.getsettercomment (Field.getcompilationunit (), Parenttype.gettypequalifiedname ('. '), Settername, Field.getelementname (), TypeName, Argname, Accessorname, Linedelim);


Modified to:
if (addcomments)
{
String comment = codegeneration.getsettercomment (Field.getcompilationunit (), Parenttype.gettypequalifiedname ('. '), Settername, Field.getelementname (), TypeName, Argname, Accessorname, Linedelim);
Isourcerange sr = Field.getjavadocrange ();
if (null!= SR)
Comment = Field.getsource (). substring (0, sr.getlength ());




The Getgetterstub function is modified in the following places:
The original:
if (addcomments)
{
String comment = codegeneration.getgettercomment (Field.getcompilationunit (), Parenttype.gettypequalifiedname ('. '), Gettername, Field.getelementname (), TypeName, Accessorname, Linedelim);


Modified to:
if (addcomments)
{
String comment = codegeneration.getgettercomment (Field.getcompilationunit (), Parenttype.gettypequalifiedname ('. '), Gettername, Field.getelementname (), TypeName, Accessorname, Linedelim);
Isourcerange sr = Field.getjavadocrange ();
if (null!= SR)
Comment = Field.getsource (). substring (0, sr.getlength ());



Getters:/** * Get ${bare_field_name} * @return ${bare_field_name} ${bare_field_name}/setters:/** * Set ${bare_field_name} * @param ${bare_field_name} ${bare_field_name} * *

Note: Generate method is selected when generating Get/set methods comments


I tested successfully in the myeclips8.6. We can try.

MyEclipse10 available

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.