}
private void walkFormParameter(ClassDoc formDoc) {
// walk all fields
for (FieldDoc field : formDoc.fields(false)) {
final AnnotationDesc pathParamAnnotation = Utils.findAnnotation(field, PathParam.class);
if (pathParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(pathParamAnnotation);
pathParameters.add(new FormFieldParameter(field, pathParamAnnotation, MethodParameterType.Path));
continue;
}
final AnnotationDesc matrixParamAnnotation = Utils.findAnnotation(field, MatrixParam.class);
if (matrixParamAnnotation != null) {
matrixParameters.add(new FormFieldParameter(field, matrixParamAnnotation, MethodParameterType.Matrix));
continue;
}
final AnnotationDesc queryParamAnnotation = Utils.findAnnotation(field, QueryParam.class);
if (queryParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(queryParamAnnotation);
queryParameters.add(new FormFieldParameter(field, queryParamAnnotation, MethodParameterType.Query));
continue;
}
final AnnotationDesc headerParamAnnotation = Utils.findAnnotation(field, HeaderParam.class);
if (headerParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(headerParamAnnotation);
headerParameters.add(new FormFieldParameter(field, headerParamAnnotation, MethodParameterType.Header));
continue;
}
final AnnotationDesc cookieParamAnnotation = Utils.findAnnotation(field, CookieParam.class);
if (cookieParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(cookieParamAnnotation);
cookieParameters.add(new FormFieldParameter(field, cookieParamAnnotation, MethodParameterType.Cookie));
continue;
}
final AnnotationDesc formParamAnnotation = Utils.findAnnotation(field, FormParam.class);
if (formParamAnnotation != null) {
formParameters.add(new FormFieldParameter(field, formParamAnnotation, MethodParameterType.Form));
continue;
}
//Recurse into the embedded @Form field
if(formClass != null) {
final AnnotationDesc formAnnotation = Utils.findAnnotation(field, formClass);
if(formAnnotation != null) {
walkFormParameter(field.type().asClassDoc());
continue;
}
}
final AnnotationDesc contextAnnotation = Utils.findAnnotation(field, Context.class);
if (contextAnnotation == null) {
this.inputParameter = new FormFieldParameter(field, null, MethodParameterType.Input);
continue;
}
}
// and methods
for (MethodDoc method : formDoc.methods(false)) {
if (!method.returnType().qualifiedTypeName().equals("void") || method.parameters().length != 1 || !method.name().startsWith("set"))
continue;
Parameter parameter = method.parameters()[0];
final AnnotationDesc pathParamAnnotation = Utils.findParameterAnnotation(method, parameter, 0, PathParam.class);
if (pathParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(pathParamAnnotation);
pathParameters.add(new FormMethodParameter(method, pathParamAnnotation, MethodParameterType.Path));
continue;
}
final AnnotationDesc matrixParamAnnotation = Utils.findParameterAnnotation(method, parameter, 0, MatrixParam.class);
if (matrixParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(matrixParamAnnotation);
matrixParameters.add(new FormMethodParameter(method, matrixParamAnnotation, MethodParameterType.Matrix));
continue;
}
final AnnotationDesc queryParamAnnotation = Utils.findParameterAnnotation(method, parameter, 0, QueryParam.class);
if (queryParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(queryParamAnnotation);
queryParameters.add(new FormMethodParameter(method, queryParamAnnotation, MethodParameterType.Query));
continue;
}
final AnnotationDesc headerParamAnnotation = Utils.findParameterAnnotation(method, parameter, 0, HeaderParam.class);
if (headerParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(headerParamAnnotation);
headerParameters.add(new FormMethodParameter(method, headerParamAnnotation, MethodParameterType.Header));
continue;
}
final AnnotationDesc cookieParamAnnotation = Utils.findParameterAnnotation(method, parameter, 0, CookieParam.class);
if (cookieParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(cookieParamAnnotation);
cookieParameters.add(new FormMethodParameter(method, cookieParamAnnotation, MethodParameterType.Cookie));
continue;
}
final AnnotationDesc formParamAnnotation = Utils.findParameterAnnotation(method, parameter, 0, FormParam.class);
if (formParamAnnotation != null) {
String name = (String) Utils.getAnnotationValue(formParamAnnotation);
formParameters.add(new FormMethodParameter(method, formParamAnnotation, MethodParameterType.Form));
continue;
}
// I'm not sure if @Form can be used on setter methods on an @Form field, but just in case...
if(formClass != null) {
//recurse into @Form parameters
final AnnotationDesc formAnnotation = Utils.findParameterAnnotation(method, parameter, 0, formClass);
if(formAnnotation != null) {
walkFormParameter(parameter.type().asClassDoc());
continue;
}
}
final AnnotationDesc contextAnnotation = Utils.findParameterAnnotation(method, parameter, 0, Context.class);
if (contextAnnotation == null) {
this.inputParameter = new FormMethodParameter(method, null, MethodParameterType.Input);
}
}
}