Writing a comment in Eclipse linking a specific line

百般思念 提交于 2019-12-22 03:52:11

问题


i'm working with Eclipse in Java and with long long classes i need a feature like this: in the top comment of a method (for example) there is a list of operations executed by the method. For each operation listed, i'd like to "hyperlink" a portion of the comment to a specific line of the related code.

Then using Ctrl+Click to that line i can jump directly to the specified line code.

Is it possible an operation like this?

Thanks


回答1:


In the comment below your question you say:

how can i link methods?

Take a look at the following example: you can press ctrl + click on bar() within the JavaDoc of foo() and eclipse jumps to the method bar().

public class Example {

    /**
     * JavaDoc of foo(). This method executes {@link Example#bar()}
     */
    public void foo() {
        bar();
    }

    /**
     * Javadoc of bar().
     */
    public void bar() { }
}

Eclipse even offers autocomplete for @link, the classname and the method (after you manually entered the #).

Is that what you are looking for?




回答2:


You can use the JavaDoc @see tag:

/**
* @see MyClass#myMethod()
*/

This generates a hyperlink in your JavaDoc.

SRC: method-linking-anchoring-in-java




回答3:


The Eclipse IDE allows you to go from a method call to the method's definition ('F3' I think).

Apart from that, I don't think there's a way to set up "special" navigation. Mind you, if you need something like that, it is a strong indication that your methods are WAY too large. Refactor them.


Thinking outside of the box, if you were to feed your code through a code-to-html pretty printer, you could embed HTML hyperlinks and anchors in comments (javadoc or normal). With a bit of luck, they would be clickable when you viewed the HTML-ized source code in a web browser.


Of course, Eclipse can follow javadoc "links". Obviously the standard tags can't link to deep inside a method, but I guess you could write an Eclipse plugin that supported non-standard javadoc tags for linking to embedded anchors, and the navigation thereof.



来源:https://stackoverflow.com/questions/15001432/writing-a-comment-in-eclipse-linking-a-specific-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!