private static Set<Property> getProperties(Class item) { Set<Property> properties = new HashSet<Property>(); for (Field field : item.getDeclaredFields()) { List<AnnotationRef> annotationRefs = new ArrayList<AnnotationRef>(); for (Annotation annotation : field.getDeclaredAnnotations()) { annotationRefs.add(ANNOTATIONTYPEREF.apply(annotation.annotationType())); } field.getDeclaringClass(); properties.add(new PropertyBuilder() .withName(field.getName()) .withModifiers(field.getModifiers()) .withAnnotations(annotationRefs) .withTypeRef(TYPEREF.apply(field.getDeclaringClass())) .build()); } return properties; }
@Override public void visit(PropertyBuilder builder) { builder.addToAttributes(LAZY_COLLECTIONS_INIT_ENABLED, isLazyCollectionEnabled); } }).build();
public PropertyBuilder(Property instance, Boolean validationEnabled) { this.fluent = this; this.withAnnotations(instance.getAnnotations()); this.withTypeRef(instance.getTypeRef()); this.withName(instance.getName()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
Property toAdd = new PropertyBuilder(property) .withModifiers(0) .addToAttributes(ORIGIN_TYPEDEF, item) .addToAttributes(OUTER_INTERFACE, fluentType) .addToAttributes(OUTER_CLASS, fluentImplType) .addToAttributes(GENERIC_TYPE_REF, genericType.toReference()) .build(); toAdd = new PropertyBuilder(toAdd).addToAttributes(DESCENDANTS, descendants).accept(new InitEnricher()).build(); methods.addAll(ToMethod.WITH_OPTIONAL.apply(toAdd)); } else { toAdd = new PropertyBuilder(toAdd).addToAttributes(BUILDABLE_ENABLED, isBuildable).accept(new InitEnricher()).build(); methods.addAll(ToMethod.GETTER.apply(toAdd)); methods.add(ToMethod.WITH.apply(toAdd));
result.add(new PropertyBuilder(property) .withName(propertyName) .withTypeRef(collectionType) .addToAttributes(DESCENDANT_OF, property) .addToAttributes(BUILDABLE_ENABLED, true) .accept(new InitEnricher()) .build()); result.add(new PropertyBuilder(property) .withName(propertyName) .withTypeRef(descendantRef) .addToAttributes(DESCENDANT_OF, property) .addToAttributes(BUILDABLE_ENABLED, true) .accept(new InitEnricher()) .build());
private static Property arrayAsList(Property property) { TypeRef unwrapped = TypeAs.UNWRAP_ARRAY_OF.apply(property.getTypeRef()); return new PropertyBuilder(property) .withTypeRef(TypeAs.ARRAY_AS_LIST.apply(TypeAs.BOXED_OF.apply(unwrapped))) .build(); }
return new PropertyBuilder(property).withTypeRef(Collections.LIST.toReference(builderType)) .addToAttributes(LAZY_INIT, " new " + listRef + "()") .addToAttributes(INIT , property.hasAttribute(LAZY_COLLECTIONS_INIT_ENABLED) && property.getAttribute(LAZY_COLLECTIONS_INIT_ENABLED) ? null : " new " + listRef + "()" ) .addToAttributes(ALSO_IMPORT, alsoImport(property, listRef, builderType)) .build(); return new PropertyBuilder(property).withTypeRef(Collections.SET.toReference(builderType)) .addToAttributes(LAZY_INIT, " new " + setRef+ "()") .addToAttributes(INIT , property.hasAttribute(LAZY_COLLECTIONS_INIT_ENABLED) && property.getAttribute(LAZY_COLLECTIONS_INIT_ENABLED) ? null : " new " + setRef + "()" ) .addToAttributes(ALSO_IMPORT, alsoImport(property, setRef, builderType)) .build(); return new PropertyBuilder(property).withTypeRef(optionalRef) .addToAttributes(INIT, " OptionalLong.empty()") .build(); return new PropertyBuilder(property).withTypeRef(optionalRef) .addToAttributes(INIT, " OptionalDouble.empty()") .build(); return new PropertyBuilder(property).withTypeRef(optionalRef) .addToAttributes(INIT, " OptionalInt.empty()") .build(); return new PropertyBuilder(property).withTypeRef(optionalRef) .addToAttributes(INIT, " Optional.empty()") .addToAttributes(ALSO_IMPORT, alsoImport(property, optionalRef, builderType)) .build();
public PropertyBuilder edit() { return new PropertyBuilder(this); }
@Override public void visit(PropertyBuilder builder) { TypeRef typeRef = builder.buildTypeRef(); TypeRef unwrapped = TypeAs.combine(TypeAs.UNWRAP_ARRAY_OF, TypeAs.UNWRAP_COLLECTION_OF, TypeAs.UNWRAP_OPTIONAL_OF).apply(typeRef); boolean isBuildable = isBuildable(unwrapped); Property parent = (Property) builder.getAttributes().get(DESCENDANT_OF); if (parent != null) { typeRef = parent.getTypeRef(); unwrapped = TypeAs.combine(TypeAs.UNWRAP_ARRAY_OF, TypeAs.UNWRAP_COLLECTION_OF, TypeAs.UNWRAP_OPTIONAL_OF).apply(typeRef); } else if (builder.getAttributes().containsKey(DESCENDANTS) && !((Collection)builder.getAttributes().get(DESCENDANTS)).isEmpty()) { hasDescendants = true; builder.addToAttributes(LAZY_INIT, "new " + listRef + "()") .addToAttributes(INIT , builder.getAttributes().containsKey(LAZY_COLLECTIONS_INIT_ENABLED) && (Boolean) builder.getAttributes().get(LAZY_COLLECTIONS_INIT_ENABLED) ? null : builder.getAttributes().get(LAZY_INIT)) .addToAttributes(INIT_FUNCTION, new Construct(Collections.ARRAY_LIST, targetType)) .addToAttributes(ALSO_IMPORT, Arrays.asList(targetType, listRef)); } else if (isSet) { ClassRef setRef = Collections.LINKED_HASH_SET.toReference(unwrapped); builder.addToAttributes(LAZY_INIT, "new " + setRef + "()") .addToAttributes(INIT , builder.getAttributes().containsKey(LAZY_COLLECTIONS_INIT_ENABLED) && (Boolean) builder.getAttributes().get(LAZY_COLLECTIONS_INIT_ENABLED) ? null : builder.getAttributes().get(LAZY_INIT)) .addToAttributes(INIT_FUNCTION, new Construct(Collections.LINKED_HASH_SET, unwrapped)) .addToAttributes(ALSO_IMPORT, Arrays.asList(targetType, setRef)); } else if (isMap) { ClassRef mapRef = Collections.LINKED_HASH_MAP.toReference(arguments); builder.addToAttributes(LAZY_INIT, "new " + mapRef + "()") .addToAttributes(INIT , builder.getAttributes().containsKey(LAZY_COLLECTIONS_INIT_ENABLED) && (Boolean) builder.getAttributes().get(LAZY_COLLECTIONS_INIT_ENABLED) ? null : builder.getAttributes().get(LAZY_INIT)) .addToAttributes(INIT_FUNCTION, new Construct(Collections.LINKED_HASH_MAP, arguments)) .addToAttributes(ALSO_IMPORT, Arrays.asList(targetType, mapRef)); } else if (isOptional) {
public Property buildFirstProperty(){ return this.properties.get(0).build(); }
private void visitPropertyBuilder(PropertyBuilder builder) { if (builder.getTypeRef() instanceof ClassRef) { ClassRefBuilder classRefBuilder = new ClassRefBuilder((ClassRef) builder.getTypeRef()); if (classRefBuilder.getDefinition() != null && classRefBuilder.getDefinition().getPackageName() != null && classRefBuilder.getDefinition().getPackageName().equals(target)) { classRefBuilder.editDefinition().withPackageName(replacement).endDefinition(); } builder.withTypeRef(classRefBuilder.accept(this).build()); } }
|| TypeUtils.isOptionalLong(property.getTypeRef()); Property toAdd = new PropertyBuilder(property) .withModifiers(TypeUtils.modifiersToInt(Modifier.PRIVATE)) .addToAttributes(ORIGIN_TYPEDEF, item) .addToAttributes(OUTER_INTERFACE, fluentType) .addToAttributes(OUTER_CLASS, fluentImplType) .addToAttributes(GENERIC_TYPE_REF, genericType.toReference()) .accept(new InitEnricher()).build(); toAdd = new PropertyBuilder(toAdd).addToAttributes(DESCENDANTS, descendants).build();
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; String methodName = "with" + property.getNameCapitalized(); TypeRef unwraped = combine(UNWRAP_COLLECTION_OF, UNWRAP_ARRAY_OF).apply(property.getTypeRef()); String addToMethodName = "addTo" + property.getNameCapitalized(); TypeRef arrayType = ARRAY_OF.apply(unwraped); Property arrayProperty = new PropertyBuilder(property).withTypeRef(arrayType).build(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(arrayProperty) .withVarArgPreferred(true) .withNewBlock() .addNewStringStatementStatement("if (this." + property.getName() + " != null) {this." + property.getName() + ".clear();}") .addNewStringStatementStatement("if (" + property.getName() + " != null) {for (" + unwraped.toString() + " item :" + property.getName() + "){ this." + addToMethodName + "(item);}} return (" + returnType + ") this;") .endBlock() .build(); }
public A removeAllFromArguments(Collection<Property> items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.remove(builder);this.arguments.remove(builder);} return (A)this; }
public Property buildProperty(int index){ return this.properties.get(index).build(); }
public Property apply(final VariableElement variableElement) { String name = variableElement.getSimpleName().toString(); TypeRef type = MIRROR_TO_TYPEREF.apply(variableElement.asType()); List<AnnotationRef> annotations = new ArrayList<AnnotationRef>(); for (AnnotationMirror annotationMirror : variableElement.getAnnotationMirrors()) { annotations.add(ANNOTATION_REF.apply(annotationMirror)); } return new PropertyBuilder() .withName(name) .withTypeRef(type) .withAnnotations(annotations) .withModifiers(TypeUtils.modifiersToInt(variableElement.getModifiers())) .build(); } };
); Property genericProperty = new PropertyBuilder(property).withTypeRef(unwrapped).build(); methods.add( new MethodBuilder()
public A addToArguments(Property... items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.add(builder);this.arguments.add(builder);} return (A)this; }
@Override public void visit(PropertyBuilder builder) { builder.addToAttributes(LAZY_COLLECTIONS_INIT_ENABLED, isLazyCollectionEnabled); } }).build();