Коммит f1612a49 создал по автору Leonid Stashevsky's avatar Leonid Stashevsky
Просмотр файлов

Make TypeInfo data class, add tests

 - #459 #471
владелец e07ca10d
version=0.9.4-SNAPSHOT
kotlin_version=1.2.50
kotlin_version=1.2.51
coroutines_version=0.23.3-dev-1
dokka_version=0.9.16
......
......@@ -3,11 +3,19 @@ package io.ktor.client.call
import java.lang.reflect.*
import kotlin.reflect.*
class TypeInfo(val type: KClass<*>, val reifiedType: Type)
/**
* Ktor type information.
* [type]: source KClass<*>
* [reifiedType]: type with substituted generics
*/
data class TypeInfo(val type: KClass<*>, val reifiedType: Type)
@PublishedApi()
internal open class TypeBase<T>
/**
* Create typeInfo from <T>
*/
inline fun <reified T> typeInfo(): TypeInfo {
val base = object : TypeBase<T>() {}
val superType = base::class.java.genericSuperclass!!
......
package io.ktor.client.tests.features.cookies
import io.ktor.client.call.*
import kotlin.test.*
class TypeInfoTest {
@Test
fun classInMethodTest() {
class Foo
typeInfo<Foo>()
}
@Test
@Ignore
fun `type info with class defined in method scope with complex name`() {
class SomeClass
typeInfo<SomeClass>()
}
@Test
fun equalsTest() {
class Foo<Bar>
assertEquals(typeInfo<Foo<Int>>(), typeInfo<Foo<Int>>())
assertNotEquals(typeInfo<Foo<String>>(), typeInfo<Foo<Int>>())
assertNotEquals(typeInfo<Foo<Int>>(), typeInfo<Foo<Char>>())
}
}
\ Нет новой строки в конце файла
......@@ -70,7 +70,7 @@ internal class JettyResponseListener(
onHeadersReceived.complete((frame.metaData as? MetaData.Response)?.let {
val (status, reason) = it.status to it.reason
reason?.let { HttpStatusCode(status, reason) } ?: HttpStatusCode.fromValue(status)
reason?.let { HttpStatusCode(status, it) } ?: HttpStatusCode.fromValue(status)
})
}
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать