public String fetchFromReqCode(ResourceMethodParameter parameter, ResourceMethod method) { return ParameterExpressionBuilder .createFromMapQueryObjectFromRequest(parameter, EndpointParameterKind.QUERY) .surroundWithCheckValid(parameter) .getParameterExpr(); } },
@Override public String apply(ParsedType param) { return toTypeDescription(param); } }).join(Joiner.on(", "));
public String fetchFromReqCode(ResourceMethodParameter parameter, ResourceMethod method) { return ParameterExpressionBuilder .createFromExpr("body", "body") .surroundWithCheckValid(parameter) .getParameterExpr(); } },
private ResourceMethodParameter(String type, String name, String reqParamName, ResourceMethodParameterKind kind, String[] validationGroupsFQNs) { TypeHelper.OptionalMatchingType optionalMatchingReturnType = TypeHelper.optionalMatchingTypeOf(type); if(optionalMatchingReturnType.getOptionalType() == TypeHelper.OptionalMatchingType.Type.GUAVA) { this.guavaOptional = true; this.java8Optional = false; } else if(optionalMatchingReturnType.getOptionalType() == TypeHelper.OptionalMatchingType.Type.JAVA8) { this.guavaOptional = false; this.java8Optional = true; } else { this.guavaOptional = false; this.java8Optional = false; } this.type = optionalMatchingReturnType.getUnderlyingType(); this.realType = type; this.name = name; this.reqParamName = reqParamName; this.kind = kind; this.validationGroupsFQNs = Arrays.asList(validationGroupsFQNs); }
String getValueCodeInstanciation() { if(AnnotationFieldKind.ANNOTATION.equals(this.kind)) { return "throw new java.lang.UnsupportedOperationException(\"Unsupported annotation field type\")"; } else if(isArray) { return String.format("return new %s[]{ %s }", // Arrays cannot be parameterized TypeHelper.rawTypeFrom(type.toString()), Joiner.on(", ").join((List)value)); } else { return "return "+kind.transformSingleValueToExpression(value, this); } } }
static String toTypeDescription(String type) { return toTypeDescription(parseParameterizedType(type)); }
static String getTypeExpressionFor(String type) { return getTypeExpressionFor(parseParameterizedType(type)); }
@Override public String transformSingleValueToExpression(Object value, AnnotationField annotationField) { return super.transformSingleValueToExpression(value, annotationField) + ".class"; } }, ENUM() {
public static OptionalMatchingType none(String underlyingType) { return new OptionalMatchingType(Type.NONE, underlyingType); }
@Override public String apply(ParsedType param) { return getTypeExpressionFor(param); } }).join(Joiner.on(", "))
public static ParameterExpressionBuilder createFromExpr(String expr, String kind) { return new ParameterExpressionBuilder(expr, kind); }
private ResourceGroup getResourceGroup(ResourceClassDef r, Map<String, ResourceGroup> groups) { ResourceGroup group = groups.get(r.group); if (group == null) { groups.put(r.group, group = new ResourceGroup(r.group)); } return group; }
static String rawTypeFrom(String type) { return isParameterizedType(type)?type.substring(0, type.indexOf("<")):type; }
protected ResourceClassDef getResourceClassDef(TypeElement typeElem) { RestxResource r = typeElem.getAnnotation(RestxResource.class); ResourceClassDef resourceClassDef = new ResourceClassDef(); resourceClassDef.value = r.value(); resourceClassDef.priority = r.priority(); resourceClassDef.group = r.group(); return resourceClassDef; }
public String fetchFromReqCode(ResourceMethodParameter parameter, ResourceMethod method) { return ParameterExpressionBuilder .createFromMapQueryObjectFromRequest(parameter, EndpointParameterKind.HEADER) .surroundWithCheckValid(parameter) .getParameterExpr(); } },
@Override public String transformSingleValueToExpression(Object value, AnnotationField annotationField) { String val = super.transformSingleValueToExpression(value, annotationField); switch(annotationField.type.toString()) { case "float": return val+"f"; case "char": return "'"+val+"'"; default: return val; } } }, STRING() {
public static OptionalMatchingType guava(String underlyingType) { return new OptionalMatchingType(Type.GUAVA, underlyingType); }
public String fetchFromReqCode(ResourceMethodParameter parameter, ResourceMethod method) { return ParameterExpressionBuilder .createFromMapQueryObjectFromRequest(parameter, EndpointParameterKind.PATH) .surroundWithCheckValid(parameter) .getParameterExpr(); } },
@Override public String transformSingleValueToExpression(Object value, AnnotationField annotationField) { return "\"" + super.transformSingleValueToExpression(value, annotationField).replace("\\", "\\\\").replace("\"", "\\\"") + "\""; } }, CLASS() {
public static OptionalMatchingType java8(String underlyingType) { return new OptionalMatchingType(Type.JAVA8, underlyingType); }