private void addStatusField(RestActionClass actionClass, MethodSpec.Builder builder) { for (Element element : actionClass.getAnnotatedElements(Status.class)) { String fieldAddress = getFieldAddress(actionClass, element); if (TypeUtils.containsType(element, Boolean.class, boolean.class)) { builder.addStatement(fieldAddress + " = response.isSuccessful()", element); } else if (TypeUtils.containsType(element, Integer.class, int.class, long.class)) { builder.addStatement( fieldAddress + " = ($T) response.getStatus()", element, element.asType()); } else if (equalTypes(element, String.class)) { builder.addStatement(fieldAddress + " = Integer.toString(response.getStatus())", element); } else if (TypeUtils.containsType(element, Long.class)) { builder.addStatement(fieldAddress + " = (long) response.getStatus()", element); } } }
private MethodSpec createFillErrorMethod(RestActionClass actionClass) { MethodSpec.Builder builder = MethodSpec.methodBuilder("fillError") .addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class) .returns(actionClass.getTypeName()) .addParameter(actionClass.getTypeName(), "action") .addParameter(Throwable.class, "error"); for (Element element : actionClass.getAnnotatedElements(Error.class)) { String fieldAddress = getFieldAddress(actionClass, element); if (TypeUtils.containsType(element, Throwable.class)) { builder.addStatement(fieldAddress + " = error", element); } else if (TypeUtils.containsType(element, Exception.class)) { builder.addStatement(fieldAddress + " = ($T) error", element, Exception.class); } } builder.addStatement("return action"); return builder.build(); }