1 | |
package com.lexicalscope.fluentreflection; |
2 | |
|
3 | |
import static ch.lambdaj.Lambda.*; |
4 | |
import static com.lexicalscope.fluentreflection.ReflectionMatchers.reflectingOn; |
5 | |
import static org.hamcrest.Matchers.hasItem; |
6 | |
|
7 | |
import java.lang.annotation.Annotation; |
8 | |
import java.lang.reflect.AnnotatedElement; |
9 | |
import java.util.List; |
10 | |
|
11 | |
import org.hamcrest.Matcher; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
final class FluentAnnotatedImpl implements FluentAnnotated { |
29 | |
private final ReflectedTypeFactory reflectedTypeFactory; |
30 | |
private final AnnotatedElement annotatedElement; |
31 | |
|
32 | 24378 | public FluentAnnotatedImpl( |
33 | |
final ReflectedTypeFactory reflectedTypeFactory, |
34 | |
final AnnotatedElement annotatedElement) { |
35 | 24378 | this.reflectedTypeFactory = reflectedTypeFactory; |
36 | 24378 | this.annotatedElement = annotatedElement; |
37 | 24378 | } |
38 | |
|
39 | |
@Override public FluentClass<?> annotation(final Matcher<? super FluentClass<?>> annotationMatcher) { |
40 | 176 | return selectFirst(annotations(), annotationMatcher); |
41 | |
} |
42 | |
|
43 | |
@Override public <A extends Annotation> A annotation(final Class<A> annotationClass) { |
44 | 16 | return annotatedElement.getAnnotation(annotationClass); |
45 | |
} |
46 | |
|
47 | |
@Override public boolean annotatedWith(final Matcher<? super FluentClass<?>> annotationMatcher) { |
48 | 32 | return hasItem(annotationMatcher).matches(annotations()); |
49 | |
} |
50 | |
|
51 | |
@Override public boolean annotatedWith(final Class<? extends Annotation> annotationClass) { |
52 | 32 | return annotatedWith(reflectingOn(annotationClass)); |
53 | |
} |
54 | |
|
55 | |
private List<FluentClass<?>> annotations() { |
56 | 208 | return convert( |
57 | 208 | convert(annotatedElement.getAnnotations(), new ConvertAnnotationToClass()), |
58 | 208 | new ConvertClassToReflectedType(reflectedTypeFactory)); |
59 | |
} |
60 | |
} |