Skip to content

Reimplement ParameterizedType #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/kotlin/graphql/kickstart/tools/GenericType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ internal open class GenericType(protected val mostSpecificType: JavaType, protec
return when (type) {
is ParameterizedType -> {
val actualTypeArguments = type.actualTypeArguments.map { replaceTypeVariable(it) }.toTypedArray()
ParameterizedTypeImpl.make(type.rawType as Class<*>?, actualTypeArguments, type.ownerType)
ParameterizedTypeImpl(type.rawType as Class<*>, actualTypeArguments, type.ownerType)
}
is ResolvedType -> {
if (type.typeParameters.isEmpty()) {
type.erasedType
} else {
val actualTypeArguments = type.typeParameters.map { replaceTypeVariable(it) }.toTypedArray()
ParameterizedTypeImpl.make(type.erasedType, actualTypeArguments, null)
ParameterizedTypeImpl(type.erasedType, actualTypeArguments, null)
}
}
is TypeVariable<*> -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,9 @@ data class SchemaParserOptions internal constructor(
index: Int,
transformer: (T) -> Any?
): GenericWrapper where T : Any {
return withTransformer(
type,
index,
transformer,
{ innerType -> ParameterizedTypeImpl.make(List::class.java, arrayOf(innerType), null) }
)
return withTransformer(type, index, transformer) { innerType ->
ParameterizedTypeImpl(List::class.java, arrayOf(innerType), null)
}
}

fun <T> listCollectionWithTransformer(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package graphql.kickstart.tools.util

import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type

class ParameterizedTypeImpl(
private val rawType: Class<*>,
private val actualTypeArguments: Array<Type>,
private val ownerType: Type?
) : ParameterizedType {
override fun getActualTypeArguments(): Array<Type> = actualTypeArguments.clone()

override fun getRawType(): Type = rawType

override fun getOwnerType(): Type? = ownerType

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as ParameterizedTypeImpl

if (rawType != other.rawType) return false
if (ownerType != other.ownerType) return false
if (!actualTypeArguments.contentEquals(other.actualTypeArguments)) return false

return true
}

override fun hashCode(): Int {
var result = rawType.hashCode()
result = 31 * result + (ownerType?.hashCode() ?: 0)
result = 31 * result + actualTypeArguments.contentHashCode()
return result
}

override fun toString(): String = buildString {
if (ownerType != null) {
append(ownerType.typeName)
append("$")
append(rawType.simpleName)
} else {
append(rawType.name)
}
if (actualTypeArguments.isNotEmpty()) {
actualTypeArguments.joinTo(this, ",", "<", ">", transform = Type::getTypeName)
}
}
}