Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does IntelliJ IDEA have a Create Wrapper code generator

If I have an interface with a few methods. Sometimes I need to create a new implementation of the interface which wraps another instance of the interface and delegates most of the methods to the wrapped instance. Then I would change a couple of the implementations, maybe not delegating them.

A classic example would be the Collections.unmodifiableXXX() methods in the JDK which block access to the modification methods.

Does IntelliJ have any code assistance that will generate a delegate implementation of the interface and then I can just tweak a couple of methods?

like image 629
Mike Q Avatar asked Sep 20 '10 16:09

Mike Q


People also ask

How do I create a custom completion code in IntelliJ?

By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.

What is the IntelliJ shortcut to generate code?

From the main menu, select Code | Generate Alt+Insert to open the popup menu with available constructs that you can generate.

How do I automatically set getters and setters in IntelliJ?

You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor , Getter , Setter or Getter and Setter .


2 Answers

You can do it in two stages. First implement the interface and then introduce delegation

like image 156
PaulJWilliams Avatar answered Oct 08 '22 18:10

PaulJWilliams


Code|Delegate Methods

like image 32
Mot Avatar answered Oct 08 '22 16:10

Mot