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


Java Method.getParameters方法代码示例

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


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

示例1: getArgs

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static Object[] getArgs(Signature signature) throws Exception {
	Method actionMethod = signature.getAction();
	Request request = signature.request();
	actionMethod.setAccessible(true);

	Parameter[] parameters = actionMethod.getParameters();
	Object[] args = new Object[parameters.length];
	String[] parameterNames = AsmKit.getMethodParamNames(actionMethod);

	for (int i = 0, len = parameters.length; i < len; i++) {
		Parameter parameter = parameters[i];
		String paramName = parameterNames[i];
		Class<?> argType = parameter.getType();
		if (containsAnnotation(parameter)) {
			args[i] = getAnnotationParam(parameter, paramName, request);
			continue;
		}
		if (ReflectKit.isPrimitive(argType)) {
			args[i] = request.query(paramName);
			continue;
		}
		args[i] = getCustomType(parameter, signature);
	}
	return args;
}
 
开发者ID:wujiangchao,项目名称:chopsticks,代码行数:26,代码来源:MethodArgument.java

示例2: prepareQuery

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void prepareQuery(JdbcQueryMethod method) {
    try {
        Method m = (Method) originalMethod.get(method);
        if (!m.isAnnotationPresent(Query.class)) {
            throw new IllegalStateException("Query annotation not present");
        }
        this.query = m.getAnnotation(Query.class).value();

        parameterKeys = new ArrayList<>(m.getParameterCount());
        for (Parameter parameter : m.getParameters()) {
            if (parameter.isAnnotationPresent(Param.class)) {
                parameterKeys.add(parameter.getAnnotation(Param.class).value());
            } else {
                parameterKeys.add(null);
            }
        }
    } catch (IllegalArgumentException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:21,代码来源:JdbcAnnotatedRepositoryQueryCreator.java

示例3: handleValidation

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
protected void handleValidation(final Message message, final Object resourceInstance, final Method method,
		final List<Object> arguments) {
	super.handleValidation(message, resourceInstance, method, arguments);

	// Check each parameter
	final Set<ConstraintViolation<?>> validationErrors = new HashSet<>();
	for (int index = 0; index < arguments.size(); index++) {
		final Parameter parameter = method.getParameters()[index];
		if (hasToBeValidated(parameter)) {
			// This parameter is a not context, path or query parameter
			validate(arguments.get(index), method, parameter, index, validationErrors);
		}
	}

	// Check the veto
	if (!validationErrors.isEmpty()) {
		message.put(FaultListener.class.getName(), new NoOpFaultListener());
		throw new ConstraintViolationException(validationErrors);
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:JAXRSBeanValidationImplicitInInterceptor.java

示例4: invoke

import java.lang.reflect.Method; //导入方法依赖的package包/类
private void invoke(Object mediator, Method method) {
  method = ReflectionHelper.makeAccessibleIfNot(method);

  List<Object> values = new ArrayList<>();
  for (Parameter param : method.getParameters()) {
    Port port = param.getAnnotation(Port.class);
    if (port != null) {
      String name = port.value();
      if (param.getType().isAssignableFrom(Sink.class)) {
        values.add(getSinkOrFail(name));
      } else if (param.getType().isAssignableFrom(Source.class)) {
        values.add(getSourceOrFail(name));
      }
    } else {
      throw new IllegalArgumentException("Invalid parameter - one parameter of " + method.getName()
        + " is not annotated with @Port");
    }
  }

  try {
    method.invoke(mediator, values.toArray());
  } catch (Exception e) {
    throw new IllegalStateException("Unable to invoke " + method.getName() + " from " + mediator.getClass()
      .getName(), e);
  }
}
 
开发者ID:cescoffier,项目名称:fluid,代码行数:27,代码来源:Fluid.java

示例5: testGetGenericType

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Test
public void testGetGenericType() throws Exception {
	Field genericInterfaceField = ClassWrapper.wrap(Foo.class).getField("genericInterface");

	assertEquals(Integer.class, getGenericType(genericInterfaceField, GenericInterface.class, 0));

	ClassWrapper<Foo> classWrapper = ClassWrapper.wrap(Foo.class);
	Field subGenericInterfaceField = classWrapper.getField("subGenericInterface");
	assertEquals(Long.class, getGenericType(subGenericInterfaceField, GenericInterface.class, 0));

	assertEquals(Long.class, getGenericType(Bar.class, GenericInterface.class, 0));

	assertEquals(Boolean.class, getGenericType(Bar.class, GenericClass.class, 0));

	Method method = classWrapper.getCompatibleMethodWithTypes("getBar", SubGenericInterface.class);
	assertEquals(Long.class, getGenericReturnType(method, GenericInterface.class, 0));

	Parameter parameter = method.getParameters()[0];
	assertEquals(Long.class, getGenericType(parameter, GenericInterface.class, 0));
}
 
开发者ID:InfinityRefactoring,项目名称:8R-Reflections,代码行数:21,代码来源:ClassWrapperTest.java

示例6: formatBeanEndpointRoute

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static String formatBeanEndpointRoute(Method m) {
    String answer = m.getName();

    Parameter[] params = m.getParameters();
    java.util.List<String> paramList = new ArrayList<>();

    if (params.length > 0) {

        paramList.add("${body}");
        for (int i = 1; i < params.length; i++) {
            paramList.add("${header.param" + i + "}");
        }
    }

    answer = answer + "(" + String.join(",", paramList) + ")";

    return answer;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:19,代码来源:RouteBuilders.java

示例7: buildLepMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private LepMethod buildLepMethod(Class<?> targetType, Object target, Method method, Object[] args) {
    DefaultMethodSignature signature = new DefaultMethodSignature();
    signature.setName(method.getName());
    signature.setModifiers(method.getModifiers());
    signature.setDeclaringClass(targetType);
    signature.setParameterTypes(method.getParameterTypes());
    signature.setExceptionTypes(method.getExceptionTypes());
    signature.setReturnType(method.getReturnType());
    signature.setMethod(method);

    Parameter[] parameters = method.getParameters();
    String[] parameterNames;
    if (parameters == null) {
        parameterNames = new String[0];
    } else {
        parameterNames = new String[parameters.length];
        for (int i = 0; i < parameters.length; i++) {
            Parameter p = parameters[i];
            // p.isNamePresent()
            parameterNames[i] = p.getName();
        }
    }
    signature.setParameterNames(parameterNames);

    return new DefaultLepMethod(target, signature, args);
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:27,代码来源:LepServiceHandler.java

示例8: recordAPIMethod

import java.lang.reflect.Method; //导入方法依赖的package包/类
private APIMethod recordAPIMethod(Method method) {
    if (method == null || !method.isAnnotationPresent(API.class)) {
        return null;
    }
    APIMethod m = new APIMethod(method.getName());
    if (method.getParameterCount() > 0) {
        Parameter[] parameters = method.getParameters();
        for (Parameter parameter : parameters) {
            String defaultValue = determineParameterDefaultValue(parameter);
            determineContentType(parameter);
            APIMethodArgument arg = new APIMethodArgument(parameter.getName(), parameter.getType(),
                    determineContentType(parameter), defaultValue);
            m.addArgument(arg);
        }
    }
    APIMethodArgument returnArg = new APIMethodArgument(method.getReturnType(), null);
    m.setReturnArgument(returnArg);
    return m;
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:20,代码来源:APIMappingGenerator.java

示例9: describeAlgorithm

import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public List<String> describeAlgorithm(String name) throws TException {
	List<String> ret = new ArrayList<>();
	Class<?> clazz = map.get(name);
	if(clazz == null){
		throw new RuntimeException("No such algorithm!");
	}
	for (final Method method : clazz.getDeclaredMethods()){
		final Algorithm my= method.getAnnotation(Algorithm.class); 
		if ((null != my) && my.name().equals(name)){
			ret.add("Algorithm Name:" + name);
			ret.add("Return Type:" + method.getReturnType().toString());
			for(Parameter param : method.getParameters()){
				ret.add(param.toString());
			}
		}
	}
	return ret;
}
 
开发者ID:kaichao,项目名称:algorithm.annotation,代码行数:20,代码来源:AlgorithmServiceImpl.java

示例10: getSetter

import java.lang.reflect.Method; //导入方法依赖的package包/类
private Method getSetter(final String fieldName) {
  for (final Method method : this.getClass().getMethods()) {
    // method must start with "set" and have only one parameter, mathich the
    // specified fieldType
    if (method.getName().equalsIgnoreCase("set" + fieldName) && method.getParameters().length == 1) {
      if (!method.isAccessible()) {
        method.setAccessible(true);
      }

      return method;
    }
  }

  return null;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:16,代码来源:ConfigurationGroup.java

示例11: isMultipartBody

import java.lang.reflect.Method; //导入方法依赖的package包/类
private static boolean isMultipartBody(Method method) {

        if (method.getParameters().length > 0) {
            Class type = method.getParameters()[0].getType();
            if (type.isAssignableFrom(InputStream.class)) {
                return true;
            }
        }
        return false;
    }
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:11,代码来源:RestHelper.java

示例12: main

import java.lang.reflect.Method; //导入方法依赖的package包/类
public static void main(String[] args) {
	Class<Java8MethodParameters> clazz = Java8MethodParameters.class;
	Method[] methods = clazz.getDeclaredMethods();
	for (Method method : methods) {
		System.out.println(method.getName());
		for (Parameter parameter : method.getParameters()) {
			System.out.println(parameter.getName());
		}
	}
}
 
开发者ID:gauravrmazra,项目名称:gauravbytes,代码行数:11,代码来源:Java8MethodParameters.java

示例13: getCommandAnnotation

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Parse Class Anotation to Method
 * @param clazz Class
 * @return A Collection of Annotation and Methods
 */
public static HashMap<Command, Method> getCommandAnnotation(Class clazz, Module instance){
    HashMap<Command, Method> allannotation = new HashMap<>();
    Console.debug("----------------Module: "+clazz.getName()+"----------------");
    try {
            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                Command annotation = method.getAnnotation(Command.class);
                LanguageMethod language = method.getAnnotation(LanguageMethod.class);
                if (annotation != null) {
                    if (method.getParameters().length == 2) {
                        if (method.getParameters()[0].getParameterizedType().equals(MessageReceivedEvent.class) && method.getParameters()[1].getParameterizedType().equals(String[].class)) {
                            Console.debug("Command: " + annotation.prefix()+annotation.command()+" in "+method.getName());
                            allannotation.put(annotation, method);
                            PERM.addPermission(annotation);
                        } else {
                            Console.error("Method has no valid Parameters: "+method.getName());
                        }
                    } else {
                        Console.error("Method has no valid Parameters Count: "+method.getName());
                    }
                } else if (language != null) {
                    Console.debug("Language: " + language.languagestringcount()+" in "+method.getName()+"   "+clazz.getName()+"   "+instance.getClass().getName());
                    COMMAND.languages.put(language, method);
                    COMMAND.langinstances.put(language, instance);
                }
            }
    } catch (Exception ex) {
        Console.error(String.format(LANG.getTranslation("annotation_error"), clazz.getName(), ex.getMessage()));
        Console.error(ex);
    }
    return allannotation;
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:38,代码来源:GetAnnotation.java

示例14: findResourceMethods

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Find all handler mehtods of the resource.
 *
 * @param resourceInstance The instance.
 */
private void findResourceMethods(Object resourceInstance) {
	for (Method declaredMethod : resourceInstance.getClass().getDeclaredMethods()) {
		Path methodPath = declaredMethod.getAnnotation(Path.class);
		
		if (methodPath == null) {
			continue;
		}
		
		Consumes consumes = declaredMethod.getAnnotation(Consumes.class);
		Produces produces = declaredMethod.getAnnotation(Produces.class);
		
		HTTPMethod method = HTTPMethod.GET;
		
		if (declaredMethod.isAnnotationPresent(POST.class)) {
			method = HTTPMethod.POST;
		} else if (declaredMethod.isAnnotationPresent(DELETE.class)) {
			method = HTTPMethod.DELETE;
		} else if (declaredMethod.isAnnotationPresent(PUT.class)) {
			method = HTTPMethod.PUT;
		} else if (declaredMethod.isAnnotationPresent(PATCH.class)) {
			method = HTTPMethod.PATCH;
		}
		
		ResourceMethod resourceMethod = new ResourceMethod(methodPath.value(), method,
			consumes.value(), produces.value(), declaredMethod, resourceInstance);
		
		for (Parameter parameter : declaredMethod.getParameters()) {
			if (parameter.isAnnotationPresent(PostKey.class)) {
				resourceMethod.addPostParam(parameter.getAnnotation(PostKey.class).value());
			}
		}
		
		this.resourceMethods.put(methodPath.value(), resourceMethod);
	}
}
 
开发者ID:D3adspaceEnterprises,项目名称:echidna,代码行数:41,代码来源:Resource.java

示例15: processAnnotationsOnParams

import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
 * Process annotations on params.
 *
 * @param requestTemplate the request template
 * @param method          the method
 */
protected void processAnnotationsOnParams(RestyRequestTemplate requestTemplate, Method method) {
    for (int i = 0; i < method.getParameters().length; i++) {
        Parameter parameter = method.getParameters()[i];
        // 处理PathVariable
        PathVariable pathVariable = findMergedAnnotation(parameter, PathVariable.class);
        if (pathVariable != null) {
            PathVariableData pathVariableData = new PathVariableData();
            pathVariableData.setIndex(i);
            pathVariableData.setName("{" + (StringUtils.isNotEmpty(pathVariable.name()) ? pathVariable.name() : parameter.getName()) + "}");
            pathVariableData.setRequired(pathVariable.required());
            requestTemplate.addPathVariable(pathVariableData);
            continue;
        }
        // 处理RequestParam
        RequestParam requestParam = findMergedAnnotation(parameter, RequestParam.class);
        if (requestParam != null) {
            RequestParamData requestParamData = new RequestParamData();
            requestParamData.setIndex(i);
            requestParamData.setName(StringUtils.isNotEmpty(requestParam.name()) ? requestParam.name() : parameter.getName());
            requestParamData.setRequired(requestParam.required());
            requestParamData.setDefaultValue(resolveDefaultValue(requestParam.defaultValue()));
            requestTemplate.addRequestParam(requestParamData);
            continue;
        }

        RequestHeader requestHeader = findMergedAnnotation(parameter, RequestHeader.class);
        if (requestHeader != null) {
            RequestHeaderData requestHeaderData = new RequestHeaderData();
            requestHeaderData.setIndex(i);
            requestHeaderData.setName(StringUtils.isNotEmpty(requestHeader.name()) ? requestHeader.name() : parameter.getName());
            requestHeaderData.setRequired(requestHeader.required());
            requestHeaderData.setDefaultValue(resolveDefaultValue(requestHeader.defaultValue()));
            requestTemplate.addRequestHeader(requestHeaderData);
            continue;
        }

        // 处理RequestBody和无注解参数
        RequestBody requestBody = findMergedAnnotation(parameter, RequestBody.class);
        if ((requestBody != null || parameter.getAnnotations().length == 0)
                && parameter.getType() != RestyFuture.class) {
            RequestBodyData requestBodyData = new RequestBodyData();
            requestBodyData.setIndex(i);
            requestBodyData.setName(parameter.getName());
            requestBodyData.setDefaultValue(null);
            if (requestBody != null) {
                requestBodyData.setRequired(requestBody.required());
            } else {
                requestBodyData.setRequired(false);
            }
            requestTemplate.addRequestBody(requestBodyData);
        }
    }
}
 
开发者ID:darren-fu,项目名称:RestyPass,代码行数:60,代码来源:SpringAnnotationWrapper.java


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