Generate Code with redirection IntelliJ Idea 15

95 Views Asked by At

I have a class like this:

public class BukkitPlayerWrapper implements Player {
    private Player p;

    public BukkitPlayerWrapper(Player p) {
        this.p = p;
    }
}

But Player interface has a lot of methods, is there a way in intelliJ to generate code like this?

@Override
public String getDisplayName() {
    return p.getDisplayName();
}

@Override
public void setDisplayName(String s) {
    p.setDisplayName(s);
}

Because writing it by hand will take hours.

1

There are 1 best solutions below

0
On BEST ANSWER

I'm not sure that's what you're looking for but if you have an interface e.g.

public interface ExampleInterface {

    void method1();

    void method2();
}

and you create a class that implements the interface and has a member variable:

public class SomeClass implements ExampleInterface {
    public ExampleInterface exampleInterface;

}

you can place the caret somewhere inside the class and hit Alt+Insert and it should give you this context menu:

context menu
then you click on Delegate Methods... and you'll get this:

context menu 2 select the the target member variable

enter image description here
and finally the methods you want to delegate and you'll end up with something similar to this:

public class SomeClass implements ExampleInterface {
    public ExampleInterface exampleInterface;

    @Override
    public void method1() {
        exampleInterface.method1();
    }

    @Override
    public void method2() {
        exampleInterface.method2();
    }
}

hope this helped a bit (: