Builgen plugin for eclipse and idea.Generate code for Java bean builder design pattern.
[TOC]
Test environment:
JDK 1.8
+Eclipse Oxygen Release (4.7.0)
- Copy
Builgen_1.0.0.201708310007.jar
to eclipseplugins
directory. - Delete
eclipse\configuration\org.eclipse.update
directory. - Rerun eclipse with
-clean
option(Windows:cmd->cd $dir_eclipse.exe->run cmd 'eclipse -clean'
). - Create a Java bean like this.
public class TestBean { private String mes; private int[] inteters; private List<String> strings; private List<Map<String, Object>> ddd; private boolean klk; private double dst; }
- Right click on file,click
Builgen
at the end.
- Content will be replaced by generated code.
public class TestBean { private String mes; private int[] inteters; private List<String> strings; private List<Map<String, Object>> ddd; private boolean klk; private double dst; public TestBean(TestBean testBean) { this.mes = testBean.getMes(); this.inteters = testBean.getInteters(); this.strings = testBean.getStrings(); this.ddd = testBean.getDdd(); this.klk = testBean.getKlk(); this.dst = testBean.getDst(); } public TestBean() { } public static class TestBeanBuilder { TestBean testBean; public TestBeanBuilder() { testBean = new TestBean(); } public TestBeanBuilder mes(String mes) { testBean.setMes(mes); return this; } public TestBeanBuilder inteters(int[] inteters) { testBean.setInteters(inteters); return this; } public TestBeanBuilder strings(List<String> strings) { testBean.setStrings(strings); return this; } public TestBeanBuilder ddd(List<Map<String, Object>> ddd) { testBean.setDdd(ddd); return this; } public TestBeanBuilder klk(boolean klk) { testBean.setKlk(klk); return this; } public TestBeanBuilder dst(double dst) { testBean.setDst(dst); return this; } public TestBean build() { return new TestBean(this.testBean); } } public void setDst(double dst) { this.dst = dst; } public double getDst() { return this.dst; } public void setKlk(boolean klk) { this.klk = klk; } public boolean getKlk() { return this.klk; } public void setDdd(List<Map<String, Object>> ddd) { this.ddd = ddd; } public List<Map<String, Object>> getDdd() { return this.ddd; } public void setStrings(List<String> strings) { this.strings = strings; } public List<String> getStrings() { return this.strings; } public void setInteters(int[] inteters) { this.inteters = inteters; } public int[] getInteters() { return this.inteters; } public void setMes(String mes) { this.mes = mes; } public String getMes() { return this.mes; } }
Test environment:
JDK 1.8
+INTELLIJ IDEA COMMUNITY 2017.2.1
-
Download Builgen.jar
-
File -> Settings -> plugins -> Install Plugins From Disk
,choose the jar downloaded,then restart idea. -
New class and right click inside editor for context menu,then
Generate -> Builgen
.