Skip to content

Commit

Permalink
Add the constructors for SuperBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-dmytruk committed Aug 20, 2024
1 parent ae06d21 commit dc7ae86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void visitClass(ClassElement element, VisitorContext context) {
}
}

private MethodDef createAllPropertiesConstructor(ClassTypeDef builderType, List<PropertyElement> properties) {
static MethodDef createAllPropertiesConstructor(ClassTypeDef builderType, List<PropertyElement> properties) {
MethodDef.MethodDefBuilder builder = MethodDef.constructor()
.addAnnotation(Creator.class);
VariableDef.This self = new VariableDef.This(builderType);
Expand Down Expand Up @@ -188,7 +188,7 @@ private MethodDef createAllPropertiesConstructor(ClassTypeDef builderType, List<
return builder.build();
}

private StatementDef iterableToArrayListStatement(VariableDef.This self, ParameterDef parameterDef) {
private static StatementDef iterableToArrayListStatement(VariableDef.This self, ParameterDef parameterDef) {
return ClassTypeDef.of(ArrayList.class)
.instantiate()
.newLocal(parameterDef.getName() + "ArrayList", arrayListVar ->
Expand All @@ -206,7 +206,7 @@ private StatementDef iterableToArrayListStatement(VariableDef.This self, Paramet
)));
}

private StatementDef mapToArrayListStatement(VariableDef.This self, ParameterDef parameterDef) {
private static StatementDef mapToArrayListStatement(VariableDef.This self, ParameterDef parameterDef) {
return self.field(parameterDef.getName(), parameterDef.getType())
.assign(
ClassTypeDef.of(ArrayList.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ public void visitClass(ClassElement element, VisitorContext context) {
)
);
if (element.booleanValue(SuperBuilder.class, SUPER_BUILDER_INTROSPECTED_MEMBER).orElse(true)) {
builder.addAnnotation(AnnotationDef.builder(Introspected.class)
.addMember("withPrefix", "").build());
builder.addAnnotation(Introspected.class);
}

builder.addMethod(MethodDef.constructor().build());
if (!properties.isEmpty()) {
builder.addMethod(BuilderAnnotationVisitor.createAllPropertiesConstructor(builderType, properties));
}

builder.addMethod(createSelfMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void testDog() {
public void dogIntrospection() {
var introspection = BeanIntrospection.getIntrospection(DogSuperBuilder.class);
assertNotNull(introspection);
assertEquals(6, introspection.getBeanProperties().size());
assertEquals(0, introspection.getBeanProperties().size());
assertEquals(6, introspection.getConstructorArguments().length);
}

@Test
Expand Down

0 comments on commit dc7ae86

Please sign in to comment.