public static boolean isAnnotationPresent(final Enum<?> enumConstant, final Class<? extends Annotation> annotationClass) { try { final Field field = enumConstant.getClass().getDeclaredField(enumConstant.name()); return isAnnotationPresent(field, annotationClass); } catch (final Exception e) { throw new IllegalStateException(e); } }
public static Method[] getMethods(final Class<?> clazz, final Class<? extends Annotation> withAnnotation) { final List<Method> result = new ArrayList<>(); final Method[] methods = getMethods(clazz); for (final Method method : methods) { if (isAnnotationPresent(method, withAnnotation)) { result.add(method); } } return result.toArray(new Method[result.size()]); }
@Override public boolean test(final ComponentDescriptor<?> descriptor) { final Class<?> componentClass = descriptor.getComponentClass(); final boolean isDeprecated = ReflectionUtils.isAnnotationPresent(componentClass, Deprecated.class); return !isDeprecated; }
public static Field[] getAllFields(final Class<?> clazz, final Class<? extends Annotation> withAnnotation) { final List<Field> result = new ArrayList<>(); final Field[] fields = getAllFields(clazz); for (final Field field : fields) { if (isAnnotationPresent(field, withAnnotation)) { result.add(field); } } return result.toArray(new Field[result.size()]); }
public boolean isRenderer() { if (_beanClazz != null) { return ReflectionUtils.isAnnotationPresent(_beanClazz, RendererBean.class) && ReflectionUtils.is(_beanClazz, Renderer.class); } return false; }
@Override protected void visitMethod(final Method method) { final boolean isInitialize; { final boolean isInitializeAnnotationPresent = ReflectionUtils.isAnnotationPresent(method, Initialize.class); final boolean isPostConstructAnnotationPresent = ReflectionUtils.isAnnotationPresent(method, PostConstruct.class); // @PostConstruct is a valid substitution for @Initialize isInitialize = isInitializeAnnotationPresent || isPostConstructAnnotationPresent; } final boolean isClose; { final boolean isPreDestroyAnnotationPresent = ReflectionUtils.isAnnotationPresent(method, PreDestroy.class); final boolean isCloseAnnotationPresent = ReflectionUtils.isAnnotationPresent(method, Close.class); // @PreDestroy is a valid substitution for @Close isClose = isCloseAnnotationPresent || isPreDestroyAnnotationPresent; } final boolean isValidate = ReflectionUtils.isAnnotationPresent(method, Validate.class); if (isInitialize) { _initializeMethods.add(new InitializeMethodDescriptorImpl(method, this)); } if (isValidate) { _validateMethods.add(new ValidateMethodDescriptorImpl(method, this)); } if (isClose) { _closeMethods.add(new CloseMethodDescriptorImpl(method, this)); } }
@Override protected void visitField(final Field field) { final boolean isInject = ReflectionUtils.isAnnotationPresent(field, Inject.class); final boolean isConfigured = ReflectionUtils.isAnnotationPresent(field, Configured.class); final boolean isProvided = ReflectionUtils.isAnnotationPresent(field, Provided.class); if (isConfigured && isProvided) { throw new DescriptorException("The field " + field + " is annotated with both @Configured and @Provided, which are mutually exclusive."); } if (!isConfigured && (isInject || isProvided)) { // provided properties = @Inject or @Provided, and NOT @Configured _providedProperties.add(new ProvidedPropertyDescriptorImpl(field, this)); } else if (isConfigured) { if (!isInject) { logger.debug("No @Inject annotation found for @Configured field: {}", field); } final ConfiguredPropertyDescriptor cpd = new ConfiguredPropertyDescriptorImpl(field, this); _configuredProperties.add(cpd); } }