如何根据Eclipse中的字段注释自动生成getter / setter的注释? [英] How to automatically generate comments for getter/setter based on field comments in Eclipse?

查看:225
本文介绍了如何根据Eclipse中的字段注释自动生成getter / setter的注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Eclipse根据以前定义的字段注释为我的getter和setter方法自动生成Javadoc注释。如何实现这一点?

I want Eclipse to automatically generate Javadoc comments for my getter and setter methods based on the previously defined comments for the fields. How can I achieve this?

背景:我们公司的一项政策是对每个方法和领域进行评论(即使他们有自己的名字)。所以我必须通过描述这些字段并再次描述getter / setter来进行冗余工作。

Background: A policy in our company is to comment every method and field (even if they have self-explanatory names). So I have to do redundant work by describing the fields and describing the getters / setters again.

示例:

/**
 * name of the dynamic strategy
 */
private String dynName;

/**
 * get the name of the dynamic strategy
 * @return
 */
public String getDynName() {
    return dynName;
}

搜索网页显示我不是唯一有问题的人 - 但我找不到任何解决方案。我查看了 http://jautodoc.sourceforge.net/ ,但似乎无法做到这一点。

Searching the web showed that I'm not the only one with the problem - but I couldn't find any solutions. I checked out http://jautodoc.sourceforge.net/ but seems like it is not capable of doing this.

推荐答案

我终于找到了一个解决方案(或至少是一个解决方法)。我在SO上阅读了关于 Spoon 的信息。它是一个Java程序处理器,允许读取和修改java源文件。它甚至可以用作Eclipse插件或Ant / Maven脚本。

I finally found a solution (or at least a workaround) myself. I read about Spoon on SO. It's an Java program processor which allows to read and modify java source files. It can even be used as Eclipse Plugin or Ant/Maven script.

您要做的一切都是扩展AbstractProcessor,它将处理一个方法。如果
,方法名称以get / set开头,则会查找相应的字段,提取其注释并替换或扩展其访问者注释。

Everything you have to do, is to extend the AbstractProcessor, which will process a method. If the method name starts with get/set it looks for the corresponding field, extracts its comment and replaces or extends the accessors comment with it.

我有一个蚂蚁脚本,它占据了我的所有来源并处理它们。

I have a little ant script, which takes all my sources and processes them.

集成在日食中的东西代码模板当然会更方便,但现在这样就可以了!

Something integrated in eclipses code templates would be of course more convenient, but for now this way is ok!

这篇关于如何根据Eclipse中的字段注释自动生成getter / setter的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆