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


Java Parameter类代码示例

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


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

示例1: testFirefoxOptions

import java.lang.reflect.Parameter; //导入依赖的package包/类
@ParameterizedTest
@MethodSource("testClassProvider")
@SuppressWarnings("unchecked")
void testFirefoxOptions(Class<?> testClass) throws Exception {
    Parameter parameter = testClass
            .getMethod("webrtcTest", FirefoxDriver.class)
            .getParameters()[0];
    Optional<Object> testInstance = Optional.of(testClass.newInstance());

    FirefoxOptions firefoxOptions = (FirefoxOptions) annotationsReader
            .getOptions(parameter, testInstance);
    Map<String, Map<String, Boolean>> options = (Map<String, Map<String, Boolean>>) firefoxOptions
            .asMap().get(FIREFOX_OPTIONS);

    assertTrue(options.get("prefs")
            .get("media.navigator.permission.disabled"));
    assertTrue(options.get("prefs").get("media.navigator.streams.fake"));
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:19,代码来源:FirefoxAnnotationReaderTest.java

示例2: getArgs

import java.lang.reflect.Parameter; //导入依赖的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

示例3: extractParams

import java.lang.reflect.Parameter; //导入依赖的package包/类
private static void extractParams(PrintWriter printer, Parameter[] parameters,
        StringBuilder params, StringBuilder paramsToLog) {
    for (Parameter param : parameters) {
        String sigFormatter;
        String paramFormatter;
        if (params.length() == 0) {
            sigFormatter = "\"%s\"";
            paramFormatter = "%s";
        } else {
            sigFormatter = ", \"%s\"";
            paramFormatter = ", %s";
        }
        printer.print(String.format(sigFormatter, param.getType().getName()));

        params.append(String.format(paramFormatter, param.getName()));

        if (param.getType().getName().startsWith("[")) {
            paramsToLog.append(asConcat(paramsToLog.length() == 0,
                    String.format("\"%s\"", arrayTypeName(param.getType().getName()))));
        } else {
            paramsToLog.append(asConcat(paramsToLog.length() == 0, param.getName()));
        }
    }
}
 
开发者ID:Piasy,项目名称:FridaAndroidTracer,代码行数:25,代码来源:FridaAndroidTracer.java

示例4: generateUpdaterMethod

import java.lang.reflect.Parameter; //导入依赖的package包/类
private static void generateUpdaterMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String updaterClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;

    mv = cw.visitMethod(ACC_PUBLIC, "updater", "()Lio/primeval/reflex/arguments/ArgumentsUpdater;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, updaterClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, updaterClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:27,代码来源:MethodArgumentsGenerator.java

示例5: of

import java.lang.reflect.Parameter; //导入依赖的package包/类
/**
 * Create key for single method/constructor parameter.
 *
 * @param parameter
 *          Parameter to build key for.
 * @return Created key.
 */
public static Key of(Parameter parameter) {
    Annotation[] annotations = parameter.getAnnotations();

    if (!parameter.getType().isAssignableFrom(Supplier.class)) {
        return new Key(parameter.getParameterizedType(), false,
                       parameter.getType(), findBindingAnnotation(annotations));
    }

    Type type = parameter.getParameterizedType();

    if (type instanceof ParameterizedType) {
        Type[] args = ((ParameterizedType) type).getActualTypeArguments();

        if (args.length > 0 && args[0] instanceof Class) {
            return Key.of(args[0], true, annotations);
        }
    }

    throw new InjectorException("Unable to determine parameter type for " + parameter);
}
 
开发者ID:siy,项目名称:booter-injector,代码行数:28,代码来源:Key.java

示例6: getUrl

import java.lang.reflect.Parameter; //导入依赖的package包/类
public Optional<URL> getUrl(Parameter parameter,
        Optional<Object> testInstance)
        throws MalformedURLException, IllegalAccessException {
    Optional<URL> out = empty();
    String urlValue = null;
    DriverUrl driverUrl = parameter.getAnnotation(DriverUrl.class);
    if (driverUrl != null) {
        // Search first DriverUrl annotation in parameter
        urlValue = driverUrl.value();
        out = Optional.of(new URL(urlValue));
    } else {
        // If not, search DriverUrl in any field
        Optional<Object> annotatedField = seekFieldAnnotatedWith(
                testInstance, DriverUrl.class);
        if (annotatedField.isPresent()) {
            urlValue = (String) annotatedField.get();
            out = Optional.of(new URL(urlValue));
        }
    }
    return out;
}
 
开发者ID:bonigarcia,项目名称:selenium-jupiter,代码行数:22,代码来源:AnnotationsReader.java

示例7: getRequestSchemma

import java.lang.reflect.Parameter; //导入依赖的package包/类
private static Optional<JsonSchema> getRequestSchemma(Method m, Class<?> controller) {
	List<Parameter> p = ReflectionUtils.getParametersBody(m);
	Optional<JsonSchema> schemma = Optional.empty();
	if (!p.isEmpty()) {
		Optional<Type> t = ReflectionUtils.getRealType(p.get(0).getParameterizedType(), controller);
		if (t.isPresent()) {
			Optional<Class<?>> c = ReflectionUtils.getClass(t.get());
			if (c.isPresent()) {
				schemma = getSchemma(c.get());
			} else {
				schemma = getSchemma(t.getClass());
			}
		} else {
			schemma = getSchemma(ReflectionUtils.getClass(p.get(0).getParameterizedType()));
		}
	}
	return schemma;
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:19,代码来源:JsonSchemmaUtils.java

示例8: handleValidation

import java.lang.reflect.Parameter; //导入依赖的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

示例9: formatBeanEndpointRoute

import java.lang.reflect.Parameter; //导入依赖的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

示例10: methodToString

import java.lang.reflect.Parameter; //导入依赖的package包/类
private String methodToString(Method method) {
	String s = method.getName();
	Parameter[] parameters = method.getParameters();
	if (parameters.length == 0) {
		return s + "()";
	}
	s += "(";
	for (int i = 0; i < parameters.length; i++) {
		s += "?";
		if (i < parameters.length - 1) {
			s += ",";
		}
	}
	s += ")";
	return s;
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:17,代码来源:EventHandlerPane.java

示例11: loadParameterWithMethod

import java.lang.reflect.Parameter; //导入依赖的package包/类
/**
 * 方法的参数加载对象 可优化:Parameter包含类型和名称
 * 
 * @param parameterTypes
 * @param parameters
 * @return
 */
private Object[] loadParameterWithMethod(Class[] parameterTypes, Parameter[] parameters) {
	Object[] paramObjs = new Object[parameterCount];

	// 厉害了,我的哥。
	// 今天找了一整天,JDK/ASM都不行,Paranamer稳!
	Paranamer paranamer = new BytecodeReadingParanamer();
	String[] parametersName = paranamer.lookupParameterNames(invokeMethod);

	int i = Constants.NUMBER.ZERO;
	for (Class<?> type : parameterTypes) {
		if (RequestContext.getInstance().isInContextObjs(type)) {
			paramObjs[i] = RequestContext.getInstance().searchObjByType(type);
		} else {
			TypeParser parser = TypeParser.newBuilder().build();
			Object searchedObject = RequestContext.getInstance().searchObjByName(parametersName[i]);
			paramObjs[i] = parser.parseType(searchedObject.toString(), type);
		}
		i++;
	}
	// 通过类型加载
	// searchAndBindByType(paramObjs, parameterTypes);
	// TODO 通过参数名加载
	return paramObjs;
}
 
开发者ID:Yoio,项目名称:X4J,代码行数:32,代码来源:CommonInvoke.java

示例12: checkViewOnShowOrLeaveMethod

import java.lang.reflect.Parameter; //导入依赖的package包/类
/**
 * Check given method has a valid signature for {@link OnShow} or {@link OnLeave} view method
 * @param viewClass View class
 * @param method Method to check
 * @param message Error message annotation description
 * @throws ViewConfigurationException Method is not valid
 */
private static void checkViewOnShowOrLeaveMethod(Class<?> viewClass, Method method, String message)
		throws ViewConfigurationException {
	if (method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE) {
		throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
				+ ": method must be a void return method");
	}
	int params = method.getParameterCount();
	if (params > 1) {
		throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
				+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
	}
	if (params == 1) {
		Parameter param = method.getParameters()[0];
		if (param.isVarArgs() || !(ViewChangeEvent.class.isAssignableFrom(param.getType())
				|| ViewNavigatorChangeEvent.class.isAssignableFrom(param.getType()))) {
			throw new ViewConfigurationException(
					"Invalid " + message + " method in view class " + viewClass.getName()
							+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:29,代码来源:ViewNavigationUtils.java

示例13: getArguments

import java.lang.reflect.Parameter; //导入依赖的package包/类
protected Object[] getArguments(Step step, StepImplementation implementation) {
	Method method = implementation.getMethod();
	Parameter[] parameters = method.getParameters();
	Object[] arguments = new Object[parameters.length];

	if (parameters.length > 0) {
		String text = step.getText();
		Pattern pattern = implementation.getPattern();
		Matcher matcher = pattern.matcher(text);
		checkState(matcher.find(),
			"unable to locate substitution parameters for pattern %s with input %s", pattern.pattern(), text);

		int groupCount = matcher.groupCount();
		ConversionService conversionService = SpringPreProcessor.getBean(ConversionService.class);
		for (int i = 0; i < groupCount; i++) {
			String parameterAsString = matcher.group(i + 1);
			Parameter parameter = parameters[i];
			Class<?> parameterType = parameter.getType();

			Object converted = conversionService.convert(parameterAsString, parameterType);
			arguments[i] = converted;
		}
	}
	return arguments;
}
 
开发者ID:qas-guru,项目名称:martini-jmeter-extension,代码行数:26,代码来源:MartiniSamplerClient.java

示例14: pathCompiler

import java.lang.reflect.Parameter; //导入依赖的package包/类
public static Pattern pathCompiler(String path, Method method) {
    Parameter[] parameters = method.getParameters();
    for (Parameter parameter : parameters) {
        if (parameter.getAnnotations().length == 0) {
            continue;
        }
        Annotation annotation = parameter.getAnnotations()[0];
        if (annotation instanceof PathVariable) {
            //如果是字符串
            if (parameter.getType() == String.class) {
                path = path.replace("{" + parameter.getName() + "}", "[0-9\\d\\D]*");
            }
            //如果是数字
            else if (parameter.getType() == Integer.class
                    || parameter.getType() == Long.class) {
                path = path.replace("{" + parameter.getName() + "}", "[0-9]*");
            }

        }
    }
    return Pattern.compile(path);
}
 
开发者ID:zhyzhyzhy,项目名称:Ink,代码行数:23,代码来源:RouteFinder.java

示例15: passAnnotations

import java.lang.reflect.Parameter; //导入依赖的package包/类
@Test
public void passAnnotations() throws Exception {
  check(ImmutableValForPass.class.getAnnotation(A1.class)).notNull();
  check(ImmutableValForPass.class.getAnnotation(A2.class)).notNull();
  check(ImmutableValForPass.class.getAnnotation(B1.class)).isNull();
  Parameter parameter = ImmutableValForPass.class.getConstructor(int.class).getParameters()[0];
  check(parameter.getAnnotation(A1.class)).notNull();
  check(parameter.getAnnotation(A2.class)).notNull();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:PassAnnotationTest.java


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