Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 配置重写方法的生成注释_Java_Eclipse - Fatal编程技术网

Java 配置重写方法的生成注释

Java 配置重写方法的生成注释,java,eclipse,Java,Eclipse,是否有一种方法,如何更改被重写方法的生成注释 “//${todo}自动生成的方法存根”仅用于一个方法的另一个文本 我需要显示警告和提示,如果有人覆盖的方法 举个例子: public class DateHolder{ public Date date; @SomeOverridingAnnotation(generateComment= "WARNING: if override and not use super then add 1 month to result!")

是否有一种方法,如何更改被重写方法的生成注释 “//${todo}自动生成的方法存根”仅用于一个方法的另一个文本

我需要显示警告和提示,如果有人覆盖的方法

举个例子:

public class DateHolder{
    public Date date;

    @SomeOverridingAnnotation(generateComment= "WARNING: if override and not use super then add 1 month to result!")
    public int getMonth(){
        return date.getMonth() + 1;
    }
}

public class DateHolder2 extends DateHolder{
    @Override
    public int getMonth() {
        // WARNING: if override and not use super then add 1 month to result!
        return super.getMonth();
    }
}

这在很大程度上取决于您使用的编辑器,因为生成的注释是由这些编辑器生成的。您的编辑器或IDE是否支持可以访问类内容的脚本注释生成器

如果不是这样的话。我怀疑是否有这样的编辑。也许有另一种方法可以达到你想要的。您可以在自己的类中管理它,例如:

public class DateHolder {
public Date date;

private int dummyInt = -42;

/**
 * Will try to call override method getMonthPlusOne, if there is not such override, then it returns month from date + 1.
 */
public final int getMonth() {
    int res = getMonthPlusOne();
    if ( res == dummyInt )
        return date.getMonth() + 1;
    return res;
}

protected int getMonthPlusOne() {
    return dummyInt;
}
}


我觉得这是XY的问题,我知道,但我不想这样。我正在寻找一个好的Eclipse插件,它允许使用它(代码模板),但如果你找到一个插件,你必须将它和代码一起分发。而类中的解决方案适用于多个编辑器。您编写了普通java解决方案。我想要eclipse解决方案(窗口->首选项->Java->Cody样式->代码模板->代码-方法体…可能会有一些表达式写在那里,它会对一些方法样式做出反应。Maybay自定义注释。Maybay插件注释模板,Java编码模板
public class DateHolder2 extends DateHolder {
    @Override
    protected int getMonthPlusOne() {
        // it will return dummyInt from DateHolder and that will add 1 to month
        return super.getMonthPlusOne();
    }
}