本文整理汇总了Java中java.lang.reflect.Parameter.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.getType方法的具体用法?Java Parameter.getType怎么用?Java Parameter.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Parameter
的用法示例。
在下文中一共展示了Parameter.getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: recordAPIMethod
import java.lang.reflect.Parameter; //导入方法依赖的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;
}
示例4: 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);
}
示例5: generateToStringMethod
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private static void generateToStringMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
Parameter[] parameters) {
MethodVisitor mv;
mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitLdcInsn(Type.getType(selfClassDescriptor));
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
mv.visitLdcInsn(" [");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
for (int i = 0; i < parameters.length; i++) {
Parameter param = parameters[i];
mv.visitLdcInsn(param.getName() + "=");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
false);
mv.visitVarInsn(ALOAD, 0); // this
mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), Type.getDescriptor(param.getType()));
Class<?> paramType = param.getType();
if (paramType.isPrimitive()) {
// special case with StringBuilder, no specific method we default to append(int)
if (paramType == short.class || paramType == byte.class) {
paramType = int.class;
}
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
Type.getMethodDescriptor(Type.getType(StringBuilder.class), Type.getType(paramType)), false);
} else {
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
"(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
}
if (i + 1 < parameters.length) {
mv.visitLdcInsn(", ");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
false);
}
}
mv.visitLdcInsn("]");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", 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();
}
示例6: getMock
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private Object getMock(Parameter parameter, ExtensionContext extensionContext) {
Class<?> mockType = parameter.getType();
Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType));
String mockName = getMockName(parameter);
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
}
else {
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
}
}
示例7: getMock
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private Object getMock(Parameter parameter,
ExtensionContext extensionContext) {
Class<?> mockType = parameter.getType();
Store mocks = extensionContext
.getStore(Namespace.create(MockitoExtension.class, mockType));
String mockName = getMockName(parameter);
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName,
key -> mock(mockType, mockName));
} else {
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(),
key -> mock(mockType));
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Software-Testing-with-JUnit-5,代码行数:16,代码来源:MockitoExtension.java
示例8: getMock
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private Object getMock(Parameter parameter, ExtensionContext extensionContext) {
Class<?> mockType = parameter.getType();
Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType));
String mockName = getMockName(parameter);
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
} else {
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
}
}
示例9: getMock
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private Object getMock(Parameter parameter, ExtensionContext extensionContext) {
Class<?> mockType = parameter.getType();
Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType));
String mockName = getMockName(parameter);
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
}
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
}
示例10: getMock
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
private Object getMock(Parameter parameter, ExtensionContext extensionContext) {
Class<?> mockType = parameter.getType();
ExtensionContext.Store mocks = extensionContext.getStore(ExtensionContext.Namespace.create(MockitoExtension.class, mockType));
String mockName = getMockName(parameter);
if (mockName != null) {
return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
} else {
return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
}
}
示例11: apply
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public ServiceReference<T> apply(final Parameter parameter) {
final Class<T> parameterType = (Class<T>) parameter.getType();
return ofNullable(parameter.getAnnotation(Named.class))
.filter(named -> !named.value().isEmpty())
.map(named -> serviceReference(parameterType, named.value()))
.orElseGet(() -> serviceReference(parameterType));
}
示例12: support
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public boolean support(Parameter param) {
Class<?> vClazz = param.getType();
if (vClazz.isPrimitive() || vClazz == String.class || vClazz == Date.class) {
return param.isAnnotationPresent(Key.class);
}
return false;
}
示例13: resolve
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public Object resolve(Parameter param, IRow row) {
Key vKey = param.getAnnotation(Key.class);
String vColumnName = vKey.value();
Class<?> vClazz = param.getType();
if (vClazz == boolean.class) {
return row.getBoolean(vColumnName);
}
if (vClazz == char.class) {
return row.getChar(vColumnName);
}
if (vClazz == byte.class) {
return row.getByte(vColumnName);
}
if (vClazz == short.class) {
return row.getShort(vColumnName);
}
if (vClazz == int.class) {
return row.getInt(vColumnName);
}
if (vClazz == long.class) {
return row.getLong(vColumnName);
}
if (vClazz == float.class) {
return row.getFloat(vColumnName);
}
if (vClazz == double.class) {
return row.getDouble(vColumnName);
}
if (vClazz == String.class) {
return row.getString(vColumnName);
}
if (vClazz == Date.class) {
return row.getDate(vColumnName);
}
throw new IllegalArgumentException("Should never be here");
}
示例14: runAllStepsInLoop
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
/**
* Runs a bunch of steps for a Gherkin loop.
*
* @param loopedSteps
* GherkinConditionedLoopedStep steps to run
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
*/
protected void runAllStepsInLoop(List<GherkinConditionedLoopedStep> loopedSteps) throws TechnicalException {
for (GherkinConditionedLoopedStep loopedStep : loopedSteps) {
List<GherkinStepCondition> stepConditions = new ArrayList<>();
String[] expecteds = loopedStep.getExpected().split(";");
String[] actuals = loopedStep.getActual().split(";");
if (actuals.length != expecteds.length) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_EXPECTED_ACTUAL_SIZE_DIFFERENT));
}
for (int i = 0; i < expecteds.length; i++) {
stepConditions.add(new GherkinStepCondition(loopedStep.getKey(), expecteds[i], actuals[i]));
}
boolean found = false;
for (Entry<String, Method> elem : Context.getCucumberMethods().entrySet()) {
Matcher matcher = Pattern.compile("value=(.*)\\)").matcher(elem.getKey());
if (matcher.find()) {
Matcher matcher2 = Pattern.compile(matcher.group(1)).matcher(loopedStep.getStep());
if (matcher2.find()) {
Object[] tab;
if (elem.getValue().isAnnotationPresent(Conditioned.class)) {
tab = new Object[matcher2.groupCount() + 1];
tab[matcher2.groupCount()] = stepConditions;
} else {
tab = new Object[matcher2.groupCount()];
}
for (int i = 0; i < matcher2.groupCount(); i++) {
Parameter param = elem.getValue().getParameters()[i];
if (param.getType() == int.class) {
int ii = Integer.parseInt(matcher2.group(i + 1));
tab[i] = ii;
} else if (param.getType() == boolean.class) {
tab[i] = Boolean.parseBoolean(matcher2.group(i + 1));
} else {
tab[i] = matcher2.group(i + 1);
}
}
try {
found = true;
elem.getValue().invoke(NoraUiInjector.getNoraUiInjectorSource().getInstance(elem.getValue().getDeclaringClass()), tab);
break;
} catch (Exception e) {
throw new TechnicalException("\"" + loopedStep.getStep() + "\"", e.getCause());
}
}
}
}
if (!found) {
throw new TechnicalException(String.format(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_STEP_UNDEFINED), loopedStep.getStep()));
}
}
}
示例15: supports
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
public boolean supports(Parameter parameter) {
return parameter.getType() == ArgumentCaptor.class;
}