Skip to content

Commit

Permalink
Only add override builder if the class does not already define one
Browse files Browse the repository at this point in the history
Closes #507
  • Loading branch information
joelittlejohn committed Feb 21, 2016
1 parent 86f3f44 commit 7305278
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ private void addOverrideBuilders(JDefinedClass jclass, JDefinedClass parentJclas
}
}

private JMethod addOverrideBuilder(JDefinedClass thisJDefinedClass, JMethod parentBuilder, JVar parentParam) {
JMethod builder = thisJDefinedClass.method(parentBuilder.mods().getValue(), thisJDefinedClass, parentBuilder.name());
builder.annotate(Override.class);

JVar param = builder.param(parentParam.type(), parentParam.name());
JBlock body = builder.body();
body.invoke(JExpr._super(), parentBuilder).arg(param);
body._return(JExpr._this());

return builder;
private void addOverrideBuilder(JDefinedClass thisJDefinedClass, JMethod parentBuilder, JVar parentParam) {

if (thisJDefinedClass.getMethod(parentBuilder.name(), new JType[] {parentParam.type()}) == null) {

JMethod builder = thisJDefinedClass.method(parentBuilder.mods().getValue(), thisJDefinedClass, parentBuilder.name());
builder.annotate(Override.class);

JVar param = builder.param(parentParam.type(), parentParam.name());
JBlock body = builder.body();
body.invoke(JExpr._super(), parentBuilder).arg(param);
body._return(JExpr._this());

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void checkWarnings() {
}

public static List<Diagnostic<? extends JavaFileObject>> warnings(List<Diagnostic<? extends JavaFileObject>> all) {
List<Diagnostic<? extends JavaFileObject>> warnings = new ArrayList<>();
List<Diagnostic<? extends JavaFileObject>> warnings = new ArrayList<Diagnostic<? extends JavaFileObject>>();
for( Diagnostic<? extends JavaFileObject> entry : all ) {
if( entry.getKind() == Kind.WARNING ) {
warnings.add(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"$ref": "subtypeOfA.json"
},
"properties": {
"parent" : {
"type": "string"
},
"child": {
"type": "string"
}
Expand Down

0 comments on commit 7305278

Please sign in to comment.