Steven B
Steven B

Reputation: 33

Eclipse - inline open declaration?

Eclipse has the handy option to hit f3 when the cursor is on a method to open the declaration. However, is there a way (via some plugin or otherwise) to do something similar, but inline the method body instead of taking you to the declaration? For example, let's say you have two classes:

public class Foo {
    public static void main(String[] args) {
        Bar b = new Bar();
        System.out.println("Value: " + b.value());
    }
}

public class Bar {
    public int value() {
        return 5;
    }
}

Then, if you put your cursor on "b.value()" and choose this option, it would display something like the following:

public class Foo {
    public static void main(String[] args) {
        Bar b = new Bar();
        System.out.println("Value: " + b.value() {
            return 5;
        });
    }
}

Ideally also being able to edit the method body for value(), and also allowing me to do the same to any further method bodies that may be within value().

My main motivation for this is to more quickly understand what foreign code is doing. I'm also open to any other IDE that supports this feature.

Upvotes: 3

Views: 1273

Answers (1)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

You will want to look at the declaration view (Window -> Show View -> Declaration). The contents of the declaration view defaults to the declaration of whatever your caret is currently selecting.

Alternatively, you are supposed to be able to use Shift-Hover to get a pop-up of the declaration (but I am currently having trouble getting that behavior to work).

There is no way to edit the code AFAIK.

Upvotes: 3

Related Questions