@Override public JavaClazz apply(JavaClazz item) { JavaType type = item.getType(); JavaType editableType = TypeAs.EDITABLE.apply(type); JavaType builderType = TypeAs.BUILDER.apply(type); Set<JavaMethod> constructors = new LinkedHashSet<JavaMethod>(); Set<JavaMethod> methods = new LinkedHashSet<JavaMethod>(); for (JavaMethod constructor : item.getConstructors()) { constructors.add(superConstructorOf(constructor, editableType)); } JavaMethod edit = new JavaMethodBuilder() .withReturnType(builderType) .withName("edit") .addToAttributes(BODY, "return new " + builderType.getSimpleName() + "(this);") .build(); methods.add(edit); return new JavaClazzBuilder() .withType(editableType) .withConstructors(constructors) .withMethods(methods) .build(); } }, INLINEABLE {
.withFields(properties) .withMethods(nestedMethods) .withConstructors(constructors) .addToAttributes(MEMBER_OF, memberOf) .build();
JavaClazz inlineableOf(BuilderContext ctx, JavaClazz clazz, Inline inline) { JavaClazz base = ClazzAs.INLINEABLE.apply(clazz); JavaType baseInterface = typeGenericOf(BuilderUtils.getInlineType(ctx, inline), clazz.getType()); JavaMethod method = new JavaMethodBuilder(base.getMethods().iterator().next()).withName(inline.value()).build(); JavaType fluent = TypeAs.SHALLOW_FLUENT.apply(clazz.getType()); JavaType shallowInlineType = new JavaTypeBuilder(base.getType()) .withClassName(inline.prefix() + base.getType().getClassName() + inline.suffix()) .addToInterfaces(baseInterface) .build(); JavaType inlineType = new JavaTypeBuilder(shallowInlineType) .withSuperClass(typeGenericOf(fluent, shallowInlineType)) .build(); Set<JavaMethod> constructors = new LinkedHashSet<JavaMethod>(); for (JavaMethod constructor : base.getConstructors()) { constructors.add(new JavaMethodBuilder(constructor).withReturnType(inlineType).build()); } return new JavaClazzBuilder(base) .withType(inlineType) .withConstructors(constructors) .withMethods(new HashSet<JavaMethod>(Arrays.asList(method))) .build(); } }
.withType(builderType) .withFields(fields) .withConstructors(constructors) .withMethods(methods) .build();