public Method apply(ExecutableElement executableElement) { MethodBuilder methodBuilder = new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(executableElement.getModifiers())) .withName(executableElement.getSimpleName().toString()) .withReturnType(MIRROR_TO_TYPEREF.apply(executableElement.getReturnType())); //Populate constructor parameters for (VariableElement variableElement : executableElement.getParameters()) { methodBuilder = methodBuilder.addToArguments(PROPERTY.apply(variableElement)); List<ClassRef> exceptionRefs = new ArrayList<ClassRef>(); for (TypeMirror thrownType : executableElement.getThrownTypes()) { if (thrownType instanceof ClassRef) { exceptionRefs.add((ClassRef) thrownType); } } methodBuilder = methodBuilder.withExceptions(exceptionRefs); } List<ClassRef> annotationRefs = new ArrayList<ClassRef>(); for (AnnotationMirror annotationMirror : executableElement.getAnnotationMirrors()) { methodBuilder.withAnnotations(ANNOTATION_REF.apply(annotationMirror)); } return methodBuilder.build(); } };
@Override public Method apply(Property property) { Method method = WITH_NEW_LIKE_NESTED.apply(property); if (!(property.getTypeRef() instanceof ClassRef)) { throw new IllegalStateException("Expected Nestable / Buildable type and found:" + property.getTypeRef()); } ClassRef baseType = (ClassRef) TypeAs.UNWRAP_COLLECTION_OF.apply(property.getTypeRef()); TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedTypeImpl = PropertyAs.NESTED_CLASS_TYPE.apply(property); List<TypeRef> typeArguments = new ArrayList<TypeRef>(); for (TypeRef ignore : baseType.getArguments()) { typeArguments.add(Q); } typeArguments.add(returnType); ClassRef rewrapedImpl = nestedTypeImpl.toReference(typeArguments); return new MethodBuilder(method) .addToArguments(0, INDEX) .withName(method.getName().replaceFirst("add", "set")) .editBlock() .withStatements(new StringStatement("return new " + rewrapedImpl.getName() + "(index, item);")) .endBlock() .build(); } };
.withName(addVarargMethodName) .withReturnType(returnType) .addToArguments(INDEX) .addToArguments(unwrappedProperty) .withNewBlock() .withStatements(new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), .withName(setMethodName) .withReturnType(returnType) .addToArguments(INDEX) .addToArguments(unwrappedProperty) .withNewBlock() .withStatements(new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"),
.withName("build" + Singularize.FUNCTION.apply(property.getNameCapitalized())) .withReturnType(unwrapped) .addToArguments(INDEX) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(index).build();"))
.withName("build" + Singularize.FUNCTION.apply(property.getNameCapitalized())) .withReturnType(unwrapped) .addToArguments(INDEX) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(index).build();")) .withName(prefix + Singularize.FUNCTION.apply(property.getNameCapitalized())) .withReturnType(unwrapped) .addToArguments(INDEX) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(index);"))