1 | |
package com.lexicalscope.fluentreflection; |
2 | |
|
3 | |
import static ch.lambdaj.Lambda.*; |
4 | |
|
5 | |
import java.util.List; |
6 | |
|
7 | |
import org.hamcrest.Matcher; |
8 | |
|
9 | |
import com.google.inject.TypeLiteral; |
10 | |
|
11 | |
final class ReflectedMembersImpl<T> implements ReflectedMembers<T> { |
12 | |
private final ReflectedSuperclassesAndInterfaces<T> superclassesAndInterfaces; |
13 | |
private final ReflectedMethods<T> methods; |
14 | |
private final ReflectedConstructors<T> constructors; |
15 | |
private final ReflectedFields<T> fields; |
16 | |
private final Class<T> klass; |
17 | |
|
18 | 14584 | public ReflectedMembersImpl(final ReflectedTypeFactory reflectedTypeFactory, final TypeLiteral<T> typeLiteral) { |
19 | 14584 | this.klass = (Class<T>) typeLiteral.getRawType(); |
20 | 29168 | this.superclassesAndInterfaces = |
21 | 14584 | new ReflectedSuperclassesAndInterfacesImpl<T>(reflectedTypeFactory, typeLiteral); |
22 | 14584 | this.methods = new ReflectedMethodsImpl<T>(reflectedTypeFactory, typeLiteral, superclassesAndInterfaces); |
23 | 14584 | this.constructors = new ReflectedConstructorsImpl<T>(reflectedTypeFactory, typeLiteral); |
24 | 14584 | this.fields = new ReflectedFieldsImpl<T>(reflectedTypeFactory, typeLiteral, superclassesAndInterfaces); |
25 | 14584 | } |
26 | |
|
27 | |
@Override public List<FluentConstructor<T>> constructors() { |
28 | 74 | return constructors.constructors(); |
29 | |
} |
30 | |
|
31 | |
@Override public List<FluentMethod> methods() { |
32 | 1628 | return methods.methods(); |
33 | |
} |
34 | |
|
35 | |
@Override public List<FluentMethod> declaredMethods() { |
36 | 284 | return methods.declaredMethods(); |
37 | |
} |
38 | |
|
39 | |
@Override public List<FluentClass<?>> superclassesAndInterfaces() { |
40 | 48 | return superclassesAndInterfaces.superclassesAndInterfaces(); |
41 | |
} |
42 | |
|
43 | |
@Override public List<FluentMethod> methods(final Matcher<? super FluentMethod> methodMatcher) { |
44 | 112 | return select(methods(), methodMatcher); |
45 | |
} |
46 | |
|
47 | |
@Override public FluentMethod method(final Matcher<? super FluentMethod> methodMatcher) { |
48 | 344 | final FluentMethod selectedMethod = selectFirst(methods(), methodMatcher); |
49 | 344 | if (selectedMethod == null) { |
50 | 0 | throw new MethodNotFoundException(klass, methodMatcher); |
51 | |
} |
52 | 344 | return selectedMethod; |
53 | |
} |
54 | |
|
55 | |
@Override public List<FluentConstructor<T>> constructors( |
56 | |
final Matcher<? super FluentConstructor<?>> constructorMatcher) { |
57 | 8 | return select(constructors(), constructorMatcher); |
58 | |
} |
59 | |
|
60 | |
@Override public FluentConstructor<T> constructor( |
61 | |
final Matcher<? super FluentConstructor<?>> constructorMatcher) { |
62 | 66 | return selectFirst(constructors(), constructorMatcher); |
63 | |
} |
64 | |
|
65 | |
@Override public List<FluentClass<?>> superclassesAndInterfaces( |
66 | |
final Matcher<? super FluentClass<?>> supertypeMatcher) { |
67 | 40 | return select(superclassesAndInterfaces(), supertypeMatcher); |
68 | |
} |
69 | |
|
70 | |
@Override public List<FluentField> declaredFields() { |
71 | 0 | return fields.declaredFields(); |
72 | |
} |
73 | |
|
74 | |
@Override public List<FluentField> fields() { |
75 | 288 | return fields.fields(); |
76 | |
} |
77 | |
|
78 | |
@Override public List<FluentField> fields(final ReflectionMatcher<? super FluentField> fieldMatcher) { |
79 | 8 | return select(fields(), fieldMatcher); |
80 | |
} |
81 | |
|
82 | |
@Override public FluentField field(final Matcher<? super FluentField> fieldMatcher) { |
83 | 80 | final FluentField selectedMethod = selectFirst(fields(), fieldMatcher); |
84 | 80 | if (selectedMethod == null) { |
85 | 0 | throw new FieldNotFoundException(klass, fieldMatcher); |
86 | |
} |
87 | 80 | return selectedMethod; |
88 | |
} |
89 | |
} |