Skip to content

Commit

Permalink
Fix code generation or private immutable builders
Browse files Browse the repository at this point in the history
See #26
  • Loading branch information
jodastephen committed Oct 14, 2013
1 parent 9270e44 commit 133833b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

<!-- types are add, fix, remove, update -->
<release version="0.8.5" date="2013-10-xx" description="v0.8.5">
<action dev="scolebourne" type="fix">
Fix code generation or private immutable builders. Fixes #26.
</action>
<action dev="scolebourne" type="fix">
Parse trailing comments on property definitions. Fixes #27.
</action>
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/org/joda/beans/gen/BeanGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ private void generateBuilderClass() {
generateBuilderProperties();
}
insertRegion.add("");
generateBuilderConstructor();
generateBuilderConstructorNoArgs();
generateBuilderConstructorCopy();
generateIndentedSeparator();
generateBuilderSet();
generateBuilderBuilder();
Expand All @@ -1011,28 +1012,32 @@ 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 */");
insertRegion.add("\t\tprivate Builder() {");
insertRegion.add("\t\t\tsuper(" + data.getTypeRaw() + ".Meta.INSTANCE);");
insertRegion.add("\t\t}");
insertRegion.add("");

List<PropertyGen> 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<PropertyGen> 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("");
}
}

Expand Down
9 changes: 0 additions & 9 deletions src/test/java/org/joda/beans/gen/ImmGenericArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> beanToCopy) {
super(ImmGenericArray.Meta.INSTANCE);
this.values = beanToCopy.getValues();
}

//-----------------------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
Expand Down

0 comments on commit 133833b

Please sign in to comment.