kotlin.reflect.KClass Java Examples
The following examples show how to use
kotlin.reflect.KClass.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeParser.java From typescript-generator with MIT License | 6 votes |
@Override public Type getMethodReturnType(Method method) { final KFunction<?> kFunction = ReflectJvmMapping.getKotlinFunction(method); if (kFunction != null) { return getType(kFunction.getReturnType(), new LinkedHashMap<>()); } else { // `method` might be a getter so try to find a corresponding field and pass it to Kotlin reflection final KClass<?> kClass = JvmClassMappingKt.getKotlinClass(method.getDeclaringClass()); final Optional<Field> field = KClasses.getMemberProperties(kClass).stream() .filter(kProperty -> Objects.equals(ReflectJvmMapping.getJavaGetter(kProperty), method)) .map(kProperty -> ReflectJvmMapping.getJavaField(kProperty)) .filter(Objects::nonNull) .findFirst(); if (field.isPresent()) { return getFieldType(field.get()); } } return javaTypeParser.getMethodReturnType(method); }
Example #2
Source File: TypeParser.java From typescript-generator with MIT License | 4 votes |
private Type getBareType(KType kType, Map<String, JTypeVariable<?>> typeParameters) { final KClassifier kClassifier = kType.getClassifier(); if (kClassifier instanceof KClass) { final KClass<?> kClass = (KClass<?>) kClassifier; final Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass); if (isArrayOfPrimitiveType(javaClass)) { return javaClass; } final List<KTypeProjection> arguments = kType.getArguments(); if (arguments.isEmpty()) { return javaClass; } else if (javaClass.isArray()) { return new JGenericArrayType(getType(arguments.get(0).getType(), typeParameters)); } else { final List<Type> javaArguments = arguments.stream() .map(argument -> getType(argument.getType(), typeParameters)) .collect(Collectors.toList()); return Utils.createParameterizedType(javaClass, javaArguments); } } if (kClassifier instanceof KTypeParameter) { final KTypeParameter kTypeParameter = (KTypeParameter) kClassifier; final JTypeVariable<?> typeVariableFromMap = typeParameters.get(kTypeParameter.getName()); if (typeVariableFromMap != null) { return typeVariableFromMap; } else { final TypeVariable<?> typeVariable = getJavaTypeVariable(kType); final JTypeVariable<?> newTypeVariable = new JTypeVariable<>( typeVariable != null ? typeVariable.getGenericDeclaration() : null, kTypeParameter.getName(), /*bounds*/ null, typeVariable != null ? typeVariable.getAnnotatedBounds() : null, typeVariable != null ? typeVariable.getAnnotations() : null, typeVariable != null ? typeVariable.getDeclaredAnnotations() : null ); typeParameters.put(kTypeParameter.getName(), newTypeVariable); final Type[] bounds = getTypes(kTypeParameter.getUpperBounds(), typeParameters).toArray(new Type[0]); newTypeVariable.setBounds(bounds); return newTypeVariable; } } throw new RuntimeException("Unexpected type: " + kType.toString()); }
Example #3
Source File: Feature.java From yawp with MIT License | 4 votes |
public <T> QueryBuilder<T> yawp(KClass<T> kClazz) { return yawp(JvmClassMappingKt.getJavaClass(kClazz)); }
Example #4
Source File: Feature.java From yawp with MIT License | 4 votes |
public <T> T from(String json, KClass<T> kClazz) { return JsonUtils.from(yawp, json, JvmClassMappingKt.getJavaClass(kClazz)); }
Example #5
Source File: Feature.java From yawp with MIT License | 4 votes |
public <T> List<T> fromList(String json, KClass<T> kClazz) { return JsonUtils.fromList(yawp, json, JvmClassMappingKt.getJavaClass(kClazz)); }
Example #6
Source File: Feature.java From yawp with MIT License | 4 votes |
public <K, V> Map<K, V> fromMap(String json, KClass<K> kKeyClazz, KClass<V> kValueClazz) { return JsonUtils.fromMap(yawp, json, JvmClassMappingKt.getJavaClass(kKeyClazz), JvmClassMappingKt.getJavaClass(kValueClazz)); }