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