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 private FluentReflection() {}
28
29 public static <T> FluentClass<T> type(final String className) {
30 try {
31 return (FluentClass<T>) type(Class.forName(className));
32 } catch (final ClassNotFoundException e) {
33 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 return new ReflectedTypeFactoryImpl().reflect(klass);
39 }
40
41 public static <T> FluentClass<T> type(final TypeToken<T> token) {
42 return (FluentClass<T>) new ReflectedTypeFactoryImpl().reflect(TypeLiteral.get(token
43 .getSuperclassTypeParameter()));
44 }
45 public static FluentMethod method(final Method method) {
46 return new ReflectedTypeFactoryImpl().method(method);
47 }
48
49 public static <T> FluentObject<T> object(final T object) {
50 return new ReflectedTypeFactoryImpl().reflect((Class<T>) object.getClass(), object);
51 }
52
53 public static FluentMethod method(final Method method, final Object instance) {
54 return new ReflectedTypeFactoryImpl().method(method, instance);
55 }
56 }