List of usage examples for org.apache.commons.lang3.reflect TypeUtils wrap
public static <T> Typed<T> wrap(final Class<T> type)
From source file:therian.cdi.internal.MapperHandler.java
public MapperHandler(final AnnotatedType<?> type) { // just for error handling of(type.getMethods().stream()/*from w ww.ja v a 2 s. com*/ .filter(m -> m.isAnnotationPresent(PropertyCopier.Mapping.class) && (m.getParameters().size() != 1 || m.getJavaMember().getReturnType() == void.class)) .collect(toList())).filter(l -> !l.isEmpty()).ifPresent(l -> { throw new IllegalArgumentException( "@Mapping only supports one parameter and not void signatures"); }); // TODO: use a single Therian instance if there are not redundant conversions specified by interface methods this.mapping = type.getMethods().stream().filter(m -> m.isAnnotationPresent(PropertyCopier.Mapping.class)) .collect(toMap(AnnotatedMethod::getJavaMember, am -> { final Method member = am.getJavaMember(); final Typed<Object> source = TypeUtils.wrap(member.getGenericParameterTypes()[0]); final Typed<Object> target = TypeUtils.wrap(member.getGenericReturnType()); final Therian therian = Therian.standard() .withAdditionalModules(TherianModule.expandingDependencies(TherianModule.create() .withOperators(PropertyCopier.getInstance(source, target, am.getAnnotation(PropertyCopier.Mapping.class), am.getAnnotation(PropertyCopier.Matching.class))))); @SuppressWarnings({ "unchecked", "rawtypes" }) final Meta<?, ?> result = new Meta(therian, sourceInstance -> Convert.to(target, Positions.<Object>readOnly(source, sourceInstance))); return result; })); this.toString = getClass().getSimpleName() + "[" + type.getJavaClass().getName() + "]"; }
From source file:therian.operator.convert.CopyingConverter.java
/** * Create a {@link CopyingConverter} instance that instantiates the target type using the default constructor. * * @param target type which must have an accessible no-arg constructor * @param <TARGET>/*from ww w .j a v a 2s . c o m*/ * @return CopyingConverter instance */ public static <TARGET> CopyingConverter<Object, TARGET> forTargetType(final Class<TARGET> target) { final Typed<TARGET> targetType = TypeUtils.wrap(target); return new Fluent<TARGET>(requireDefaultConstructor(target)) { @Override public Typed<TARGET> getTargetType() { return targetType; } }; }
From source file:therian.operator.convert.CopyingConverter.java
/** * Intermediate step to create a {@link CopyingConverter} instance that instantiates the (most likely abstract) * target type using the default constructor of a specific implementation. * * @param targetType//from ww w .ja va 2s . c o m * @return {@link Implementing} step */ public static <TARGET> Implementing<TARGET> implementing(Class<TARGET> targetType) { return new Implementing<>(TypeUtils.wrap(targetType)); }
From source file:therian.operator.copy.PropertyCopierTest.java
private PropertyCopier<Jerk, Jerk> jerkCopier() { final Typed<Jerk> type = TypeUtils.wrap(Jerk.class); Method method;/*w w w. ja v a 2 s . c o m*/ try { method = getClass().getMethod("holdConfig"); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException(e); } return PropertyCopier.getInstance(type, type, method.getAnnotation(Mapping.class), method.getAnnotation(Matching.class)); }