@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(); } };
.withArguments(INDEX) .withName("edit" + suffix) .editBlock() .withStatements( new StringStatement("if (" + property.getName() + ".size() <= index) throw new RuntimeException(\"Can't edit " + property.getName() + ". Index exceeds size.\");"), .withName("editFirst" + suffix) .withArguments() .editBlock() .withStatements( new StringStatement("if (" + property.getName() + ".size() == 0) throw new RuntimeException(\"Can't edit first " + property.getName() + ". The list is empty.\");"), .withName("editLast" + suffix) .withArguments() .editBlock() .withStatements( new StringStatement("int index = "+property.getName()+".size() - 1;"), .withTypeRef(predicate.toReference(builderRef)) .endArgument() .editBlock() .withStatements( new StringStatement("int index = -1;"),
.editBlock() .withStatements( new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), .editBlock() .withStatements( new StringStatement("if (this." + propertyName + " == null) {this." + propertyName + " = " + property.getAttribute(LAZY_INIT) + ";}"), .editBlock() .withStatements(createAddToDescendants("addTo", descendants, true), new StringStatement("return (" + returnType + ")this;")) .endBlock() .editBlock() .withStatements(createAddToDescendants("setTo", descendants, true), new StringStatement("return (" + returnType + ")this;")) .endBlock()