Writing a comment in Eclipse linking a specific line
Asked Answered
U

3

10

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

Urdar answered 21/2, 2013 at 11:45 Comment(4)
I am pretty sure you can only link to methods (e.g. the ones you call) not to code inside of methods.Porphyria
'a list of operations' sounds a little if each 'operation' is a candidate for extract to method refactoring. Why would you want to make comments in the method-comment related to implementation specific decisions within the method (They might change without changing the functionality of the method)?Sphygmomanometer
@Sphygmomanometer you are right, i can use different methods but, as kw4nta is saying, how can i link methods?Urdar
Why don't you bookmark these lines?Topazolite
Y
7

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?

Yellowbird answered 21/2, 2013 at 11:58 Comment(0)
M
2

You can use the JavaDoc @see tag:

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

This generates a hyperlink in your JavaDoc.

SRC: method-linking-anchoring-in-java

Meliamelic answered 21/2, 2013 at 11:53 Comment(3)
Works only on method-level. You cannot link to parts within the method. That was the question.Sphygmomanometer
With this notation the links are shown only in JavaDoc. I need to use that links direcly on the code sources, like Ctrl+ClickUrdar
In that case you can use some hyper link manager with eclipse see help.eclipse.org/helios/…Meliamelic
F
0

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.

Farlee answered 21/2, 2013 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.