public static ClassLoader getClassLoader(Type target, ClassLoader defaultClassLoader) { if (target == null) return defaultClassLoader; Class<?> clazz = toClass(target); if (clazz == null) return defaultClassLoader; return clazz.getClassLoader(); }
public static Class<?> toWrapperClass(Type type) { final Class<?> clazz = TypeHelper.toClass(type); if (clazz.isPrimitive()) { return wrappers.get(clazz); } else return clazz; } public static String toWrapperType(Type type) {
@Override public boolean supports(Type type) { return "org.eclipse.collections.api.list.MutableList".equals(TypeHelper.toClass(type).getName()); } @Override
@Override public boolean supports(Type type) { return "com.google.common.collect.ImmutableList".equals(TypeHelper.toClass(type).getName()); } @Override
public static boolean isKotlinClass(Type target) { Annotation[] annotations = TypeHelper.toClass(target).getDeclaredAnnotations(); if (annotations != null) { for(int i = 0; i < annotations.length;i++) { Annotation a = annotations[i]; if (a.annotationType().getName().equals("kotlin.Metadata")) { return true; } } } return false; }
private static ClassLoader getClassLoader(Type target) { if (target == null) return Thread.currentThread().getContextClassLoader(); Class<Object> aClass = TypeHelper.toClass(target); if (aClass == null) return Thread.currentThread().getContextClassLoader(); return aClass.getClassLoader(); }
public static Class<?> asJavaClass(DataType dataType, Type target) { if (dataType != null) { Class<?> dataTypeClass = asJavaClass(dataType); if (dataTypeClass != null) { return dataTypeClass; } } return defaultTypes.get(TypeHelper.toClass(target).getName()); } }
public static boolean supports(Type target) { Class<?> clazz = TypeHelper.toClass(target); for(InstantiatorDefinitionAndIntermediatTypeFactory factory :intermediatTypeFactories) { if (factory.supports(target)) { return true; } } return (Collection.class.isAssignableFrom(clazz) || Iterable.class.equals(clazz)); }
private Member getBuilderInstantiator(Type target) { String typeName = TypeHelper.toClass(target).getName(); UnaryFactory<Type, Member> builderSupplier = builderMethods.get(typeName); if (builderSupplier != null) { return builderSupplier.newInstance(target); } return null; }
private static InstantiatorDefinition getConstructor(Type type) { if (TypeHelper.isArray(type)) { return null; } else { try { return new ExecutableInstantiatorDefinition(TypeHelper.toClass(type).getDeclaredConstructor()); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("No empty constructor for " + type); } } }
public static InstantiatorDefinitionAndIntermediatType getTypeInfo(Type type) { for(InstantiatorDefinitionAndIntermediatTypeFactory factory :intermediatTypeFactories) { if (factory.supports(type)) { return factory.newTypeInfo(type); } } Class<Object> clazz = TypeHelper.toClass(type); if (!Modifier.isAbstract(clazz.getModifiers())) { return new InstantiatorDefinitionAndIntermediatType(getConstructor(type), type, false); } throw new IllegalArgumentException("Unknown List impl for " + type); }
public static String toTargetTypeDeclaration(Type targetType) { if (TypeHelper.isPrimitive(targetType)) { return primitivesType.get(TypeHelper.toClass(targetType)); } return toTargetTypeDeclaration(AsmUtils.toAsmType(targetType)); } public static String toTargetTypeDeclaration(String targetType) {
public static String toTargetTypeDeclaration(Type targetType) { if (TypeHelper.isPrimitive(targetType)) { return primitivesType.get(TypeHelper.toClass(targetType)); } return toTargetTypeDeclaration(AsmUtils.toAsmType(targetType)); } public static String toTargetTypeDeclaration(String targetType) {
public static void invoke(MethodVisitor mv, Type target, String method, String sig) { Type publicClass = findTypeInHierarchy(target, new TypeIsPublicAndHasMethodMethod(method)); boolean isInterface = TypeHelper.toClass(publicClass).isInterface(); mv.visitMethodInsn(isInterface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, toAsmType(publicClass), method, sig, isInterface); }
@Override public void addMappingCall(MethodVisitor mv, String mapperClassType) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, mapperClassType, prefix + index, "L" + AsmUtils.toAsmType(mapperClass) + ";"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 3); Method m = getMapToMethod(TypeHelper.toClass(mapperClass)); AsmUtils.invoke(mv, m); }
@Override public void addMappingCall(MethodVisitor mv, String mapperClassType) { Type mapperClass = AsmUtils.findClosestPublicTypeExposing(mapper.getClass(), FieldMapper.class); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, mapperClassType, prefix + index, "L" + AsmUtils.toAsmType(mapperClass) + ";"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 3); Method m = getMapToMethod(TypeHelper.toClass(mapperClass)); AsmUtils.invoke(mv, m); }
private static <T, E> ConstructorPropertyMeta<T, E> newConstructorPropertyMeta(InstantiatorDefinition instantiatorDefinition, int i, ReflectionService reflectionService, Type type) { Class<T> tClass = TypeHelper.toClass(type); final Parameter parameter = instantiatorDefinition.getParameters()[i]; Getter<T, E> getter = reflectionService.getObjectGetterFactory().getGetter(tClass, parameter.getName()); return new ConstructorPropertyMeta<T, E>("element" + i, type, reflectionService, parameter, ScoredGetter.<T, E>of(getter, Integer.MAX_VALUE), ScoredSetter.<T, E>nullSetter(), instantiatorDefinition, null); }
@Override public <T> ContextualIndexedSetter<PreparedStatement, T> getIndexedSetter(PropertyMapping<?, ?, JdbcColumnKey> arg, ContextFactoryBuilder contextFactoryBuilder, Object... properties) { Type propertyType = arg.getPropertyMeta().getPropertyType(); ContextualIndexedSetter<PreparedStatement, T> setter = getIndexedSetter(propertyType, arg, contextFactoryBuilder); if (setter == null) { Class<?> iclass = JdbcTypeHelper.toJavaType(arg.getColumnKey().getSqlType(properties), propertyType); setter = getSetterWithConvertion(TypeHelper.<T>toClass(propertyType), iclass,contextFactoryBuilder, arg); } return setter; }
private static <T, E> ConstructorPropertyMeta<T, E> newConstructorPropertyMeta(InstantiatorDefinition instantiatorDefinition, int i, ReflectionService reflectionService, Type type) { Class<T> tClass = TypeHelper.toClass(type); final Parameter parameter = instantiatorDefinition.getParameters()[i]; Getter<T, E> getter = reflectionService.getObjectGetterFactory().getGetter(tClass, parameter.getName()); return new ConstructorPropertyMeta<T, E>("element" + i, type, reflectionService, parameter, ScoredGetter.<T, E>of(getter, Integer.MAX_VALUE), ScoredSetter.<T, E>nullSetter(), instantiatorDefinition, null); }