本文整理汇总了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"));
}
示例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;
}
示例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()));
}
}
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
}
}
示例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;
}
示例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);
}
示例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();
}