public static final Method forProperty(Property property) { return new MethodBuilder() .withName(name(property)) .withReturnType(property.getTypeRef()) .withNewBlock() .addNewStringStatementStatement("return this." + property + ";") .endBlock() .build(); }
private static Method superConstructorOf(Method constructor, TypeDef constructorType) { List<AnnotationRef> annotations = new ArrayList<AnnotationRef>(); for (AnnotationRef candidate : constructor.getAnnotations()) { if (!candidate.getClassRef().equals(BUILDABLE_ANNOTATION.getClassRef())) { annotations.add(candidate); } } return new MethodBuilder(constructor) .withAnnotations(annotations) .withReturnType(constructorType.toReference()) .withNewBlock() .addNewStringStatementStatement("super(" + StringUtils.join(constructor.getArguments(), new Function<Property, String>() { public String apply(Property item) { return item.getName(); } }, ", ") + ");") .endBlock() .build(); } }
.withTypeRef(baseType.toReference()) .endArgument() .withNewBlock() .addNewStringStatementStatement("this.builder = new " + builderType.getName() + "(this, item);") .endBlock() .withName("") .withReturnType(nestedRef) .withNewBlock() .addNewStringStatementStatement("this.builder = new " + builderType.getName() + "(this);") .endBlock()
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 Method apply(Property property) { String methodName = "set" + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(VOID) .withArguments() .withNewBlock() .addNewStringStatementStatement("this." + property.getName() + "=" + property.getName() + ";") .endBlock() .build(); } });
public Method apply(final Property property) { String prefix = "has"; String methodName = prefix + property.getNameCapitalized(); List<Statement> statements = new ArrayList<Statement>(); if (isPrimitive(property.getTypeRef())) { statements.add(new StringStatement("return true;")); } else if (isList(property.getTypeRef()) || isSet(property.getTypeRef())) { statements.add(new StringStatement("return " + property.getName() + " != null && !" + property.getName() + ".isEmpty();")); } else if (isOptional(property.getTypeRef())|| isOptionalInt(property.getTypeRef()) || isOptionalLong(property.getTypeRef()) || isOptionalDouble(property.getTypeRef())) { statements.add(new StringStatement("return " + property.getName() + " != null && " + property.getName() + ".isPresent();")); } else { statements.add(new StringStatement("return this." + property.getName() + " != null;")); } return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withName(methodName) .withReturnType(BOOLEAN_REF) .withArguments() .withNewBlock() .withStatements(statements) .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(); } });
.withReturnType(builderType.toInternalReference()) .withName("edit") .withNewBlock() .addToStatements(new StringStatement(new Provider<String>() { @Override
.withReturnType(returnType) .withArguments(property) .withNewBlock() .addNewStringStatementStatement("if (" + fieldName + " == null || !" + fieldName + ".isPresent()) { this." + fieldName + " = " + property.getAttribute(INIT) + "; } else {" + prepareOptionalSource + " this." + fieldName + " = " + optionalSource + "; } return (" + returnType + ") this;") .endBlock() .withReturnType(returnType) .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()
.withReturnType(rewraped) .withName(methodName) .withNewBlock() .addNewStringStatementStatement(statement) .endBlock()
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) { 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(); } });
public Method apply(Property property) { String classPrefix = getClassPrefix(property); boolean isArray = TypeUtils.isArray(property.getTypeRef()); boolean isList = TypeUtils.isList(property.getTypeRef()); boolean isSet = TypeUtils.isSet(property.getTypeRef()); String prefix = isArray || isList ? "setTo" : "with"; String withMethodName = prefix + property.getNameCapitalized(); return new MethodBuilder() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withReturnType(N_REF) .withName("and") .withNewBlock() .addNewStringStatementStatement("return (N) " + classPrefix + withMethodName + "(" + (isArray || isList ? "index, " : "") + "builder.build());") .endBlock() .build(); }
.withTypeRef(baseType) .endArgument() .withNewBlock() .addNewStringStatementStatement(statement) .endBlock()
.withTypeRef(baseType) .endArgument() .withNewBlock() .addNewStringStatementStatement("return new " + rewrapedImpl.getName() + "(" + (isCollection ? "-1, " : "") + "item);") .endBlock()
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(); }
.withName(ownName) .withParameters(baseType.getParameters()) .withNewBlock() .addNewStringStatementStatement("return (" + returnType + ")" + delegateName + "(new " + baseType.getName() + "(" + args + "));") .endBlock()
.withReturnType(rewraped) .withName(methodName) .withNewBlock() .addNewStringStatementStatement("return new " + rewrapedImpl.getName() + "();") .endBlock()
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(); } });