List of usage examples for java.lang.annotation Annotation annotationType
Class<? extends Annotation> annotationType();
From source file:Main.java
private static boolean isChromiumAnnotation(Annotation annotation) { Package pkg = annotation.annotationType().getPackage(); return pkg != null && pkg.getName().startsWith("org.chromium"); }
From source file:Main.java
public static Object getAnnotationValueWithName(Annotation annotation, String valueName) { try {//from ww w .j a v a 2 s .c om return annotation.annotationType().getMethod(valueName).invoke(annotation); } catch (Exception e) { return null; } }
From source file:Main.java
public static <T> String getXmlTagNameFromJaxbClass(Class<T> jaxbClass) { String xmlTagName = ""; for (Annotation annotation : jaxbClass.getAnnotations()) { if (annotation.annotationType() == XmlRootElement.class) { xmlTagName = ((XmlRootElement) annotation).name(); break; }//from w w w . ja v a 2s . co m } return xmlTagName; }
From source file:Main.java
/** * Finds an annotation of given <code>annotationType</code> from the given <code>annotations</code>. If * <code>annotations</code> contains multiple annotations of the given type, the first one is returned. If none * is found, this method returns <code>null</code>. * * @param annotations The annotations to search in * @param annotationType The type of annotation to search for * @param <T> The type of annotation to search for * @return the first annotation found, or <code>null</code> if no such annotation is present *//*ww w . j a va2s. co m*/ @SuppressWarnings({ "unchecked" }) @Deprecated public static <T> T getAnnotation(Annotation[] annotations, Class<T> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType().equals(annotationType)) { return (T) annotation; } } return null; }
From source file:Main.java
public static <T> String getNamespaceUriFromJaxbClass(Class<T> jaxbClass) { String nsURI = ""; for (Annotation annotation : jaxbClass.getPackage().getAnnotations()) { if (annotation.annotationType() == XmlSchema.class) { nsURI = ((XmlSchema) annotation).namespace(); break; }/* w w w .ja va 2s .c o m*/ } return nsURI; }
From source file:springfox.documentation.swagger.readers.parameter.ParameterAnnotationReader.java
private static <A extends Annotation> Predicate<? super Annotation> annotationOfType( final Class<A> annotationType) { return new Predicate<Annotation>() { @Override//from www. ja va 2s . c o m public boolean apply(Annotation input) { return input.annotationType().equals(annotationType); } }; }
From source file:com.vmware.photon.controller.common.dcp.validation.NotBlankValidator.java
public static void validate(ServiceDocument state) { try {/*w w w . j a v a 2 s . c om*/ Field[] declaredFields = state.getClass().getDeclaredFields(); for (Field field : declaredFields) { Annotation[] declaredAnnotations = field.getDeclaredAnnotations(); for (Annotation annotation : declaredAnnotations) { if (annotation.annotationType() == NotBlank.class) { checkState(null != field.get(state), String.format("%s cannot be null", field.getName())); if (String.class.equals(field.getType())) { checkState((StringUtils.isNotBlank((String) field.get(state))), String.format("%s cannot be blank", field.getName())); } } } } } catch (IllegalStateException e) { throw e; } catch (Throwable t) { throw new RuntimeException(t); } }
From source file:org.lightadmin.core.util.AnnotationUtils.java
public static Object getAnnotationValue(Annotation annotation, String valueName) throws RuntimeException { try {/* ww w .j a v a 2 s. c om*/ return annotation.annotationType().getMethod(valueName).invoke(annotation); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.nortal.petit.beanmapper.BeanMappingReflectionUtils.java
@SuppressWarnings("unchecked") static <B extends Annotation> B getAnnotation(List<Annotation> ans, Class<B> annotationType) { if (ans != null) { for (Annotation a : ans) { if (a.annotationType().isAssignableFrom(annotationType)) { return (B) a; }/*from www . ja v a 2 s . c o m*/ } } return null; }
From source file:com.payu.ratel.client.RemoteAutowireCandidateResolver.java
private static Optional<Annotation> getAnnotationWithType(DependencyDescriptor descriptor, final Class clazz) { return Iterables.tryFind(Arrays.asList(descriptor.getAnnotations()), new Predicate<Annotation>() { @Override//from w w w. ja v a 2 s. co m public boolean apply(Annotation input) { return clazz.getName().equals(input.annotationType().getName()); } }); }