diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5fd3f367..dc785d39 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -9,6 +9,9 @@ + + Fix code generation or private immutable builders. Fixes #26. + Parse trailing comments on property definitions. Fixes #27. diff --git a/src/main/java/org/joda/beans/gen/BeanGen.java b/src/main/java/org/joda/beans/gen/BeanGen.java index b69d661f..f3e6c1cc 100644 --- a/src/main/java/org/joda/beans/gen/BeanGen.java +++ b/src/main/java/org/joda/beans/gen/BeanGen.java @@ -999,7 +999,8 @@ private void generateBuilderClass() { generateBuilderProperties(); } insertRegion.add(""); - generateBuilderConstructor(); + generateBuilderConstructorNoArgs(); + generateBuilderConstructorCopy(); generateIndentedSeparator(); generateBuilderSet(); generateBuilderBuilder(); @@ -1011,7 +1012,7 @@ private void generateBuilderClass() { insertRegion.add(""); } - private void generateBuilderConstructor() { + private void generateBuilderConstructorNoArgs() { insertRegion.add("\t\t/**"); insertRegion.add("\t\t * Restricted constructor."); insertRegion.add("\t\t */"); @@ -1019,20 +1020,24 @@ private void generateBuilderConstructor() { insertRegion.add("\t\t\tsuper(" + data.getTypeRaw() + ".Meta.INSTANCE);"); insertRegion.add("\t\t}"); insertRegion.add(""); - - List nonDerived = nonDerivedProperties(); - if (nonDerived.size() > 0) { - insertRegion.add("\t\t/**"); - insertRegion.add("\t\t * Restricted copy constructor."); - insertRegion.add("\t\t * @param beanToCopy the bean to copy from, not null"); - insertRegion.add("\t\t */"); - insertRegion.add("\t\tprivate Builder(" + data.getTypeNoExtends() + " beanToCopy) {"); - insertRegion.add("\t\t\tsuper(" + data.getTypeRaw() + ".Meta.INSTANCE);"); - for (int i = 0; i < nonDerived.size(); i++) { - insertRegion.addAll(nonDerived.get(i).generateBuilderConstructorAssign("beanToCopy")); + } + + private void generateBuilderConstructorCopy() { + if (data.isEffectiveBuilderScopePublic()) { + List nonDerived = nonDerivedProperties(); + if (nonDerived.size() > 0) { + insertRegion.add("\t\t/**"); + insertRegion.add("\t\t * Restricted copy constructor."); + insertRegion.add("\t\t * @param beanToCopy the bean to copy from, not null"); + insertRegion.add("\t\t */"); + insertRegion.add("\t\tprivate Builder(" + data.getTypeNoExtends() + " beanToCopy) {"); + insertRegion.add("\t\t\tsuper(" + data.getTypeRaw() + ".Meta.INSTANCE);"); + for (int i = 0; i < nonDerived.size(); i++) { + insertRegion.addAll(nonDerived.get(i).generateBuilderConstructorAssign("beanToCopy")); + } + insertRegion.add("\t\t}"); + insertRegion.add(""); } - insertRegion.add("\t\t}"); - insertRegion.add(""); } } diff --git a/src/test/java/org/joda/beans/gen/ImmGenericArray.java b/src/test/java/org/joda/beans/gen/ImmGenericArray.java index 8ddd5b9e..a2a1b4ed 100644 --- a/src/test/java/org/joda/beans/gen/ImmGenericArray.java +++ b/src/test/java/org/joda/beans/gen/ImmGenericArray.java @@ -234,15 +234,6 @@ private Builder() { super(ImmGenericArray.Meta.INSTANCE); } - /** - * Restricted copy constructor. - * @param beanToCopy the bean to copy from, not null - */ - private Builder(ImmGenericArray beanToCopy) { - super(ImmGenericArray.Meta.INSTANCE); - this.values = beanToCopy.getValues(); - } - //----------------------------------------------------------------------- @SuppressWarnings("unchecked") @Override