Skip to content

Commit

Permalink
Simplify AnnotationSource / begin removing uses of AnnotatedElement
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jul 25, 2018
1 parent 50bcc9a commit 10d2349
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.AnnotatedElement;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -43,7 +42,7 @@
* @author Graeme Rocher
* @since 1.0
*/
public interface AnnotationMetadata extends AnnotatedElement {
public interface AnnotationMetadata extends AnnotationSource {
/**
* A constant for representing empty metadata.
*/
Expand Down Expand Up @@ -179,6 +178,22 @@ public interface AnnotationMetadata extends AnnotatedElement {
*/
List<AnnotationValue> getDeclaredAnnotationValuesByType(Class<? extends Annotation> annotationType);

/**
* @see AnnotationSource#isAnnotationPresent(Class)
*/
@Override
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
return hasAnnotation(annotationClass);
}

/**
* @see AnnotationSource#isAnnotationPresent(Class)
*/
@Override
default boolean isDeclaredAnnotationPresent(Class<? extends Annotation> annotationClass) {
return hasDeclaredAnnotation(annotationClass);
}

/**
* Return the default value for the given annotation member.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import io.micronaut.core.convert.value.ConvertibleValues;
import io.micronaut.core.value.OptionalValues;

import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.*;

/**
* An interface that can be implemented by other classes that delegate the resolution of the {@link AnnotationMetadata}
Expand All @@ -33,6 +32,226 @@
*/
public interface AnnotationMetadataDelegate extends AnnotationMetadataProvider, AnnotationMetadata {

@Override
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
return getAnnotationMetadata().isAnnotationPresent(annotationClass);
}

@Override
default boolean isDeclaredAnnotationPresent(Class<? extends Annotation> annotationClass) {
return getAnnotationMetadata().isDeclaredAnnotationPresent(annotationClass);
}

@Override
default <T> Optional<T> getDefaultValue(Class<? extends Annotation> annotation, String member, Class<T> requiredType) {
return getAnnotationMetadata().getDefaultValue(annotation, member, requiredType);
}

@Override
default <T> Optional<T> getValue(Class<? extends Annotation> annotation, String member, Class<T> requiredType) {
return getAnnotationMetadata().getValue(annotation, member, requiredType);
}

@Override
default Optional<String> getAnnotationNameByStereotype(String stereotype) {
return getAnnotationMetadata().getAnnotationNameByStereotype(stereotype);
}

@Override
default Optional<String> getDeclaredAnnotationNameTypeByStereotype(String stereotype) {
return getAnnotationMetadata().getDeclaredAnnotationNameTypeByStereotype(stereotype);
}

@Override
default Optional<Class<? extends Annotation>> getAnnotationTypeByStereotype(Class<? extends Annotation> stereotype) {
return getAnnotationMetadata().getAnnotationTypeByStereotype(stereotype);
}

@Override
default Optional<Class<? extends Annotation>> getDeclaredAnnotationTypeByStereotype(Class<? extends Annotation> stereotype) {
return getAnnotationMetadata().getDeclaredAnnotationTypeByStereotype(stereotype);
}

@Override
default Optional<Class<? extends Annotation>> getDeclaredAnnotationTypeByStereotype(String stereotype) {
return getAnnotationMetadata().getDeclaredAnnotationTypeByStereotype(stereotype);
}

@Override
default Optional<Class<? extends Annotation>> getAnnotationTypeByStereotype(String stereotype) {
return getAnnotationMetadata().getAnnotationTypeByStereotype(stereotype);
}

@Override
default Optional<String> getAnnotationNameByStereotype(Class<? extends Annotation> stereotype) {
return getAnnotationMetadata().getAnnotationNameByStereotype(stereotype);
}

@Override
default <T> OptionalValues<T> getValues(Class<? extends Annotation> annotation, Class<T> valueType) {
return getAnnotationMetadata().getValues(annotation, valueType);
}

@Override
default List<String> getAnnotationNamesByStereotype(Class<? extends Annotation> stereotype) {
return getAnnotationMetadata().getAnnotationNamesByStereotype(stereotype);
}

@Override
default List<Class<? extends Annotation>> getAnnotationTypesByStereotype(Class<? extends Annotation> stereotype) {
return getAnnotationMetadata().getAnnotationTypesByStereotype(stereotype);
}

@Override
default ConvertibleValues<Object> getValues(Class<? extends Annotation> annotation) {
return getAnnotationMetadata().getValues(annotation);
}

@Override
default <T> Optional<T> getValue(String annotation, String member, Class<T> requiredType) {
return getAnnotationMetadata().getValue(annotation, member, requiredType);
}

@Override
default OptionalLong longValue(String annotation, String member) {
return getAnnotationMetadata().longValue(annotation, member);
}

@Override
default Optional<Class> classValue(String annotation) {
return getAnnotationMetadata().classValue(annotation);
}

@Override
default Optional<Class> classValue(String annotation, String member) {
return getAnnotationMetadata().classValue(annotation, member);
}

@Override
default Optional<Class> classValue(Class<? extends Annotation> annotation) {
return getAnnotationMetadata().classValue(annotation);
}

@Override
default Optional<Class> classValue(Class<? extends Annotation> annotation, String member) {
return getAnnotationMetadata().classValue(annotation, member);
}

@Override
default OptionalInt intValue(String annotation, String member) {
return getAnnotationMetadata().intValue(annotation, member);
}

@Override
default OptionalDouble doubleValue(String annotation, String member) {
return getAnnotationMetadata().doubleValue(annotation, member);
}

@Override
default <T> Optional<T> getValue(String annotation, Class<T> requiredType) {
return getAnnotationMetadata().getValue(annotation, requiredType);
}

@Override
default Optional<Object> getValue(String annotation, String member) {
return getAnnotationMetadata().getValue(annotation, member);
}

@Override
default Optional<Object> getValue(Class<? extends Annotation> annotation, String member) {
return getAnnotationMetadata().getValue(annotation, member);
}

@Override
default boolean isTrue(String annotation, String member) {
return getAnnotationMetadata().isTrue(annotation, member);
}

@Override
default boolean isTrue(Class<? extends Annotation> annotation, String member) {
return getAnnotationMetadata().isTrue(annotation, member);
}

@Override
default boolean isPresent(String annotation, String member) {
return getAnnotationMetadata().isPresent(annotation, member);
}

@Override
default boolean isPresent(Class<? extends Annotation> annotation, String member) {
return getAnnotationMetadata().isPresent(annotation, member);
}

@Override
default boolean isFalse(Class<? extends Annotation> annotation, String member) {
return getAnnotationMetadata().isFalse(annotation, member);
}

@Override
default boolean isFalse(String annotation, String member) {
return getAnnotationMetadata().isFalse(annotation, member);
}

@Override
default Optional<Object> getValue(String annotation) {
return getAnnotationMetadata().getValue(annotation);
}

@Override
default Optional<Object> getValue(Class<? extends Annotation> annotation) {
return getAnnotationMetadata().getValue(annotation);
}

@Override
default <T> Optional<T> getValue(Class<? extends Annotation> annotation, Class<T> requiredType) {
return getAnnotationMetadata().getValue(annotation, requiredType);
}

@Override
default boolean hasAnnotation(@Nullable Class<? extends Annotation> annotation) {
return getAnnotationMetadata().hasAnnotation(annotation);
}

@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);
}

@Override
default boolean hasStereotype(String[] annotations) {
return getAnnotationMetadata().hasStereotype(annotations);
}

@Override
default boolean hasDeclaredAnnotation(@Nullable Class<? extends Annotation> annotation) {
return getAnnotationMetadata().hasDeclaredAnnotation(annotation);
}

@Override
default boolean hasDeclaredStereotype(@Nullable Class<? extends Annotation> stereotype) {
return getAnnotationMetadata().hasDeclaredStereotype(stereotype);
}

@Override
default boolean hasDeclaredStereotype(Class<? extends Annotation>... annotations) {
return getAnnotationMetadata().hasDeclaredStereotype(annotations);
}

@Override
default boolean isEmpty() {
return getAnnotationMetadata().isEmpty();
}

@Override
default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
return getAnnotationMetadata().getDeclaredAnnotation(annotationClass);
}

@Override
default boolean hasDeclaredAnnotation(String annotation) {
return getAnnotationMetadata().hasDeclaredAnnotation(annotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package io.micronaut.core.annotation;

import java.lang.annotation.Annotation;

/**
* An interface for a type that provides {@link AnnotationMetadata}.
*
* @author Graeme Rocher
* @since 1.0
*/
public interface AnnotationMetadataProvider {
public interface AnnotationMetadataProvider extends AnnotationSource {

/**
* Supplies the metadata. Defaults to {@link AnnotationMetadata#EMPTY_METADATA}.
Expand All @@ -32,4 +34,44 @@ public interface AnnotationMetadataProvider {
default AnnotationMetadata getAnnotationMetadata() {
return AnnotationMetadata.EMPTY_METADATA;
}

@Override
default <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return getAnnotationMetadata().getAnnotation(annotationClass);
}

@Override
default Annotation[] getAnnotations() {
return getAnnotationMetadata().getAnnotations();
}

@Override
default Annotation[] getDeclaredAnnotations() {
return getAnnotationMetadata().getDeclaredAnnotations();
}

@Override
default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
return getAnnotationMetadata().isAnnotationPresent(annotationClass);
}

@Override
default boolean isDeclaredAnnotationPresent(Class<? extends Annotation> annotationClass) {
return getAnnotationMetadata().isDeclaredAnnotationPresent(annotationClass);
}

@Override
default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
return getAnnotationMetadata().getAnnotationsByType(annotationClass);
}

@Override
default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
return getAnnotationMetadata().getDeclaredAnnotation(annotationClass);
}

@Override
default <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
return getAnnotationMetadata().getDeclaredAnnotationsByType(annotationClass);
}
}
Loading

0 comments on commit 10d2349

Please sign in to comment.