public PropertyBuilder edit() { return new PropertyBuilder(this); }
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 A addToArguments(Property... items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.add(builder);this.arguments.add(builder);} return (A)this; }
public A removeFromArguments(Property... items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.remove(builder);this.arguments.remove(builder);} return (A)this; }
public A removeAllFromProperties(Collection<Property> items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.remove(builder);if (this.properties != null) {this.properties.remove(builder);}} return (A)this; }
public A addAllToArguments(Collection<Property> items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.add(builder);this.arguments.add(builder);} return (A)this; }
public A removeFromProperties(Property... items){ for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.remove(builder);if (this.properties != null) {this.properties.remove(builder);}} return (A)this; }
public A setToArguments(int index,Property item){ PropertyBuilder builder = new PropertyBuilder(item); if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);} if (index < 0 || index >= arguments.size()) { arguments.add(builder); } else { arguments.set(index, builder);} return (A) this; }
public A addToProperties(Property... items){ if (this.properties == null) {this.properties = new ArrayList<PropertyBuilder>();} for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.add(builder);this.properties.add(builder);} return (A)this; }
public A addToArguments(int index, Property item) { PropertyBuilder builder = new PropertyBuilder(item); _visitables.add(index >= 0 ? index : _visitables.size(), builder); this.arguments.add(index >= 0 ? index : arguments.size(), builder); return (A) this; }
public A addAllToProperties(Collection<Property> items){ if (this.properties == null) {this.properties = new ArrayList<PropertyBuilder>();} for (Property item : items) {PropertyBuilder builder = new PropertyBuilder(item);_visitables.add(builder);this.properties.add(builder);} return (A)this; }
public A setToProperties(int index,Property item){ if (this.properties == null) {this.properties = new ArrayList<PropertyBuilder>();} PropertyBuilder builder = new PropertyBuilder(item); if (index < 0 || index >= _visitables.size()) { _visitables.add(builder); } else { _visitables.set(index, builder);} if (index < 0 || index >= properties.size()) { properties.add(builder); } else { properties.set(index, builder);} return (A)this; }
public A addToProperties(int index,Property item){ if (this.properties == null) {this.properties = new ArrayList<PropertyBuilder>();} PropertyBuilder builder = new PropertyBuilder(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this.properties.add(index >= 0 ? index : properties.size(), builder); return (A)this; }
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(); } };
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(); }
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(); } });