1 package com.lexicalscope.fluentreflection;
2
3 import java.lang.reflect.Constructor;
4
5 import ch.lambdaj.function.convert.Converter;
6
7 import com.google.inject.TypeLiteral;
8
9 class ConvertConstructorToReflectedConstructor<T> implements Converter<Constructor<?>, FluentConstructor<T>> {
10 private final ReflectedTypeFactory reflectedTypeFactory;
11 private final TypeLiteral<T> typeLiteral;
12
13 public ConvertConstructorToReflectedConstructor(
14 final ReflectedTypeFactory reflectedTypeFactory,
15 final TypeLiteral<T> typeLiteral) {
16 this.reflectedTypeFactory = reflectedTypeFactory;
17 this.typeLiteral = typeLiteral;
18 }
19
20 public ConvertConstructorToReflectedConstructor(
21 final ReflectedTypeFactory reflectedTypeFactory,
22 final Class<T> klass) {
23 this(reflectedTypeFactory, TypeLiteral.get(klass));
24 }
25
26 @SuppressWarnings("unchecked") @Override public FluentConstructor<T> convert(final Constructor<?> from) {
27 return new FluentConstructorImpl<T>(reflectedTypeFactory, typeLiteral, (Constructor<T>) from);
28 }
29 }