@Override default boolean hasStereotype(String[] annotations) { return getAnnotationMetadata().hasStereotype(annotations); }
@Override default boolean hasStereotype(@Nullable Class<? extends Annotation> annotation) { return getAnnotationMetadata().hasStereotype(annotation); }
@Override default boolean hasStereotype(Class<? extends Annotation>... annotations) { return getAnnotationMetadata().hasStereotype(annotations); }
/** * <p>Checks whether this object has the given annotation stereotype on the object itself or inherited from a parent</p>. * <p> * <p>An annotation stereotype is a meta annotation potentially applied to another annotation</p> * * @param annotation The annotation * @return True if the annotation is present */ default boolean hasStereotype(@Nullable Class<? extends Annotation> annotation) { if (annotation != null) { Repeatable repeatable = annotation.getAnnotation(Repeatable.class); if (repeatable != null) { return hasStereotype(repeatable.value()); } else { return hasStereotype(annotation.getName()); } } return false; }
@Override default boolean hasStereotype(String annotation) { return getAnnotationMetadata().hasStereotype(annotation); }
/** * Check whether any of the given stereotypes is present. * * @param annotations The annotations * @return True if any of the given stereotypes are present */ default boolean hasStereotype(@Nullable String[] annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (String annotation : annotations) { if (hasStereotype(annotation)) { return true; } } return false; }
/** * Check whether any of the given stereotypes is present. * * @param annotations The annotations * @return True if any of the given stereotypes are present */ @SuppressWarnings("unchecked") default boolean hasStereotype(@Nullable Class<? extends Annotation>... annotations) { if (ArrayUtils.isEmpty(annotations)) { return false; } for (Class<? extends Annotation> annotation : annotations) { if (hasStereotype(annotation)) { return true; } } return false; }
/** * Get the value of the given annotation member. * * @param annotation The annotation class * @param member The annotation member * @param requiredType The required type * @param <T> The value * @return An {@link Optional} of the value */ default @Nonnull <T> Optional<T> getValue(@Nonnull String annotation, @Nonnull String member, @Nonnull Argument<T> requiredType) { ArgumentUtils.requireNonNull("annotation", annotation); ArgumentUtils.requireNonNull("member", member); ArgumentUtils.requireNonNull("requiredType", requiredType); Optional<T> value = findAnnotation(annotation).flatMap(av -> av.get(member, requiredType)); if (!value.isPresent()) { if (hasStereotype(annotation)) { return getDefaultValue(annotation, member, requiredType); } } return value; }
Optional<T> value = values.flatMap(av -> av.get(member, requiredType)); if (!value.isPresent()) { if (hasStereotype(annotation)) { return getDefaultValue(annotation, member, requiredType);
if (annotationMetadata.hasStereotype(Format.class)) { final Object v = paramMap.get(argumentName); if (v != null) {
private <T> Function<Class, Boolean> typeMatches(BeanType<T> definition, AnnotationMetadata annotationMetadata) { Class<T> bt = definition.getBeanType(); if (annotationMetadata.hasStereotype(INTRODUCTION_TYPE)) { Class<? super T> superclass = bt.getSuperclass(); if (superclass == Object.class) { // interface introduction return (clazz) -> clazz.isAssignableFrom(bt); } else { // abstract class introduction return (clazz) -> clazz == superclass; } } if (annotationMetadata.hasStereotype(AROUND_TYPE)) { Class<? super T> superclass = bt.getSuperclass(); return (clazz) -> clazz == superclass || clazz == bt; } return (clazz) -> clazz == bt; }
@Override public <BT extends BeanType<T>> Stream<BT> reduce(Class<T> beanType, Stream<BT> candidates) { return candidates.filter(candidate -> candidate.getAnnotationMetadata().hasStereotype(stereotype)); }
private <T> Function<Class, Boolean> typeMatches(BeanType<T> definition, AnnotationMetadata annotationMetadata) { Class<T> bt = definition.getBeanType(); if (annotationMetadata.hasStereotype(INTRODUCTION_TYPE)) { Class<? super T> superclass = bt.getSuperclass(); if (superclass == Object.class) { // interface introduction return (clazz) -> clazz.isAssignableFrom(bt); } else { // abstract class introduction return (clazz) -> clazz == superclass; } } if (annotationMetadata.hasStereotype(AROUND_TYPE)) { Class<? super T> superclass = bt.getSuperclass(); return (clazz) -> clazz == superclass || clazz == bt; } return (clazz) -> clazz == bt; }
@Override public <BT extends BeanType<T>> Stream<BT> reduce(Class<T> beanType, Stream<BT> candidates) { return candidates.filter(candidate -> candidate.getAnnotationMetadata().hasStereotype(stereotype)); }
@Override public boolean isEnabled(BeanContext context) { int contextId = System.identityHashCode(context); Boolean enabled = this.enabled.get(contextId); if (enabled == null) { AnnotationMetadata annotationMetadata = getAnnotationMetadata(); Condition condition = annotationMetadata.hasStereotype(Requires.class) ? new RequiresCondition(annotationMetadata) : null; DefaultConditionContext<AbstractBeanContextConditional> conditionContext = new DefaultConditionContext<>(context, this); enabled = condition == null || condition.matches(conditionContext); if (LOG.isDebugEnabled() && !enabled) { if (this instanceof BeanConfiguration) { LOG.debug(this + " will not be loaded due to failing conditions:"); } else { LOG.debug("Bean [" + this + "] will not be loaded due to failing conditions:"); } for (Failure failure : conditionContext.getFailures()) { LOG.debug("* {}", failure.getMessage()); } } this.enabled.put(contextId, enabled); } return enabled; } }
@Override public boolean isEnabled(BeanContext context) { int contextId = System.identityHashCode(context); Boolean enabled = this.enabled.get(contextId); if (enabled == null) { AnnotationMetadata annotationMetadata = getAnnotationMetadata(); Condition condition = annotationMetadata.hasStereotype(Requires.class) ? new RequiresCondition(annotationMetadata) : null; DefaultConditionContext<AbstractBeanContextConditional> conditionContext = new DefaultConditionContext<>(context, this); enabled = condition == null || condition.matches(conditionContext); if (LOG.isDebugEnabled() && !enabled) { if (this instanceof BeanConfiguration) { LOG.debug(this + " will not be loaded due to failing conditions:"); } else { LOG.debug("Bean [" + this + "] will not be loaded due to failing conditions:"); } for (Failure failure : conditionContext.getFailures()) { LOG.debug("* {}", failure.getMessage()); } } this.enabled.put(contextId, enabled); } return enabled; } }
if (candidate.getAnnotationMetadata().hasStereotype(Replaces.class)) { replacedTypes.add(candidate);
if (candidate.getAnnotationMetadata().hasStereotype(Replaces.class)) { replacedTypes.add(candidate);
if (annotationMetadata.hasStereotype(Format.class)) { final Object v = paramMap.get(argumentName); if (v != null) {
if (annotationMetadata.hasStereotype(Format.class)) { final Object v = paramMap.get(argumentName); if (v != null) {