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


Java Method.getGenericParameterTypes方法代码示例

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


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

示例1: invokeFunction

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static <T> Function<Data<T>, Object> invokeFunction(Method method, Object target, Class<T> dataType) {
    Type[] parameters = method.getGenericParameterTypes();
    if (parameters.length != 1) {
        throw new IllegalArgumentException(
                String.format("Upcaster method '%s' has unexpected number of parameters. Expected 1 or 0.", method));
    }
    if (parameters[0] instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) parameters[0];
        if (parameterizedType.getRawType().equals(Data.class) && dataType
                .isAssignableFrom((Class<?>) parameterizedType.getActualTypeArguments()[0])) {
            return data -> invokeMethod(method, data, target);
        }
        if (dataType.isAssignableFrom((Class<?>) parameterizedType.getRawType())) {
            return data -> invokeMethod(method, data.getValue(), target);
        }
    } else if (dataType.isAssignableFrom((Class<?>) parameters[0])) {
        return data -> invokeMethod(method, data.getValue(), target);
    }
    throw new IllegalArgumentException(String.format(
            "First parameter in upcaster method '%s' is of unexpected type. Expected Data<%s> or %s.",
            method, dataType.getName(), dataType.getName()));
}
 
开发者ID:flux-capacitor-io,项目名称:flux-capacitor-client,代码行数:23,代码来源:UpcastInspector.java

示例2: registerMethodParameterTypes

import java.lang.reflect.Method; //导入方法依赖的package包/类
public boolean registerMethodParameterTypes(String service, Class<?> clazz) {

		Method[] methods = clazz.getMethods();

		for (Method method : methods) {
			Class<?> declaredClazz = method.getDeclaringClass();
			if (declaredClazz == Object.class) {
				continue;
			}

			Type[] parameterTypes = method.getGenericParameterTypes();
			String key = service + "/" + method.getName() + "/" + parameterTypes.length;
			this.serviceMethodParameterTypesCache.put(key, new ServiceMethodDesc(key, parameterTypes));

			String defaultKey = service + "/" + method.getName() + "/";
			this.serviceMethodParameterTypesCache.put(defaultKey, new ServiceMethodDesc(key, parameterTypes));
		}

		return false;

	}
 
开发者ID:sylinklee,项目名称:netto_rpc,代码行数:22,代码来源:ArgsDeserializer.java

示例3: getActualTypeArguments

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 查找泛型类型
 *
 * @param m
 * @return
 */
protected Type getActualTypeArguments(Method m) {
    Type[] genericParameterTypes = m.getGenericParameterTypes();
    for (Type type : genericParameterTypes) {
        Type[] actualTypeArguments = ReflectionUtils.getActualTypeArguments(type);
        if (null == actualTypeArguments || actualTypeArguments.length == 0)
            return null;
        //Map 取value的泛型
        if (actualTypeArguments.length > 1) {
            return actualTypeArguments[1];
            //Collection 取泛型
        } else {
            return actualTypeArguments[0];
        }
    }
    return null;
}
 
开发者ID:lovejj1994,项目名称:Simplify-Core,代码行数:23,代码来源:AbstractJson.java

示例4: getParamProviders

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Returns the param providers for a resource method.
 *
 * This is very similar to the logic used in building param providers for a normal
 * <code>@Inject</code> constructor, with one major difference.
 *
 * A resource method is allowed one special "entity" parameter representing the content body.
 * This entity parameter is handled by a <code>EntityProvider</code>.
 *
 * @param method The resource method.
 * @return The array of resource method param providers.
 */
private Provider<?>[] getParamProviders(final Method method) {
    final Class<?>[] paramClasses = method.getParameterTypes();
    final Type[] paramTypes = method.getGenericParameterTypes();
    final Annotation[][] annotations = method.getParameterAnnotations();
    final Provider<?>[] result = new Provider<?>[paramTypes.length];

    final Consumes consumes = method.getAnnotation(Consumes.class);
    final List<MediaType> consumesTypes = MediaTypeUtils.parseMediaTypes(consumes);
    boolean consumed = false;

    for (int i = 0; i < paramTypes.length; i++) {
        if (annotations[i].length == 0 && !consumed) {
            result[i] = new EntityProvider<>(paramClasses[i], paramTypes[i], annotations[i], consumesTypes);
            consumed = true;
        } else {
            result[i] = getInjector().getProvider(paramClasses[i], annotations[i]);
        }
    }
    return result;
}
 
开发者ID:minijax,项目名称:minijax,代码行数:33,代码来源:MinijaxApplication.java

示例5: testInterface

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Test
public void testInterface() throws Exception {
  ClassConfig classConfig = new ClassConfig();
  classConfig.setIntf(true);
  String intfName = "cse.ut.TestInterface";
  classConfig.setClassName(intfName);

  String source = "java.util.List method(java.util.Map map, java.util.Set set);";
  String genericSignature =
      "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;Ljava/util/Set<Ljava/lang/String;>;)Ljava/util/List<Ljava/lang/String;>;";
  classConfig.addMethod(source, genericSignature);

  Class<?> intf = JavassistUtils.createClass(classConfig);

  Assert.assertEquals(intfName, intf.getName());
  Method method = ReflectUtils.findMethod(intf, "method");
  Assert.assertEquals("method", method.getName());
  Assert.assertEquals("java.util.List<java.lang.String>", method.getGenericReturnType().getTypeName());

  Type[] types = method.getGenericParameterTypes();
  Assert.assertEquals("java.util.Map<java.lang.String, java.lang.String>", types[0].getTypeName());
  Assert.assertEquals("java.util.Set<java.lang.String>", types[1].getTypeName());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:24,代码来源:TestJavassistUtils.java

示例6: getMethodGenericParameterTypes

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static List<Class<?>> getMethodGenericParameterTypes(Method method) {
	List<Class<?>> results = new ArrayList<Class<?>>();
	Type[] genericParameterTypes = method.getGenericParameterTypes();
	for (Type genericParameterType : genericParameterTypes) {
		if (genericParameterType instanceof ParameterizedType) {
			ParameterizedType aType = (ParameterizedType) genericParameterType;
			Type[] parameterArgTypes = aType.getActualTypeArguments();
			for (Type parameterArgType : parameterArgTypes) {
				Class<?> parameterArgClass = (Class<?>) parameterArgType;
				results.add(parameterArgClass);
			}
			return results;
		}
	}
	return results;
}
 
开发者ID:funtl,项目名称:framework,代码行数:17,代码来源:CommonUtils.java

示例7: isEventHandler

import java.lang.reflect.Method; //导入方法依赖的package包/类
private boolean isEventHandler(Method m) {
    // We assume that a method is an event handler if it has a single
    // argument, whose type inherit from java.util.Event.
    Type argTypes[] = m.getGenericParameterTypes();
    if (argTypes.length != 1) {
        return false;
    }
    return isSubclass(TypeResolver.erase(TypeResolver.resolveInClass(beanClass, argTypes[0])), EventObject.class);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:Introspector.java

示例8: ConvertingMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private ConvertingMethod(Method m) throws OpenDataException {
    this.method = m;
    MXBeanMappingFactory mappingFactory = MXBeanMappingFactory.DEFAULT;
    returnMapping =
            mappingFactory.mappingForType(m.getGenericReturnType(), mappingFactory);
    Type[] params = m.getGenericParameterTypes();
    paramMappings = new MXBeanMapping[params.length];
    boolean identity = true;
    for (int i = 0; i < params.length; i++) {
        paramMappings[i] = mappingFactory.mappingForType(params[i], mappingFactory);
        identity &= DefaultMXBeanMappingFactory.isIdentity(paramMappings[i]);
    }
    paramConversionIsIdentity = identity;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ConvertingMethod.java

示例9: create

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static <R, T> RuleSourceBackedRuleAction<R, T> create(ModelType<T> subjectType, R ruleSourceInstance) {
    ModelType<R> ruleSourceType = ModelType.typeOf(ruleSourceInstance);
    List<Method> mutateMethods = JavaReflectionUtil.findAllMethods(ruleSourceType.getConcreteClass(), new Spec<Method>() {
        public boolean isSatisfiedBy(Method element) {
            return element.isAnnotationPresent(Mutate.class);
        }
    });
    FormattingValidationProblemCollector problemsFormatter = new FormattingValidationProblemCollector("rule source", ruleSourceType);
    RuleSourceValidationProblemCollector problems = new DefaultRuleSourceValidationProblemCollector(problemsFormatter);

    if (mutateMethods.size() == 0) {
        problems.add("Must have at exactly one method annotated with @" + Mutate.class.getName());
    } else {
        if (mutateMethods.size() > 1) {
            problems.add("More than one method is annotated with @" + Mutate.class.getName());
        }

        for (Method ruleMethod : mutateMethods) {
            if (ruleMethod.getReturnType() != Void.TYPE) {
                problems.add(ruleMethod, "A rule method must return void");
            }
            Type[] parameterTypes = ruleMethod.getGenericParameterTypes();
            if (parameterTypes.length == 0 || !subjectType.isAssignableFrom(ModelType.of(parameterTypes[0]))) {
                problems.add(ruleMethod, String.format("First parameter of a rule method must be of type %s", subjectType));
            }
        }
    }

    if (problemsFormatter.hasProblems()) {
        throw new RuleActionValidationException(problemsFormatter.format());
    }

    return new RuleSourceBackedRuleAction<R, T>(ruleSourceInstance, new JavaMethod<R, T>(subjectType.getConcreteClass(), mutateMethods.get(0)));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:35,代码来源:RuleSourceBackedRuleAction.java

示例10: Builder

import java.lang.reflect.Method; //导入方法依赖的package包/类
Builder(Retrofit retrofit, Method method) {
  this.retrofit = retrofit;
  this.method = method;
  this.methodAnnotations = method.getAnnotations();
  this.parameterTypes = method.getGenericParameterTypes();
  this.parameterAnnotationsArray = method.getParameterAnnotations();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:ServiceMethod.java

示例11: generateByNewInstance

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * this method generate record instance by calling newIntance
 * using reflection, add register the generated value to typeValueCache
 */
@SuppressWarnings("rawtypes")
private static Object generateByNewInstance(Class clazz) throws Exception {
  Object ret = typeValueCache.get(clazz);
  if (ret != null) {
    return ret;
  }
  Method newInstance = null;
  Type [] paramTypes = new Type[0];
  // get newInstance method with most parameters
  for (Method m : clazz.getMethods()) {
    int mod = m.getModifiers();
    if (m.getDeclaringClass().equals(clazz) &&
        Modifier.isPublic(mod) &&
        Modifier.isStatic(mod) &&
        m.getName().equals("newInstance")) {
      Type [] pts = m.getGenericParameterTypes();
      if (newInstance == null
          || (pts.length > paramTypes.length)) {
        newInstance = m;
        paramTypes = pts;
      }
    }
  }
  if (newInstance == null) {
    throw new IllegalArgumentException("type " + clazz.getName() +
        " does not have newInstance method");
  }
  Object [] args = new Object[paramTypes.length];
  for (int i=0;i<args.length;i++) {
    args[i] = genTypeValue(paramTypes[i]);
  }
  ret = newInstance.invoke(null, args);
  typeValueCache.put(clazz, ret);
  return ret;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:TestPBImplRecords.java

示例12: getReturnClassImports

import java.lang.reflect.Method; //导入方法依赖的package包/类
private String getReturnClassImports(
                                      Class<?> actionClass ) {

    Method[] actionClassMethods = actionClass.getDeclaredMethods();
    //using TreeSet to prevent duplication of imports and have sorted list
    Set<String> imports = new TreeSet<String>();
    for (Method m : actionClassMethods) {
        if (ActionClassGenerator.isAnActionClass(m)) {

            // import method return type if needed
            Class<?> returnType = m.getReturnType();
            //check if the return type is an array
            if (returnType.getComponentType() != null) {
                returnType = returnType.getComponentType();
            }
            if (needsToImportMethodReturnType(returnType)) {
                addImport(imports, returnType, m.getGenericReturnType());
            }

            // import method parameter types if needed
            Class<?> methodParameterTypes[] = m.getParameterTypes();
            Type methodGenericParameterTypes[] = m.getGenericParameterTypes();
            for (int i = 0; i < methodParameterTypes.length; i++) {
                Class<?> methodParameterType = methodParameterTypes[i];
                if (needsToImportMethodParameterType(methodParameterType)) {
                    addImport(imports, methodParameterType, methodGenericParameterTypes[i]);
                }
            }
        }
    }
    if (imports.size() > 0) {
        StringBuilder sb = new StringBuilder();
        for (String s : imports) {
            sb.append(s);
        }
        return sb.toString();
    } else {
        return "";
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:41,代码来源:ClassTemplateProcessor.java

示例13: getGenerics

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * 获取方法某个入参参数上的某个位置的范型Class原型
 * 
 * @param i_Method
 * @param i_ParamIndex      方法的入参参数位置
 * @param i_GenericsIndex   入参参数范型的位置
 * @return
 */
public static Class<?> getGenerics(Method i_Method ,int i_ParamIndex ,int i_GenericsIndex)
{
    try
    {
        ParameterizedType v_PType = (ParameterizedType) i_Method.getGenericParameterTypes()[i_ParamIndex];
        Type              v_Type  = v_PType.getActualTypeArguments()[i_GenericsIndex];
        return (Class<?>)v_Type;
    }
    catch (Exception exce)
    {
        return null;
    }
}
 
开发者ID:HY-ZhengWei,项目名称:hy.common.base,代码行数:22,代码来源:MethodReflect.java

示例14: of

import java.lang.reflect.Method; //导入方法依赖的package包/类
@NonNull
static ArgumentParser of(@NonNull final Binder binder, @NonNull final Method method) {
  final Annotation[][] annotations = method.getParameterAnnotations();
  final Type[] types = method.getGenericParameterTypes();

  final Argument[] arguments = new Argument[types.length];
  for(int i = 0; i < types.length; i++) {
    arguments[i] = createArgument(binder, types[i], Arrays.asList(annotations[i]));
  }

  return new ArgumentParser(arguments);
}
 
开发者ID:KyoriPowered,项目名称:ghost,代码行数:13,代码来源:ArgumentParser.java

示例15: 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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:Introspector.java


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