Java Code Examples for java.lang.reflect.AnnotatedElement#getAnnotationsByType()
The following examples show how to use
java.lang.reflect.AnnotatedElement#getAnnotationsByType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringValidator.java From jsonstream with Apache License 2.0 | 6 votes |
public StringValidator(AnnotatedElement ae) { required = ae.isAnnotationPresent(Required.class); minLength = ae.isAnnotationPresent(MinLength.class) ? ae.getAnnotation(MinLength.class).value() : null; maxLength = ae.isAnnotationPresent(MaxLength.class) ? ae.getAnnotation(MaxLength.class).value() : null; pattern = ae.isAnnotationPresent(Pattern.class) ? java.util.regex.Pattern.compile(ae.getAnnotation(Pattern.class).value()) : null; enums = ae.isAnnotationPresent(EnumString.class) ? new HashSet<String>(Arrays.asList(ae.getAnnotation(EnumString.class).value())) : null; Format[] formatAnnos = ae.getAnnotationsByType(Format.class); formats = new StringFormat[formatAnnos.length]; for (int i=0; i<formatAnnos.length; i++) { formats[i] = newStringFormat(formatAnnos[i].value()); } }
Example 2
Source File: StringValidator.java From jsonstream with Apache License 2.0 | 6 votes |
public StringValidator(AnnotatedElement ae) { required = ae.isAnnotationPresent(Required.class); minLength = ae.isAnnotationPresent(MinLength.class) ? ae.getAnnotation(MinLength.class).value() : null; maxLength = ae.isAnnotationPresent(MaxLength.class) ? ae.getAnnotation(MaxLength.class).value() : null; pattern = ae.isAnnotationPresent(Pattern.class) ? java.util.regex.Pattern.compile(ae.getAnnotation(Pattern.class).value()) : null; enums = ae.isAnnotationPresent(EnumString.class) ? new HashSet<String>(Arrays.asList(ae.getAnnotation(EnumString.class).value())) : null; Format[] formatAnnos = ae.getAnnotationsByType(Format.class); formats = new StringFormat[formatAnnos.length]; for (int i=0; i<formatAnnos.length; i++) { formats[i] = newStringFormat(formatAnnos[i].value()); } }
Example 3
Source File: AopInterceptor.java From hasor with Apache License 2.0 | 5 votes |
private List<Class<? extends MethodInterceptor>> collectAnno(AnnotatedElement element) { Aop[] annoSet = element.getAnnotationsByType(Aop.class); if (annoSet == null) { annoSet = new Aop[0]; } return Arrays.stream(annoSet).flatMap(// (Function<Aop, Stream<Class<? extends MethodInterceptor>>>) aop -> Arrays.stream(aop.value())// ).collect(Collectors.toList()); }
Example 4
Source File: AnnotatedElementTestSupport.java From j2objc with Apache License 2.0 | 5 votes |
/** * Asserts that {@link AnnotatedElement#getAnnotationsByType(Class)} returns the * expected result. The result is specified using a String. See * {@link AnnotatedElementTestSupport} for the string syntax. */ static void assertGetAnnotationsByType(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType, String[] expectedAnnotationStrings) throws Exception { Annotation[] annotations = annotatedElement.getAnnotationsByType(annotationType); assertAnnotationsMatch(annotations, expectedAnnotationStrings); }