當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。