.withModifiers(modifiersToInt(Modifier.PUBLIC)) .withNewBlock() .withStatements(new StringStatement("return this." + StringUtils.toFieldName(name) + ";")) .endBlock() .build()); .withArguments(constructorArgs) .withNewBlock() .withStatements(statements) .endBlock() .accept(new TypedVisitor<PropertyBuilder>() { @Override .withReturnType(pojoBuilder.toInternalReference()) .withNewBlock() .addNewStringStatementStatement("return new "+ pojoBuilder.getFullyQualifiedName()+"();") .endBlock() .build(); .withReturnType(generatedPojo.toInternalReference()) .withNewBlock() .addNewStringStatementStatement("return newBuilder(instance).build();") .endBlock() .build(); .withReturnType(pojoBuilder.toInternalReference()) .withNewBlock() .addToStatements(new StringStatement(() -> "return " + convertReference("instance", item, generatedPojo, pojoBuilder)+";")) .endBlock()
.withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withNewBlock() .addNewStringStatementStatement("this(true);") .endBlock() .build(); .and() .withNewBlock() .addToStatements(new StringStatement(new Provider<String>() { @Override public String get() { .endBlock() .build(); .and() .withNewBlock() .addNewStringStatementStatement("this(fluent, true);") .endBlock() .build(); .and() .withNewBlock() .addToStatements(new StringStatement(new Provider<String>() { @Override public String get() { .endBlock() .build();
.withArguments(new Property[]{}) .withNewBlock() .withStatements(statements) .endBlock() .build(); .addToArguments(INDEX) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(index).build();")) .endBlock() .build()); .withReturnType(unwrapped) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(0).build();")) .endBlock() .build()); .withReturnType(unwrapped) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(" + property.getName() + ".size() - 1).build();")) .endBlock() .build()); .withReturnType(unwrapped) .withNewBlock() .withStatements(new StringStatement("for (" + builderRef + " item: " + property.getName() + ") { if(predicate.apply(item)){return item.build();} } return null;")) .endBlock() .build());
.addToArguments(unwrappedProperty) .withNewBlock() .withStatements(new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), new StringStatement("this." + propertyName + ".add(index, item);"), new StringStatement("return (" + returnType + ")this;")) .endBlock() .addToAttributes(Attributeable.ALSO_IMPORT, alsoImport) .build(); .addToArguments(unwrappedProperty) .withNewBlock() .withStatements(new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), new StringStatement("this." + propertyName + ".set(index, item); return (" + returnType + ")this;")) .endBlock() .addToAttributes(Attributeable.ALSO_IMPORT, alsoImport) .build(); .withParameters(parameters) .editBlock() .withStatements( new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), new StringStatement(builderClass + " builder = new " + builderClass + "(item);_visitables.add(index >= 0 ? index : _visitables.size(), builder);this." + propertyName + ".add(index >= 0 ? index : " + propertyName + ".size(), builder); return (" + returnType + ")this;")) .endBlock() .build(); .withParameters(parameters) .editBlock() .withStatements( new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"),
.withName("instance").and() .withNewBlock() .withStatements(toInstanceConstructorBody(item, "")) .endBlock() .build();
.withArguments() .withNewBlock() .addNewStringStatementStatement(body) .endBlock() .addToAttributes(ALSO_IMPORT, isBuildable ? Arrays.asList(BuilderContextManager.getContext().getVisitableBuilderInterface().toInternalReference()) : Collections.EMPTY_LIST) .build(); .addToArguments(INDEX) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(index).build();")) .endBlock() .build()); .withReturnType(unwrapped) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(0).build();")) .endBlock() .build()); .withReturnType(unwrapped) .withNewBlock() .withStatements(new StringStatement("return this." + property.getName() + ".get(" + property.getName() + ".size() - 1).build();")) .endBlock() .build()); .withReturnType(unwrapped) .withNewBlock() .withStatements(new StringStatement("for (" + builderRef + " item: " + property.getName() + ") { if(predicate.apply(item)){return item.build();} } return null;")) .endBlock()
.withName(methodName) .withNewBlock() .addNewStringStatementStatement(statement) .endBlock() .build(); .withName("edit" + suffix) .editBlock() .withStatements( new StringStatement("if (" + property.getName() + ".size() <= index) throw new RuntimeException(\"Can't edit " + property.getName() + ". Index exceeds size.\");"), new StringStatement("return setNew" + suffix + "Like(index, build" + suffix + "(index));") .endBlock() .build()); .withArguments() .editBlock() .withStatements( new StringStatement("if (" + property.getName() + ".size() == 0) throw new RuntimeException(\"Can't edit first " + property.getName() + ". The list is empty.\");"), new StringStatement("return setNew" + suffix + "Like(0, build" + suffix + "(0));")) .endBlock() .build()); .withArguments() .editBlock() .withStatements( new StringStatement("int index = "+property.getName()+".size() - 1;"), new StringStatement("if (index < 0) throw new RuntimeException(\"Can't edit last "+property.getName()+". The list is empty.\");"), new StringStatement("return setNew" + suffix + "Like(index, build" + suffix + "(index));"))
.withName(inline.value()) .withNewBlock() .addNewStringStatementStatement(BUILD_AND_APPLY_FUNCTION) .endBlock() .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .build(); .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withNewBlock() .addNewStringStatementStatement(String.format(NEW_BULDER_AND_SET_FUNCTION_FORMAT, builderType.getName())) .endBlock() .build()); .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withNewBlock() .addNewStringStatementStatement(String.format(NEW_BULDER_WITH_ITEM_AND_SET_FUNCTION_FORMAT, builderType.getName())) .endBlock() .build()); .withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withNewBlock() .addNewStringStatementStatement(String.format(NEW_BUILDER_AND_EMTPY_FUNCTION_FORMAT, builderType.getName(), String.format(EMPTY_FUNCTION_TEXT, type.toInternalReference(), returnType.toInternalReference(), returnType.toInternalReference(), type.toInternalReference()))) .endBlock() .build());
.withArguments(builderProperty) .withNewBlock() .addToStatements( new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), new StringStatement("_visitables.remove(builder);this."+propertyName+".remove(builder); return (" + returnType + ")this;") .endBlock() .build()); } else { .withVarArgPreferred(true) .withNewBlock() .withStatements(statements) .endBlock() .build(); .withArguments(new PropertyBuilder(item).withTypeRef(COLLECTION.toReference(unwrapped)).build()) .withNewBlock() .withStatements(statements) .endBlock() .addToAttributes(Attributeable.ALSO_IMPORT, alsoImport) .build();
.withArguments(arguments) .withNewBlock() .withStatements(statementsWithItem) .endBlock() .build()); .withReturnType(nestedRef) .withNewBlock() .withStatements(statementsWithoutItem) .endBlock() .build());
.endArgument() .withNewBlock() .addNewStringStatementStatement("this.builder = new " + builderType.getName() + "(this, item);") .endBlock() .build()); .withReturnType(nestedRef) .withNewBlock() .addNewStringStatementStatement("this.builder = new " + builderType.getName() + "(this);") .endBlock() .build());
.endArgument() .withNewBlock() .addNewStringStatementStatement(statement) .endBlock() .build();
.withName("edit") .withNewBlock() .addToStatements(new StringStatement(new Provider<String>() { @Override public String get() { .endBlock() .build();
.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() );
.withName(methodName) .withNewBlock() .addNewStringStatementStatement("return new " + rewrapedImpl.getName() + "();") .endBlock() .build();
.endArgument() .withNewBlock() .addNewStringStatementStatement("return new " + rewrapedImpl.getName() + "(" + (isCollection ? "-1, " : "") + "item);") .endBlock() .build();
.withParameters(baseType.getParameters()) .withNewBlock() .addNewStringStatementStatement("return (" + returnType + ")" + delegateName + "(new " + baseType.getName() + "(" + args + "));") .endBlock() .build());
.withName(methodName) .withNewBlock() .addNewStringStatementStatement(statement) .endBlock() .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 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(); } });