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; }
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(); } };
arguments.add(new PropertyBuilder() .withName(ARGUMENT_PREFIX + i) .withTypeRef(TYPEREF.apply(argumentType)) .build());
arguments.add(new PropertyBuilder() .withName(ARGUMENT_PREFIX + i) .withTypeRef(TYPEREF.apply(argumentType)) .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(); }
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()); } }
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; }
.withTypeRef(builderType).build()); statementsWithoutItem.add(new StringStatement("this.index = -1;")); arguments.add(new PropertyBuilder().withName("item").withTypeRef(unwrapped).build());
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; if (!(property.getTypeRef() instanceof ClassRef)) { throw new IllegalStateException("Expected Map type and found:" + property.getTypeRef()); } ClassRef mapType = (ClassRef) property.getTypeRef(); TypeRef keyType = mapType.getArguments().get(0); TypeRef valueType = mapType.getArguments().get(1); Property keyProperty = new PropertyBuilder().withName("key").withTypeRef(keyType).build(); Property valueProperty = new PropertyBuilder().withName("value").withTypeRef(valueType).build(); String methodName = "addTo" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(new Property[]{keyProperty, valueProperty}) .withNewBlock() .addNewStringStatementStatement("if(this."+property.getName()+" == null && key != null && value != null) { this." + property.getName() + " = " + property.getAttribute(INIT_FUNCTION).apply(Collections.emptyList()) + "; }") .addNewStringStatementStatement("if(key != null && value != null) {this." + property.getName() + ".put(key, value);} return (" + returnType + ")this;") .endBlock() .build(); } });
.withTypeRef(builderType.toReference()).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 + "()" ) 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 + "()" ) 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)) return new PropertyBuilder(property).withTypeRef(builderType) .addToAttributes(ALSO_IMPORT, alsoImport(property, builderType)) .build();
Property builderProperty = new PropertyBuilder(property).withName("builder").withTypeRef(builderType).build(); Property item = new PropertyBuilder(property) .withName("items") .withTypeRef(unwrapped.withDimensions(1)) .build(); .withName(removeAllMethdoName) .withReturnType(returnType) .withArguments(new PropertyBuilder(item).withTypeRef(COLLECTION.toReference(unwrapped)).build()) .withNewBlock() .withStatements(statements)
properties.add(new PropertyBuilder() .withName(var.getId().getName()) .withTypeRef(typeRef) .withModifiers(fieldDeclaration.getModifiers()) .addToAttributes(Attributeable.INIT, var.getInit() != null ? var.getInit().toStringWithoutComments() : null) .withTypeRef(typeRef) .withModifiers(parameter.getModifiers()) .withAnnotations(annotations) arguments.add(new PropertyBuilder() .withName(parameter.getId().getName()) .withTypeRef(typeRef) .withModifiers(parameter.getModifiers()) .withAnnotations(annotations)
result.add(new PropertyBuilder(property) .withName(propertyName) .withTypeRef(collectionType) .addToAttributes(DESCENDANT_OF, property) .addToAttributes(BUILDABLE_ENABLED, true) result.add(new PropertyBuilder(property) .withName(propertyName) .withTypeRef(descendantRef) .addToAttributes(DESCENDANT_OF, property) .addToAttributes(BUILDABLE_ENABLED, true)
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; ClassRef mapType = (ClassRef) property.getTypeRef(); TypeRef keyType = mapType.getArguments().get(0); Property keyProperty = new PropertyBuilder().withName("key").withTypeRef(keyType).build(); String methodName = "removeFrom" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(keyProperty) .withNewBlock() .addNewStringStatementStatement("if(this." + property.getName() + " == null) { return (" + returnType + ") this; }") .addNewStringStatementStatement("if(key != null && this."+property.getName()+" != null) {this." + property.getName() + ".remove(key);} return (" + returnType + ")this;") .endBlock() .build(); } });
public Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeRef mapType = property.getTypeRef(); Property mapProperty = new PropertyBuilder().withName("map").withTypeRef(mapType).build(); String methodName = "addTo" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(mapProperty) .withNewBlock() .addNewStringStatementStatement("if(this."+property.getName()+" == null && map != null) { this." + property.getName() + " = " + property.getAttribute(INIT_FUNCTION).apply(Collections.emptyList()) + "; }") .addNewStringStatementStatement("if(map != null) { this." + property.getName() + ".putAll(map);} return (" + returnType + ")this;") .endBlock() .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 Method apply(Property property) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeRef mapType = property.getTypeRef(); Property mapProperty = new PropertyBuilder().withName("map").withTypeRef(mapType).build(); String methodName = "removeFrom" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(mapProperty) .withNewBlock() .addNewStringStatementStatement("if(this." + property.getName() + " == null) { return (" + returnType + ") this; }") .addNewStringStatementStatement("if(map != null) { for(Object key : map.keySet()) {if (this."+property.getName()+" != null){this." + property.getName() + ".remove(key);}}} return (" + returnType + ")this;") .endBlock() .build(); } });
); Property genericProperty = new PropertyBuilder(property).withTypeRef(unwrapped).build(); methods.add( new MethodBuilder()
.withTypeRef(TypeAs.BUILDER.apply(type).toInternalReference()) .withName(BUILDER) .withModifiers(TypeUtils.modifiersToInt(Modifier.PRIVATE, Modifier.FINAL)) .withTypeRef(functionType) .withName(FUNCTION) .withModifiers(TypeUtils.modifiersToInt(Modifier.PRIVATE, Modifier.FINAL))