@Test public void testTypeConversion() { TypeProcessor converter = new DefaultTypeProcessor(); final TypeProcessor.Context context = getTestContext(converter); assertEquals(context.getSymbol(A.class).getFullName(), converter.processType(A.class, context).getTsType().toString()); assertEquals(context.getSymbol(B.class).getFullName(), converter.processType(B.class, context).getTsType().toString()); assertEquals(TsType.Void, converter.processType(void.class, context).getTsType()); assertEquals(TsType.Number, converter.processType(BigDecimal.class, context).getTsType()); assertEquals(TsType.String, converter.processType(UUID.class, context).getTsType()); assertEquals(TsType.Number.optional(), converter.processType(OptionalInt.class, context).getTsType()); assertEquals(TsType.Number.optional(), converter.processType(OptionalLong.class, context).getTsType()); assertEquals(TsType.Number.optional(), converter.processType(OptionalDouble.class, context).getTsType()); }
@Override public Result processType(Type javaType, Context context) { if (Objects.equals(javaType, Object.class)) { return new Result(TsType.Any); } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.stringClasses, javaClass)) { return new Result(TsType.String); } if (isAssignableFrom(known.numberClasses, javaClass)) { return new Result(TsType.Number); } if (isAssignableFrom(known.booleanClasses, javaClass)) { return new Result(TsType.Boolean); } if (isAssignableFrom(known.dateClasses, javaClass)) { return new Result(TsType.Date); } if (isAssignableFrom(known.voidClasses, javaClass)) { return new Result(TsType.Void); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; final Symbol importedSymbol = context.getSymbolIfImported(javaClass); if (importedSymbol != null) { return new Result(new TsType.ReferenceType(importedSymbol)); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.anyClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.isArray()) { final Result result = context.processTypeInsideCollection(javaClass.getComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaClass.isEnum()) { return new Result(new TsType.EnumReferenceType(context.getSymbol(javaClass)), javaClass); } if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(Object.class); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(String.class, Object.class, context); } if (OptionalInt.class.isAssignableFrom(javaClass) || OptionalLong.class.isAssignableFrom(javaClass) || OptionalDouble.class.isAssignableFrom(javaClass)) { return new Result(TsType.Number.optional()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.getTypeParameters().length > 0) { final List<TsType> tsTypeArguments = new ArrayList<>(); for (int i = 0; i < javaClass.getTypeParameters().length; i++) { tsTypeArguments.add(TsType.Any); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments)); } return new Result(new TsType.ReferenceType(context.getSymbol(javaClass)), javaClass); } if (javaType instanceof ParameterizedType) { final ParameterizedType parameterizedType = (ParameterizedType) javaType; if (parameterizedType.getRawType() instanceof Class) { final Class<?> javaClass = (Class<?>) parameterizedType.getRawType(); if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(parameterizedType.getActualTypeArguments()[0]); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(parameterizedType.getActualTypeArguments()[0], parameterizedType.getActualTypeArguments()[1], context); } if (isAssignableFrom(known.optionalClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType().optional(), result.getDiscoveredClasses()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType(), result.getDiscoveredClasses()); } final List<Class<?>> discoveredClasses = new ArrayList<>(); discoveredClasses.add(javaClass); final List<TsType> tsTypeArguments = new ArrayList<>(); for (Type typeArgument : parameterizedType.getActualTypeArguments()) { final TypeProcessor.Result typeArgumentResult = context.processType(typeArgument); tsTypeArguments.add(typeArgumentResult.getTsType()); discoveredClasses.addAll(typeArgumentResult.getDiscoveredClasses()); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments), discoveredClasses); } } if (javaType instanceof GenericArrayType) { final GenericArrayType genericArrayType = (GenericArrayType) javaType; final Result result = context.processTypeInsideCollection(genericArrayType.getGenericComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) javaType; if (typeVariable.getGenericDeclaration() instanceof Method) { return context.processType(typeVariable.getBounds()[0]); } return new Result(new TsType.GenericVariableType(typeVariable.getName())); } if (javaType instanceof WildcardType) { final WildcardType wildcardType = (WildcardType) javaType; final Type[] upperBounds = wildcardType.getUpperBounds(); return upperBounds.length > 0 ? context.processType(upperBounds[0]) : new Result(TsType.Any); } if (javaType instanceof JUnionType) { final JUnionType unionType = (JUnionType) javaType; final List<Result> results = unionType.getTypes().stream() .map(type -> context.processType(type)) .collect(Collectors.toList()); return new Result( new TsType.UnionType(results.stream() .map(result -> result.getTsType()) .collect(Collectors.toList())), results.stream() .flatMap(result -> result.getDiscoveredClasses().stream()) .collect(Collectors.toList()) ); } if (javaType instanceof JTypeWithNullability) { final JTypeWithNullability typeWithNullability = (JTypeWithNullability) javaType; final Result result = context.processType(typeWithNullability.getType()); return new Result( typeWithNullability.isNullable() ? new TsType.NullableType(result.getTsType()) : result.getTsType(), result.getDiscoveredClasses() ); } return null; }
DefaultTypeProcessor implements TypeProcessor { @Override public Result processType(Type javaType, Context context) { if (Objects.equals(javaType, Object.class)) { return new Result(TsType.Any); } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.stringClasses, javaClass)) { return new Result(TsType.String); } if (isAssignableFrom(known.numberClasses, javaClass)) { return new Result(TsType.Number); } if (isAssignableFrom(known.booleanClasses, javaClass)) { return new Result(TsType.Boolean); } if (isAssignableFrom(known.dateClasses, javaClass)) { return new Result(TsType.Date); } if (isAssignableFrom(known.voidClasses, javaClass)) { return new Result(TsType.Void); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; final Symbol importedSymbol = context.getSymbolIfImported(javaClass); if (importedSymbol != null) { return new Result(new TsType.ReferenceType(importedSymbol)); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.anyClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.isArray()) { final Result result = context.processTypeInsideCollection(javaClass.getComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaClass.isEnum()) { return new Result(new TsType.EnumReferenceType(context.getSymbol(javaClass)), javaClass); } if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(Object.class); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(String.class, Object.class, context); } if (OptionalInt.class.isAssignableFrom(javaClass) || OptionalLong.class.isAssignableFrom(javaClass) || OptionalDouble.class.isAssignableFrom(javaClass)) { return new Result(TsType.Number.optional()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.getTypeParameters().length > 0) { final List<TsType> tsTypeArguments = new ArrayList<>(); for (int i = 0; i < javaClass.getTypeParameters().length; i++) { tsTypeArguments.add(TsType.Any); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments)); } return new Result(new TsType.ReferenceType(context.getSymbol(javaClass)), javaClass); } if (javaType instanceof ParameterizedType) { final ParameterizedType parameterizedType = (ParameterizedType) javaType; if (parameterizedType.getRawType() instanceof Class) { final Class<?> javaClass = (Class<?>) parameterizedType.getRawType(); if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(parameterizedType.getActualTypeArguments()[0]); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(parameterizedType.getActualTypeArguments()[0], parameterizedType.getActualTypeArguments()[1], context); } if (isAssignableFrom(known.optionalClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType().optional(), result.getDiscoveredClasses()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType(), result.getDiscoveredClasses()); } final List<Class<?>> discoveredClasses = new ArrayList<>(); discoveredClasses.add(javaClass); final List<TsType> tsTypeArguments = new ArrayList<>(); for (Type typeArgument : parameterizedType.getActualTypeArguments()) { final TypeProcessor.Result typeArgumentResult = context.processType(typeArgument); tsTypeArguments.add(typeArgumentResult.getTsType()); discoveredClasses.addAll(typeArgumentResult.getDiscoveredClasses()); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments), discoveredClasses); } } if (javaType instanceof GenericArrayType) { final GenericArrayType genericArrayType = (GenericArrayType) javaType; final Result result = context.processTypeInsideCollection(genericArrayType.getGenericComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) javaType; if (typeVariable.getGenericDeclaration() instanceof Method) { return context.processType(typeVariable.getBounds()[0]); } return new Result(new TsType.GenericVariableType(typeVariable.getName())); } if (javaType instanceof WildcardType) { final WildcardType wildcardType = (WildcardType) javaType; final Type[] upperBounds = wildcardType.getUpperBounds(); return upperBounds.length > 0 ? context.processType(upperBounds[0]) : new Result(TsType.Any); } if (javaType instanceof JUnionType) { final JUnionType unionType = (JUnionType) javaType; final List<Result> results = unionType.getTypes().stream() .map(type -> context.processType(type)) .collect(Collectors.toList()); return new Result( new TsType.UnionType(results.stream() .map(result -> result.getTsType()) .collect(Collectors.toList())), results.stream() .flatMap(result -> result.getDiscoveredClasses().stream()) .collect(Collectors.toList()) ); } if (javaType instanceof JTypeWithNullability) { final JTypeWithNullability typeWithNullability = (JTypeWithNullability) javaType; final Result result = context.processType(typeWithNullability.getType()); return new Result( typeWithNullability.isNullable() ? new TsType.NullableType(result.getTsType()) : result.getTsType(), result.getDiscoveredClasses() ); } return null; } }
DefaultTypeProcessor implements TypeProcessor { @Override public Result processType(Type javaType, Context context) { if (Objects.equals(javaType, Object.class)) { return new Result(TsType.Any); } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.stringClasses, javaClass)) { return new Result(TsType.String); } if (isAssignableFrom(known.numberClasses, javaClass)) { return new Result(TsType.Number); } if (isAssignableFrom(known.booleanClasses, javaClass)) { return new Result(TsType.Boolean); } if (isAssignableFrom(known.dateClasses, javaClass)) { return new Result(TsType.Date); } if (isAssignableFrom(known.voidClasses, javaClass)) { return new Result(TsType.Void); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; final Symbol importedSymbol = context.getSymbolIfImported(javaClass); if (importedSymbol != null) { return new Result(new TsType.ReferenceType(importedSymbol)); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.anyClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.isArray()) { final Result result = context.processTypeInsideCollection(javaClass.getComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaClass.isEnum()) { return new Result(new TsType.EnumReferenceType(context.getSymbol(javaClass)), javaClass); } if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(Object.class); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(String.class, Object.class, context); } if (OptionalInt.class.isAssignableFrom(javaClass) || OptionalLong.class.isAssignableFrom(javaClass) || OptionalDouble.class.isAssignableFrom(javaClass)) { return new Result(TsType.Number.optional()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.getTypeParameters().length > 0) { final List<TsType> tsTypeArguments = new ArrayList<>(); for (int i = 0; i < javaClass.getTypeParameters().length; i++) { tsTypeArguments.add(TsType.Any); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments)); } return new Result(new TsType.ReferenceType(context.getSymbol(javaClass)), javaClass); } if (javaType instanceof ParameterizedType) { final ParameterizedType parameterizedType = (ParameterizedType) javaType; if (parameterizedType.getRawType() instanceof Class) { final Class<?> javaClass = (Class<?>) parameterizedType.getRawType(); if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(parameterizedType.getActualTypeArguments()[0]); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(parameterizedType.getActualTypeArguments()[0], parameterizedType.getActualTypeArguments()[1], context); } if (isAssignableFrom(known.optionalClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType().optional(), result.getDiscoveredClasses()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType(), result.getDiscoveredClasses()); } final List<Class<?>> discoveredClasses = new ArrayList<>(); discoveredClasses.add(javaClass); final List<TsType> tsTypeArguments = new ArrayList<>(); for (Type typeArgument : parameterizedType.getActualTypeArguments()) { final TypeProcessor.Result typeArgumentResult = context.processType(typeArgument); tsTypeArguments.add(typeArgumentResult.getTsType()); discoveredClasses.addAll(typeArgumentResult.getDiscoveredClasses()); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments), discoveredClasses); } } if (javaType instanceof GenericArrayType) { final GenericArrayType genericArrayType = (GenericArrayType) javaType; final Result result = context.processTypeInsideCollection(genericArrayType.getGenericComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) javaType; if (typeVariable.getGenericDeclaration() instanceof Method) { return context.processType(typeVariable.getBounds()[0]); } return new Result(new TsType.GenericVariableType(typeVariable.getName())); } if (javaType instanceof WildcardType) { final WildcardType wildcardType = (WildcardType) javaType; final Type[] upperBounds = wildcardType.getUpperBounds(); return upperBounds.length > 0 ? context.processType(upperBounds[0]) : new Result(TsType.Any); } if (javaType instanceof JUnionType) { final JUnionType unionType = (JUnionType) javaType; final List<Result> results = unionType.getTypes().stream() .map(type -> context.processType(type)) .collect(Collectors.toList()); return new Result( new TsType.UnionType(results.stream() .map(result -> result.getTsType()) .collect(Collectors.toList())), results.stream() .flatMap(result -> result.getDiscoveredClasses().stream()) .collect(Collectors.toList()) ); } if (javaType instanceof JTypeWithNullability) { final JTypeWithNullability typeWithNullability = (JTypeWithNullability) javaType; final Result result = context.processType(typeWithNullability.getType()); return new Result( typeWithNullability.isNullable() ? new TsType.NullableType(result.getTsType()) : result.getTsType(), result.getDiscoveredClasses() ); } return null; } DefaultTypeProcessor();  DefaultTypeProcessor(LoadedDataLibraries dataLibraries); }
DefaultTypeProcessor implements TypeProcessor { @Override public Result processType(Type javaType, Context context) { if (Objects.equals(javaType, Object.class)) { return new Result(TsType.Any); } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.stringClasses, javaClass)) { return new Result(TsType.String); } if (isAssignableFrom(known.numberClasses, javaClass)) { return new Result(TsType.Number); } if (isAssignableFrom(known.booleanClasses, javaClass)) { return new Result(TsType.Boolean); } if (isAssignableFrom(known.dateClasses, javaClass)) { return new Result(TsType.Date); } if (isAssignableFrom(known.voidClasses, javaClass)) { return new Result(TsType.Void); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; final Symbol importedSymbol = context.getSymbolIfImported(javaClass); if (importedSymbol != null) { return new Result(new TsType.ReferenceType(importedSymbol)); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.anyClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.isArray()) { final Result result = context.processTypeInsideCollection(javaClass.getComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaClass.isEnum()) { return new Result(new TsType.EnumReferenceType(context.getSymbol(javaClass)), javaClass); } if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(Object.class); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(String.class, Object.class, context); } if (OptionalInt.class.isAssignableFrom(javaClass) || OptionalLong.class.isAssignableFrom(javaClass) || OptionalDouble.class.isAssignableFrom(javaClass)) { return new Result(TsType.Number.optional()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.getTypeParameters().length > 0) { final List<TsType> tsTypeArguments = new ArrayList<>(); for (int i = 0; i < javaClass.getTypeParameters().length; i++) { tsTypeArguments.add(TsType.Any); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments)); } return new Result(new TsType.ReferenceType(context.getSymbol(javaClass)), javaClass); } if (javaType instanceof ParameterizedType) { final ParameterizedType parameterizedType = (ParameterizedType) javaType; if (parameterizedType.getRawType() instanceof Class) { final Class<?> javaClass = (Class<?>) parameterizedType.getRawType(); if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(parameterizedType.getActualTypeArguments()[0]); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(parameterizedType.getActualTypeArguments()[0], parameterizedType.getActualTypeArguments()[1], context); } if (isAssignableFrom(known.optionalClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType().optional(), result.getDiscoveredClasses()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType(), result.getDiscoveredClasses()); } final List<Class<?>> discoveredClasses = new ArrayList<>(); discoveredClasses.add(javaClass); final List<TsType> tsTypeArguments = new ArrayList<>(); for (Type typeArgument : parameterizedType.getActualTypeArguments()) { final TypeProcessor.Result typeArgumentResult = context.processType(typeArgument); tsTypeArguments.add(typeArgumentResult.getTsType()); discoveredClasses.addAll(typeArgumentResult.getDiscoveredClasses()); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments), discoveredClasses); } } if (javaType instanceof GenericArrayType) { final GenericArrayType genericArrayType = (GenericArrayType) javaType; final Result result = context.processTypeInsideCollection(genericArrayType.getGenericComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) javaType; if (typeVariable.getGenericDeclaration() instanceof Method) { return context.processType(typeVariable.getBounds()[0]); } return new Result(new TsType.GenericVariableType(typeVariable.getName())); } if (javaType instanceof WildcardType) { final WildcardType wildcardType = (WildcardType) javaType; final Type[] upperBounds = wildcardType.getUpperBounds(); return upperBounds.length > 0 ? context.processType(upperBounds[0]) : new Result(TsType.Any); } if (javaType instanceof JUnionType) { final JUnionType unionType = (JUnionType) javaType; final List<Result> results = unionType.getTypes().stream() .map(type -> context.processType(type)) .collect(Collectors.toList()); return new Result( new TsType.UnionType(results.stream() .map(result -> result.getTsType()) .collect(Collectors.toList())), results.stream() .flatMap(result -> result.getDiscoveredClasses().stream()) .collect(Collectors.toList()) ); } if (javaType instanceof JTypeWithNullability) { final JTypeWithNullability typeWithNullability = (JTypeWithNullability) javaType; final Result result = context.processType(typeWithNullability.getType()); return new Result( typeWithNullability.isNullable() ? new TsType.NullableType(result.getTsType()) : result.getTsType(), result.getDiscoveredClasses() ); } return null; } DefaultTypeProcessor();  DefaultTypeProcessor(LoadedDataLibraries dataLibraries); @Override Result processType(Type javaType, Context context); }
DefaultTypeProcessor implements TypeProcessor { @Override public Result processType(Type javaType, Context context) { if (Objects.equals(javaType, Object.class)) { return new Result(TsType.Any); } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.stringClasses, javaClass)) { return new Result(TsType.String); } if (isAssignableFrom(known.numberClasses, javaClass)) { return new Result(TsType.Number); } if (isAssignableFrom(known.booleanClasses, javaClass)) { return new Result(TsType.Boolean); } if (isAssignableFrom(known.dateClasses, javaClass)) { return new Result(TsType.Date); } if (isAssignableFrom(known.voidClasses, javaClass)) { return new Result(TsType.Void); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; final Symbol importedSymbol = context.getSymbolIfImported(javaClass); if (importedSymbol != null) { return new Result(new TsType.ReferenceType(importedSymbol)); } } if (javaType instanceof Class) { final Class<?> javaClass = (Class<?>) javaType; if (isAssignableFrom(known.anyClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.isArray()) { final Result result = context.processTypeInsideCollection(javaClass.getComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaClass.isEnum()) { return new Result(new TsType.EnumReferenceType(context.getSymbol(javaClass)), javaClass); } if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(Object.class); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(String.class, Object.class, context); } if (OptionalInt.class.isAssignableFrom(javaClass) || OptionalLong.class.isAssignableFrom(javaClass) || OptionalDouble.class.isAssignableFrom(javaClass)) { return new Result(TsType.Number.optional()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { return new Result(TsType.Any); } if (javaClass.getTypeParameters().length > 0) { final List<TsType> tsTypeArguments = new ArrayList<>(); for (int i = 0; i < javaClass.getTypeParameters().length; i++) { tsTypeArguments.add(TsType.Any); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments)); } return new Result(new TsType.ReferenceType(context.getSymbol(javaClass)), javaClass); } if (javaType instanceof ParameterizedType) { final ParameterizedType parameterizedType = (ParameterizedType) javaType; if (parameterizedType.getRawType() instanceof Class) { final Class<?> javaClass = (Class<?>) parameterizedType.getRawType(); if (isAssignableFrom(known.listClasses, javaClass)) { final Result result = context.processTypeInsideCollection(parameterizedType.getActualTypeArguments()[0]); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (isAssignableFrom(known.mapClasses, javaClass)) { return processMapType(parameterizedType.getActualTypeArguments()[0], parameterizedType.getActualTypeArguments()[1], context); } if (isAssignableFrom(known.optionalClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType().optional(), result.getDiscoveredClasses()); } if (isAssignableFrom(known.wrapperClasses, javaClass)) { final Result result = context.processType(parameterizedType.getActualTypeArguments()[0]); return new Result(result.getTsType(), result.getDiscoveredClasses()); } final List<Class<?>> discoveredClasses = new ArrayList<>(); discoveredClasses.add(javaClass); final List<TsType> tsTypeArguments = new ArrayList<>(); for (Type typeArgument : parameterizedType.getActualTypeArguments()) { final TypeProcessor.Result typeArgumentResult = context.processType(typeArgument); tsTypeArguments.add(typeArgumentResult.getTsType()); discoveredClasses.addAll(typeArgumentResult.getDiscoveredClasses()); } return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments), discoveredClasses); } } if (javaType instanceof GenericArrayType) { final GenericArrayType genericArrayType = (GenericArrayType) javaType; final Result result = context.processTypeInsideCollection(genericArrayType.getGenericComponentType()); return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses()); } if (javaType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) javaType; if (typeVariable.getGenericDeclaration() instanceof Method) { return context.processType(typeVariable.getBounds()[0]); } return new Result(new TsType.GenericVariableType(typeVariable.getName())); } if (javaType instanceof WildcardType) { final WildcardType wildcardType = (WildcardType) javaType; final Type[] upperBounds = wildcardType.getUpperBounds(); return upperBounds.length > 0 ? context.processType(upperBounds[0]) : new Result(TsType.Any); } if (javaType instanceof JUnionType) { final JUnionType unionType = (JUnionType) javaType; final List<Result> results = unionType.getTypes().stream() .map(type -> context.processType(type)) .collect(Collectors.toList()); return new Result( new TsType.UnionType(results.stream() .map(result -> result.getTsType()) .collect(Collectors.toList())), results.stream() .flatMap(result -> result.getDiscoveredClasses().stream()) .collect(Collectors.toList()) ); } if (javaType instanceof JTypeWithNullability) { final JTypeWithNullability typeWithNullability = (JTypeWithNullability) javaType; final Result result = context.processType(typeWithNullability.getType()); return new Result( typeWithNullability.isNullable() ? new TsType.NullableType(result.getTsType()) : result.getTsType(), result.getDiscoveredClasses() ); } return null; } DefaultTypeProcessor();  DefaultTypeProcessor(LoadedDataLibraries dataLibraries); @Override Result processType(Type javaType, Context context);  }