private void writeField(Writer writer, Property field, String block) throws IOException { if (field != null) { writer.append(field.toString()); if (field.getAttribute(INIT) != null) { writer.append(" = ").append(field.getAttribute(INIT)); } } writer.append(";"); } }
private String getClassPrefix(Property property) { TypeDef memberOf = property.getAttribute(OUTER_CLASS); if (memberOf != null) { return memberOf.getName() + ".this."; } else return ""; }
public TypeDef apply(Property property) { TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); TypeRef typeRef = TypeAs.combine(UNWRAP_COLLECTION_OF, UNWRAP_ARRAY_OF, UNWRAP_OPTIONAL_OF).apply(property.getTypeRef()); TypeDef typeDef = BuilderContextManager.getContext().getDefinitionRepository().getDefinition(typeRef); if (typeDef == null) { if (typeRef instanceof ClassRef) { typeDef = ((ClassRef)typeRef).getDefinition(); } else { throw new IllegalStateException("Could not find definition from property: ["+property+"] neither in the repo nor via the object tree."); } } TypeDef outerInterface = property.getAttribute(OUTER_INTERFACE); List<TypeParamDef> parameters = new ArrayList<TypeParamDef>(); for (TypeParamDef generic : typeDef.getParameters()) { parameters.add(generic); } parameters.add(N); return new TypeDefBuilder(typeDef) .withPackageName(outerInterface.getPackageName()) .withName(BuilderUtils.fullyQualifiedNameDiff(property.getTypeRef(), originTypeDef) + property.getNameCapitalized() + "Nested") .withParameters(parameters) .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(); } };
public TypeDef apply(Property item) { TypeDef nested = new TypeDefBuilder(SHALLOW_NESTED_TYPE.apply(item)).withOuterType(item.getAttribute(OUTER_INTERFACE)).build(); TypeDef outerInterface = item.getAttribute(OUTER_INTERFACE);
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; 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(); } });
TypeRef unwrapped = TypeAs.combine(TypeAs.UNWRAP_OPTIONAL_OF).apply(property.getTypeRef()); TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; String methodName = "with" + property.getNameCapitalized(); String fieldName = property.getName(); .withArguments(property) .withNewBlock() .addNewStringStatementStatement("if (" + fieldName + " == null || !" + fieldName + ".isPresent()) { this." + fieldName + " = " + property.getAttribute(INIT) + "; } else {" + prepareOptionalSource + " this." + fieldName + " = " + optionalSource + "; } return (" + returnType + ") this;") .endBlock() .build() .withArguments(genericProperty) .withNewBlock() .addNewStringStatementStatement("if (" + fieldName + " == null) { this." + fieldName + " = " + property.getAttribute(INIT) + "; } else {" + prepareSource + " this." + fieldName + " = " + property.getAttribute(INIT_FUNCTION).apply(Collections.singletonList(source)) + "; } 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(); List<ClassRef> alsoImport = new ArrayList<ClassRef>(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(returnType) .withArguments(property) .withVarArgPreferred(true) .withNewBlock() .withStatements(getStatements(property, alsoImport)) .endBlock() .addToAttributes(Attributeable.ALSO_IMPORT, alsoImport) .build(); }
public TypeDef apply(Property item) { TypeDef shallowNestedType = SHALLOW_NESTED_TYPE.apply(item); TypeDef nestedInterfaceType = NESTED_INTERFACE_TYPE.apply(item); TypeDef outerClass = item.getAttribute(OUTER_CLASS);
public Method apply(Property property) { ClassRef baseType = (ClassRef) TypeAs.combine(UNWRAP_COLLECTION_OF, UNWRAP_OPTIONAL_OF, UNWRAP_OPTIONAL_OF).apply(property.getTypeRef()); TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property); TypeDef nestedTypeImpl = PropertyAs.NESTED_CLASS_TYPE.apply(property);
public Set<Method> apply(Property property) { TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; Set<Method> result = new LinkedHashSet<Method>(); TypeRef unwrappedType = TypeAs.combine(UNWRAP_COLLECTION_OF, UNWRAP_ARRAY_OF, UNWRAP_OPTIONAL_OF).apply(property.getTypeRef());
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(); } });
TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property);
public Method apply(Property property) { TypeDef originTypeDef = property.getAttribute(Constants.ORIGIN_TYPEDEF); String methodName = "end" + BuilderUtils.fullyQualifiedNameDiff(property.getTypeRef(), originTypeDef) + capitalizeFirst(IS_COLLECTION.apply(property.getTypeRef()) ? Singularize.FUNCTION.apply(property.getNameCapitalized()) : property.getNameCapitalized()); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withReturnType(N_REF) .withName(methodName) .withNewBlock() .addNewStringStatementStatement("return and();") .endBlock() .build(); } });
TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property);
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(); }
TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property); TypeDef nestedTypeImpl = PropertyAs.NESTED_CLASS_TYPE.apply(property);
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(); } });
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();