for (AnnotatedType t : method.getAnnotatedParameterTypes()) { annotation = t.getAnnotation(MyTypeAnnotation.class); if (annotation != null) {
@Override public Object compute(MetaAccessProvider metaAccess, ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) { Executable executable = (Executable) receiver; return executable.getAnnotatedParameterTypes(); } }
public class AnnoTest { @Retention(RetentionPolicy.RUNTIME) @interface Email {} void example(@Email String arg) {} public static void main(String[] args) throws ReflectiveOperationException { Method method=AnnoTest.class.getDeclaredMethod("example", String.class); System.out.println("parameter type annotations:"); AnnotatedType annotatedType = method.getAnnotatedParameterTypes()[0]; //Annotation annotation = annotatedType.getAnnotation(Annotation.class); System.out.println(Arrays.toString(annotatedType.getAnnotations())); System.out.println("parameter annotations:"); System.out.println(Arrays.toString(method.getParameterAnnotations()[0])); } }
public class AnnoTest { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_USE) @interface Email {} void example(@Email String arg) {} public static void main(String[] args) throws ReflectiveOperationException { Method method=AnnoTest.class.getDeclaredMethod("example", String.class); System.out.println("parameter type annotations:"); AnnotatedType annotatedType = method.getAnnotatedParameterTypes()[0]; //Annotation annotation = annotatedType.getAnnotation(Annotation.class); System.out.println(Arrays.toString(annotatedType.getAnnotations())); System.out.println("parameter annotations:"); System.out.println(Arrays.toString(method.getParameterAnnotations()[0])); } }
System.out.println(returnTypeAnnotation); AnnotatedType[] parameters = m.getAnnotatedParameterTypes(); for (AnnotatedType p : parameters) { Annotation parameterAnnotation = p.getAnnotation(ExpectedType.class);
private static AnnotatedType[] getParameterTypes(Executable exe, AnnotatedType declaringType, VarMap.MappingMode mappingMode) { AnnotatedType[] parameterTypes = exe.getAnnotatedParameterTypes(); AnnotatedType exactDeclaringType = getExactSuperType(capture(declaringType), exe.getDeclaringClass()); if (exactDeclaringType == null) { // capture(type) is not a subtype of exe.getDeclaringClass() throw new IllegalArgumentException("The method/constructor " + exe + " is not a member of type " + declaringType); } AnnotatedType[] result = new AnnotatedType[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { result[i] = mapTypeParameters(parameterTypes[i], exactDeclaringType, mappingMode); } return result; }
/** * Returns the exact annotated parameter types of the executable declared by the given type, with type variables resolved (if possible) * * @param executable The executable whose parameter types are to be resolved * @param declaringType The declaring annotated type against which to resolve the types of the parameters of the given executable * @return The resolved annotated types of the parameters of the given executable */ public static AnnotatedType[] getParameterTypes(Executable executable, AnnotatedType declaringType) { AnnotatedType exactDeclaringType = GenericTypeReflector.getExactSuperType(capture(declaringType), executable.getDeclaringClass()); if (isMissingTypeParameters(exactDeclaringType.getType())) { return executable.getAnnotatedParameterTypes(); } return GenericTypeReflector.getParameterTypes(executable, declaringType); }