當前位置: 首頁>>代碼示例>>Java>>正文


Java Parameter.getType方法代碼示例

本文整理匯總了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;
}
 
開發者ID:wujiangchao,項目名稱:chopsticks,代碼行數:26,代碼來源:MethodArgument.java

示例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);
}
 
開發者ID:siy,項目名稱:booter-injector,代碼行數:28,代碼來源:Key.java

示例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;
}
 
開發者ID:ARMmbed,項目名稱:mbed-cloud-sdk-java,代碼行數:20,代碼來源:APIMappingGenerator.java

示例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);
}
 
開發者ID:zhyzhyzhy,項目名稱:Ink,代碼行數:23,代碼來源:RouteFinder.java

示例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();
}
 
開發者ID:primeval-io,項目名稱:primeval-reflex,代碼行數:52,代碼來源:MethodArgumentssUpdaterGenerator.java

示例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));
	}
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:13,代碼來源:MockitoExtension.java

示例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));
  }
}
 
開發者ID:1tontech,項目名稱:intellij-spring-assistant,代碼行數:12,代碼來源:MockitoExtension.java

示例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));
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:11,代碼來源:MockitoExtension.java

示例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));
    }
}
 
開發者ID:jcapsule,項目名稱:jwebassembly,代碼行數:12,代碼來源:MockitoExtension.java

示例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));
}
 
開發者ID:slezhnin,項目名稱:yadi,代碼行數:10,代碼來源:NamedParameterReference.java

示例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;
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:9,代碼來源:NamedArgumentResolver.java

示例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");
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:38,代碼來源:NamedArgumentResolver.java

示例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()));
        }
    }
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:60,代碼來源:Step.java

示例15: supports

import java.lang.reflect.Parameter; //導入方法依賴的package包/類
@Override
public boolean supports(Parameter parameter) {
  return parameter.getType() == ArgumentCaptor.class;
}
 
開發者ID:JeffreyFalgout,項目名稱:junit5-extensions,代碼行數:5,代碼來源:CaptorParameterFactory.java


注:本文中的java.lang.reflect.Parameter.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。