.withName(constructor.getName()) .withModifiers(constructor.getModifiers()) .withArguments(arguments) .withParameters(parameters) .withAnnotations(annotationRefs)
.withModifiers(method.getModifiers()) .withReturnType(TYPEREF.apply(method.getReturnType())) .withArguments(arguments) .withParameters(parameters) .withAnnotations(annotationRefs)
.withName("") .withReturnType(nestedRef) .withArguments(arguments) .withNewBlock() .withStatements(statementsWithItem)
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(); } });
.withName(removeVarargMethodName) .withReturnType(returnType) .withArguments(builderProperty) .withNewBlock() .addToStatements( .withParameters(parameters) .withReturnType(returnType) .withArguments(item) .withVarArgPreferred(true) .withNewBlock() .withName(removeAllMethdoName) .withReturnType(returnType) .withArguments(new PropertyBuilder(item).withTypeRef(COLLECTION.toReference(unwrapped)).build()) .withNewBlock() .withStatements(statements)
.withName(methodName) .withReturnType(returnType) .withArguments(property) .withNewBlock() .addNewStringStatementStatement("if (" + fieldName + " == null || !" + fieldName + ".isPresent()) { this." + fieldName + " = " + property.getAttribute(INIT) + "; } else {" + prepareOptionalSource + " this." + fieldName + " = " + optionalSource + "; } return (" + returnType + ") this;") .withName(methodName) .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;")
.withReturnType(returnType) .withExceptions(exceptions) .withArguments(arguments) .withBlock(BLOCK.apply(methodDeclaration.getBody())) .build()); .withModifiers(constructorDeclaration.getModifiers()) .withExceptions(exceptions) .withArguments(arguments) .withBlock(BLOCK.apply(constructorDeclaration.getBlock())) .build());
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) { 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(); }
public MethodBuilder(Method instance,Boolean validationEnabled){ this.fluent = this; this.withComments(instance.getComments()); this.withAnnotations(instance.getAnnotations()); this.withParameters(instance.getParameters()); this.withName(instance.getName()); this.withReturnType(instance.getReturnType()); this.withArguments(instance.getArguments()); this.withVarArgPreferred(instance.isVarArgPreferred()); this.withExceptions(instance.getExceptions()); this.withBlock(instance.getBlock()); this.withModifiers(instance.getModifiers()); this.withAttributes(instance.getAttributes()); this.validationEnabled = validationEnabled; }
.withModifiers(TypeUtils.modifiersToInt(Modifier.PUBLIC)) .withReturnType(returnType) .withArguments(constructor.getArguments()) .withName(ownName) .withParameters(baseType.getParameters())
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(); } });
String suffix = Singularize.FUNCTION.apply(property.getNameCapitalized()); methods.add(new MethodBuilder(base) .withArguments(INDEX) .withName("edit" + suffix) .editBlock() .withArguments() .editBlock() .withStatements( .withArguments() .editBlock() .withStatements(
.withName(getterName) .withReturnType(property.getTypeRef()) .withArguments() .withNewBlock() .addNewStringStatementStatement(body)
.withName(addVarargMethodName) .withReturnType(returnType) .withArguments(builderProperty) .withNewBlock() .addToStatements( .withName(addVarargMethodName) .withReturnType(returnType) .withArguments(INDEX, builderProperty) .withNewBlock() .addToStatements( .withName(addVarargMethodName) .withReturnType(returnType) .withArguments(item) .withVarArgPreferred(true) .withNewBlock() .withName(addAllMethodName) .withReturnType(returnType) .withArguments(new PropertyBuilder(item).withTypeRef(COLLECTION.toReference(unwrapped)).build()) .withNewBlock() .addAllToStatements(collectionInit)
.withName(getterName) .withReturnType(property.getTypeRef()) .withArguments(new Property[]{}) .withNewBlock() .withStatements(statements)