1 | |
package com.lexicalscope.fluentreflection; |
2 | |
|
3 | |
import java.lang.reflect.Method; |
4 | |
|
5 | |
import com.google.inject.TypeLiteral; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
public final class FluentReflection { |
27 | 0 | private FluentReflection() {} |
28 | |
|
29 | |
public static <T> FluentClass<T> type(final String className) { |
30 | |
try { |
31 | 10 | return (FluentClass<T>) type(Class.forName(className)); |
32 | 0 | } catch (final ClassNotFoundException e) { |
33 | 0 | throw new ClassNotFoundRuntimeException("unable to find class with name " + className, e); |
34 | |
} |
35 | |
} |
36 | |
|
37 | |
public static <T> FluentClass<T> type(final Class<T> klass) { |
38 | 844 | return new ReflectedTypeFactoryImpl().reflect(klass); |
39 | |
} |
40 | |
|
41 | |
public static <T> FluentClass<T> type(final TypeToken<T> token) { |
42 | 48 | return (FluentClass<T>) new ReflectedTypeFactoryImpl().reflect(TypeLiteral.get(token |
43 | 24 | .getSuperclassTypeParameter())); |
44 | |
} |
45 | |
public static FluentMethod method(final Method method) { |
46 | 32 | return new ReflectedTypeFactoryImpl().method(method); |
47 | |
} |
48 | |
|
49 | |
public static <T> FluentObject<T> object(final T object) { |
50 | 968 | return new ReflectedTypeFactoryImpl().reflect((Class<T>) object.getClass(), object); |
51 | |
} |
52 | |
|
53 | |
public static FluentMethod method(final Method method, final Object instance) { |
54 | 8 | return new ReflectedTypeFactoryImpl().method(method, instance); |
55 | |
} |
56 | |
} |