当前位置: 首页>>代码示例>>Java>>正文


Java Method.getGenericReturnType方法代码示例

本文整理汇总了Java中java.lang.reflect.Method.getGenericReturnType方法的典型用法代码示例。如果您正苦于以下问题:Java Method.getGenericReturnType方法的具体用法?Java Method.getGenericReturnType怎么用?Java Method.getGenericReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getGenericReturnType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getReturnTypes

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Type[] getReturnTypes(Invocation invocation) {
    try {
        if (invocation != null && invocation.getInvoker() != null
                && invocation.getInvoker().getUrl() != null
                && ! invocation.getMethodName().startsWith("$")) {
            String service = invocation.getInvoker().getUrl().getServiceInterface();
            if (service != null && service.length() > 0) {
                Class<?> cls = ReflectUtils.forName(service);
                Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                if (method.getReturnType() == void.class) {
                    return null;
                }
                return new Type[]{method.getReturnType(), method.getGenericReturnType()};
            }
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    }
    return null;
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:RpcUtils.java

示例2: getClassesForRecursion

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Looks at a method and gets any return or parameter types that match the basePackage.
 */
private static List<Class> getClassesForRecursion(String basePackage, Method method){
    List<Class> classesForRecursion = new ArrayList<>();

    // Check regular return types
    if (method.getReturnType().toString().contains(basePackage)) {
        classesForRecursion.add(method.getReturnType());
    } else {
        // Check for generic return types
        if (method.getGenericReturnType() instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType) method.getGenericReturnType();
            Arrays.stream(type.getActualTypeArguments())
                    .filter(actualType -> actualType.getTypeName().contains(basePackage))
                    .forEach(actualType -> classesForRecursion.add((Class) actualType));
        }
    }

    // Check for parameter types
    Arrays.stream(method.getParameterTypes())
            .filter(paramType -> paramType.toString().contains(basePackage))
            .forEach(classesForRecursion::add);

    return classesForRecursion;
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:27,代码来源:ClassPhotographer.java

示例3: getAsyncReturnType

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Class getAsyncReturnType(Method method, Class returnType) {
    if(Response.class.isAssignableFrom(returnType)){
        Type ret = method.getGenericReturnType();
        return erasure(((ParameterizedType)ret).getActualTypeArguments()[0]);
    }else{
        Type[] types = method.getGenericParameterTypes();
        Class[] params = method.getParameterTypes();
        int i = 0;
        for(Class cls : params){
            if(AsyncHandler.class.isAssignableFrom(cls)){
                return erasure(((ParameterizedType)types[i]).getActualTypeArguments()[0]);
            }
            i++;
        }
    }
    return returnType;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:RuntimeModeler.java

示例4: getAsyncReturnType

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Class getAsyncReturnType(Method method, Class returnType) {
    if(Response.class.isAssignableFrom(returnType)){
        Type ret = method.getGenericReturnType();
        return (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)ret).getActualTypeArguments()[0]);
    }else{
        Type[] types = method.getGenericParameterTypes();
        Class[] params = method.getParameterTypes();
        int i = 0;
        for(Class cls : params){
            if(AsyncHandler.class.isAssignableFrom(cls)){
                return (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)types[i]).getActualTypeArguments()[0]);
            }
            i++;
        }
    }
    return returnType;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:RuntimeModeler.java

示例5: getClazz

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * get field type
 */
private Type getClazz(Field field, Class<?> clazz) {
    Method method = getGetterMethod(field, clazz);
    if (method == null) {
        return null;
    }

    return method.getGenericReturnType();
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:12,代码来源:YmlAdaptor.java

示例6: getType

import java.lang.reflect.Method; //导入方法依赖的package包/类
public Type getType(String methodName){
    Method method;
    try {
        method = getClass().getDeclaredMethod(methodName, new Class<?>[]{} );
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    Type gtype = method.getGenericReturnType();
    return gtype;
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:11,代码来源:PojoUtilsTest.java

示例7: getMethodType

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Type getMethodType(Class<?> clazz, String methodName) {
    try {
        Method method = clazz.getMethod(methodName);

        return method.getGenericReturnType();
    } catch (Exception ex) {
        return null;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:ASMUtilsTest.java

示例8: get

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public CallAdapter<?, ?> get(ApiComposer apiComposer, Method method) {
    Type returnType = method.getGenericReturnType();
    Class<?> rawType = Types.getRawType(returnType);
    boolean isSingle = rawType == Single.class;
    if (rawType != Observable.class && !isSingle) {
        return null;
    }

    Type observableType = getParameterUpperBound(0, returnType);

    return new RxCallAdapter(observableType);
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:14,代码来源:RxCallAdapter.java

示例9: addPropertyDescriptor

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Adds the property descriptor to the list store.
 */
private void addPropertyDescriptor(PropertyDescriptor pd) {
    String propName = pd.getName();
    List<PropertyDescriptor> list = pdStore.get(propName);
    if (list == null) {
        list = new ArrayList<>();
        pdStore.put(propName, list);
    }
    if (this.beanClass != pd.getClass0()) {
        // replace existing property descriptor
        // only if we have types to resolve
        // in the context of this.beanClass
        Method read = pd.getReadMethod();
        Method write = pd.getWriteMethod();
        boolean cls = true;
        if (read != null) cls = cls && read.getGenericReturnType() instanceof Class;
        if (write != null) cls = cls && write.getGenericParameterTypes()[0] instanceof Class;
        if (pd instanceof IndexedPropertyDescriptor) {
            IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
            Method readI = ipd.getIndexedReadMethod();
            Method writeI = ipd.getIndexedWriteMethod();
            if (readI != null) cls = cls && readI.getGenericReturnType() instanceof Class;
            if (writeI != null) cls = cls && writeI.getGenericParameterTypes()[1] instanceof Class;
            if (!cls) {
                pd = new IndexedPropertyDescriptor(ipd);
                pd.updateGenericsFor(this.beanClass);
            }
        }
        else if (!cls) {
            pd = new PropertyDescriptor(pd);
            pd.updateGenericsFor(this.beanClass);
        }
    }
    list.add(pd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:Introspector.java

示例10: checkReturnType

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void checkReturnType(Method method1, Method method2) {
    Class<?> returnType;
    Type returnType1, returnType2;
    if (ModuleCall.class.equals(method1.getReturnType())) { // 异步回调的方法
        returnType = method2.getReturnType();
        if (returnType.equals(Observable.class) || returnType.equals(Single.class) || returnType.equals(Flowable.class) || returnType.equals(Maybe.class)) {

            returnType1 = method1.getGenericReturnType();
            returnType2 = method2.getGenericReturnType();

            if (returnType1 instanceof ParameterizedType && returnType2 instanceof ParameterizedType) { // 都带泛型
                // 检查泛型的类型是否一样
                if (!((ParameterizedType) returnType1).getActualTypeArguments()[0].equals(((ParameterizedType) returnType2).getActualTypeArguments()[0])) {
                    throw new IllegalArgumentException(method1.getName() + "方法的返回值类型的泛型的须一样");
                }
            } else if (!(returnType1 instanceof Class && returnType2 instanceof Class)) {
                throw new IllegalArgumentException(method1.getName() + "方法的返回值类型的泛型的须一样");
            }
        } else {
            throw new IllegalArgumentException(String.format("%s::%s的返回值类型必须是Observable,Single,Flowable,Maybe之一", method2.getDeclaringClass().getSimpleName(), method2.getName()));
        }
    } else {
        if (!method1.getGenericReturnType().equals(method2.getGenericReturnType())) { //同步调用的返回值必须一样
            throw new IllegalArgumentException(method1.getName() + "方法的返回值类型不一样");
        }
    }
}
 
开发者ID:linyongsheng,项目名称:android-arch-mvvm,代码行数:28,代码来源:ModuleManager.java

示例11: getBeanHandlerType

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 获得实体类型(从方法的返回值中获取),用于BeanHandler映射
 * @param method
 * @return
 */
private Class<?> getBeanHandlerType(Method method) {
    if (List.class.isAssignableFrom(method.getReturnType())) {
        Type type = method.getGenericReturnType();
        String typeName = type.getTypeName().replaceAll(".+<(.+)>", "$1");
        return ClassUtil.loadClass(typeName);
    }
    return method.getReturnType();
}
 
开发者ID:omsfuk,项目名称:Samurai,代码行数:14,代码来源:OrmContext.java

示例12: testToGenericType_staticMemberClass

import java.lang.reflect.Method; //导入方法依赖的package包/类
public void testToGenericType_staticMemberClass() throws Exception {
  Method getStaticAnonymousClassMethod =
      TypeTokenTest.class.getDeclaredMethod("getStaticAnonymousClass", Object.class);
  ParameterizedType javacReturnType =
      (ParameterizedType) getStaticAnonymousClassMethod.getGenericReturnType();

  ParameterizedType parameterizedType =
      (ParameterizedType) TypeToken.toGenericType(GenericClass.class).getType();
  assertThat(parameterizedType.getOwnerType()).isEqualTo(javacReturnType.getOwnerType());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:TypeTokenTest.java

示例13: getReturnTypeParameters

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * @param method {@link Method} object
 * @return the actual type parameters used in the source code. Return <strong>empty</strong> list if no parametrized type
 */
public static List<String> getReturnTypeParameters(Method method) {
    List<String> typeParameters = new ArrayList<>();

    Type type = method.getGenericReturnType();
    String typeName = type.getTypeName(); // ex: java.util.List<com.timeyang.search.entity.Person>, java.lang.Long
    Pattern p = Pattern.compile("<((\\S+\\.?),?\\s*)>");
    Matcher m = p.matcher(typeName);
    while (m.find()) {
        typeParameters.add(m.group(2));
    }

    return typeParameters;
}
 
开发者ID:chaokunyang,项目名称:jkes,代码行数:18,代码来源:ReflectionUtils.java

示例14: makeCompositeMapping

import java.lang.reflect.Method; //导入方法依赖的package包/类
private MXBeanMapping makeCompositeMapping(Class<?> c,
                                           MXBeanMappingFactory factory)
        throws OpenDataException {

    // For historical reasons GcInfo implements CompositeData but we
    // shouldn't count its CompositeData.getCompositeType() field as
    // an item in the computed CompositeType.
    final boolean gcInfoHack =
        (c.getName().equals("com.sun.management.GcInfo") &&
            c.getClassLoader() == null);

    ReflectUtil.checkPackageAccess(c);
    final List<Method> methods =
            MBeanAnalyzer.eliminateCovariantMethods(Arrays.asList(c.getMethods()));
    final SortedMap<String,Method> getterMap = newSortedMap();

    /* Select public methods that look like "T getX()" or "boolean
       isX()", where T is not void and X is not the empty
       string.  Exclude "Class getClass()" inherited from Object.  */
    for (Method method : methods) {
        final String propertyName = propertyName(method);

        if (propertyName == null)
            continue;
        if (gcInfoHack && propertyName.equals("CompositeType"))
            continue;

        Method old =
            getterMap.put(decapitalize(propertyName),
                        method);
        if (old != null) {
            final String msg =
                "Class " + c.getName() + " has method name clash: " +
                old.getName() + ", " + method.getName();
            throw new OpenDataException(msg);
        }
    }

    final int nitems = getterMap.size();

    if (nitems == 0) {
        throw new OpenDataException("Can't map " + c.getName() +
                                    " to an open data type");
    }

    final Method[] getters = new Method[nitems];
    final String[] itemNames = new String[nitems];
    final OpenType<?>[] openTypes = new OpenType<?>[nitems];
    int i = 0;
    for (Map.Entry<String,Method> entry : getterMap.entrySet()) {
        itemNames[i] = entry.getKey();
        final Method getter = entry.getValue();
        getters[i] = getter;
        final Type retType = getter.getGenericReturnType();
        openTypes[i] = factory.mappingForType(retType, factory).getOpenType();
        i++;
    }

    CompositeType compositeType =
        new CompositeType(c.getName(),
                          c.getName(),
                          itemNames, // field names
                          itemNames, // field descriptions
                          openTypes);

    return new CompositeMapping(c,
                                compositeType,
                                itemNames,
                                getters,
                                factory);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:72,代码来源:DefaultMXBeanMappingFactory.java

示例15: getGenericReturnType

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
Type getGenericReturnType(Method m) {
    return m.getGenericReturnType();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:StandardMBeanIntrospector.java


注:本文中的java.lang.reflect.Method.getGenericReturnType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。