FunctionCall(Method method, Thrift thrift) { methodName = method.getName(); Func func = method.getAnnotation(Func.class); if (func == null) { throw new IllegalArgumentException( "method " + methodName + " should be annotated with @Func"); } oneway = func.oneway(); isObservable = getIsObservable(method); parseRequest(method, thrift); parseResponse(method, func, thrift); argsStruct = new TStruct(methodName + "_args"); }
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)); } } }