Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a java bean class from an interface in IntelliJ?

So, there already is a way to generate an implementation of a class in IntelliJ (v11), but it is rather simple.

It will create a class with all the methods necessary to satisfy the interface. These methods are empty and return null where appropriate.

What I am looking for is a plugin or something that will generate beans from a interface. If the generator sees a method getXXXX or setXXX (or isXXX) in the interface, it will create a member of that type and get or return that member, respectively in the implemented class.

like image 493
marathon Avatar asked Feb 08 '12 02:02

marathon


People also ask

How to create an interface in IntelliJ IDEA?

Create an interface based on the methods of a class. Rename the original class, and it implements the newly created interface. In such case, IntelliJ IDEA changes all usages of the original class to use the interface where possible. In addition, static final fields, declared in the initial class, can be moved to an interface.

How to implement builders as static inner classes in IntelliJ?

Some of us may prefer to implement builders as static inner classes as described by Joshua Bloch in Effective Java. If this is the case, we need to take a few extra steps to achieve this using IntelliJ's Replace Constructor with Builder feature. First of all, we need to manually create an empty inner class and make the constructor private:

What is extract interface refactoring in IntelliJ?

With the Extract Interface refactoring you have the following options: 1 Create an interface based on the methods of a class. 2 Rename the original class, and it implements the newly created interface. In such case, IntelliJ IDEA changes all usages... More ...

What is a java bean class?

JavaBeans are classes that encapsulate many objects into a single object (the bean). It is a java class that should follow following conventions: Must implement Serializable. It should have a public no-arg constructor. All properties in java bean must be private with public getters and setter methods. public class TestBean {.


1 Answers

All you can do is create a new class that implements the interface, then tell IntelliJ to implement all the methods. From that point, it's up to you to fill in the meat of the methods. There's no magic that I know of.

like image 77
duffymo Avatar answered Oct 01 '22 16:10

duffymo