com.yixsoft.support.mybatis.utils.MapperMethodUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yixsoft-batis Show documentation
Show all versions of yixsoft-batis Show documentation
YixSoft MyBatis AutoSql Plugin
package com.yixsoft.support.mybatis.utils;
import java.lang.reflect.*;
import java.util.Collection;
/**
* get method return type utils
* Created by yixian on 2015-09-03.
*/
public class MapperMethodUtils {
public static Class> getReturnType(Method method) {
Class> returnType = method.getReturnType();
// issue #508
if (Collection.class.isAssignableFrom(returnType)) {
Type returnTypeParameter = method.getGenericReturnType();
if (returnTypeParameter instanceof ParameterizedType) {
Type[] actualTypeArguments = ((ParameterizedType) returnTypeParameter).getActualTypeArguments();
if (actualTypeArguments != null && actualTypeArguments.length == 1) {
returnTypeParameter = actualTypeArguments[0];
if (returnTypeParameter instanceof Class) {
returnType = (Class>) returnTypeParameter;
} else if (returnTypeParameter instanceof ParameterizedType) {
// (issue #443) actual type can be a also a parameterized type
returnType = (Class>) ((ParameterizedType) returnTypeParameter).getRawType();
} else if (returnTypeParameter instanceof GenericArrayType) {
Class> componentType = (Class>) ((GenericArrayType) returnTypeParameter).getGenericComponentType();
// (issue #525) support List
returnType = Array.newInstance(componentType, 0).getClass();
}
}
}
}
return returnType;
}
}