@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(); } };
private List<Statement> getStatements(Property property, List<ClassRef> alsoImport) { TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; String argumentName = property.getName(); String fieldName = property.getName(); TypeRef unwrapped = combine(UNWRAP_COLLECTION_OF, UNWRAP_ARRAY_OF, UNWRAP_OPTIONAL_OF).apply(property.getTypeRef()); List<Statement> statements = new ArrayList<Statement>(); Set<Property> descendants = property.hasAttribute(DESCENDANTS) ? property.getAttribute(DESCENDANTS) : Collections.EMPTY_SET; if (property.hasAttribute(DESCENDANT_OF)) { Property descendantOf = property.getAttribute(DESCENDANT_OF); fieldName = descendantOf.getName();
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) { 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 returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property);
Property builderProperty = new PropertyBuilder(property).withName("builder").withTypeRef(builderType).build(); TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; final TypeRef unwrapped = BOXED_OF.apply(TypeAs.combine(UNWRAP_COLLECTION_OF).apply(property.getTypeRef())); List<ClassRef> alsoImport = new ArrayList<ClassRef>(); if (isBuildable(unwrapped) && !isAbstract(unwrapped)) { final ClassRef targetType = (ClassRef) unwrapped; if (property.hasAttribute(Constants.DESCENDANT_OF)) { Property attrValue = property.getAttribute(Constants.DESCENDANT_OF); if (attrValue != null) {
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(); } });
TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property);
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; 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);
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());
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();
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(); } });
TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; final TypeRef unwrapped = BOXED_OF.apply(TypeAs.combine(UNWRAP_COLLECTION_OF).apply(property.getTypeRef())); List<ClassRef> alsoImport = new ArrayList<ClassRef>(); if (property.hasAttribute(Constants.DESCENDANT_OF)) { Property attrValue = property.getAttribute(Constants.DESCENDANT_OF); if (attrValue != null) {
TypeRef returnType = property.hasAttribute(GENERIC_TYPE_REF) ? property.getAttribute(GENERIC_TYPE_REF) : T_REF; TypeDef nestedType = PropertyAs.NESTED_INTERFACE_TYPE.apply(property);
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();