Esempio n. 1
0
 void parseRequest(Method method, Thrift thrift) {
   Annotation[][] parametersAnnotations = method.getParameterAnnotations();
   Type[] parameterTypes = method.getGenericParameterTypes();
   for (int i = 0, n = parametersAnnotations.length; i < n; i++) {
     Field paramField = null;
     Annotation[] parameterAnnotations = parametersAnnotations[i];
     for (Annotation annotation : parameterAnnotations) {
       if (annotation instanceof Field) {
         paramField = (Field) annotation;
         break;
       }
     }
     if (paramField == null) {
       throw new IllegalArgumentException(
           "parameter" + " of method " + methodName + " is not annotated with @Field");
     }
     TypeAdapter typeAdapter = thrift.getAdapter(parameterTypes[i]);
     requestTypeList.add(
         new FieldSpec(paramField.id(), paramField.required(), paramField.name(), typeAdapter));
   }
 }
Esempio n. 2
0
 void parseResponse(Method method, Func func, Thrift thrift) {
   Type type = getMethodReturnType(method);
   // if return type is Void,we don't need to find adapter
   if (Void.class.equals(type) || void.class.equals(type)) {
     isVoid = true;
   } else {
     TypeAdapter returnTypeAdapter = thrift.getAdapter(type);
     responseSuccessType =
         new FieldSpec((short) 0, false, "success", returnTypeAdapter); // success
   }
   Field[] exceptionFields = func.value();
   Class<?>[] exceptions = method.getExceptionTypes();
   if (exceptionFields != null) {
     for (int i = 0, n = exceptionFields.length; i < n; i++) {
       Field exceptionField = exceptionFields[i];
       TypeAdapter exceptionTypeAdapter = thrift.getAdapter(exceptions[i]);
       responseExceptionTypeMap.put(
           exceptionField.id(),
           new FieldSpec(exceptionField.id(), false, exceptionField.name(), exceptionTypeAdapter));
     }
   }
 }