开发者

Why does /**[newline] not always insert the Javadoc template including @param and @return in Eclipse?

I'm documenting code in Eclipse and have been using the /** followed by Enter a lot to insert the Javado开发者_高级运维c template. However this does not always work for some reason, it will create the template for writing comments but it won't automatically insert the @param and @return text. If I copy the exact same method to another class it will insert the full template.

It would be a big help if anyone could tell me why it won't do this in some situations.


As far as I know this usually happens when Eclipse doesn't know for sure which method you want to document.

A more reliable way would be to select the method/class etc. you want to create the JavaDoc for and press ALT + SHIFT + J or right click on the method in the class outline and clicking Source -> Generate element comment.


It always works for me UNLESS there's a comment above the method I'm trying to add the documentation for. Here's an example of some code and an undocumented method where it wouldn't work:

public class Test {
    // Declare some fields. Bla bla bla.

    // ~ Constructors

    public Test() { // <-- If I insert /** above this line it fails to work
    }
}

My fix is usually to temporarily declare a variable that separates my method from the comments so the Eclipse recognises what I'm doing...

public class Test {
    // Declare some fields. Bla bla bla.

    // ~ Constructors
    int i;
    public Test() { // <-- If I insert /** above this line it works. Then discard the temp var.
    }
}


This started happening with me occasionally with the last build, Mars. Restarting Eclipse fixes it. It seems that I really need to restart Eclipse every day in order to avoid random problems like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜