Kapt: Fix erasure() for immediate class types (KT-13748)
(cherry picked from commit 5fe01f6)
This commit is contained in:
+17
-6
@@ -22,18 +22,29 @@ import javax.lang.model.type.ArrayType
|
||||
import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeArrayType(override val psiType: PsiArrayType, override val psiManager: PsiManager) : JePsiType(), JeTypeWithManager, ArrayType {
|
||||
class JeArrayType(
|
||||
override val psiType: PsiArrayType,
|
||||
override val psiManager: PsiManager,
|
||||
private val isRaw: Boolean
|
||||
) : JePsiType(), JeTypeWithManager, ArrayType {
|
||||
override fun getKind() = TypeKind.ARRAY
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitArray(this, p)
|
||||
override fun getComponentType() = psiType.componentType.toJeType(psiManager)
|
||||
override fun getComponentType() = psiType.componentType.toJeType(psiManager, isRaw = isRaw)
|
||||
|
||||
override fun toString() = psiType.getCanonicalText(false)
|
||||
|
||||
override fun equals(other: Any?): Boolean{
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
return componentType == (other as? JeArrayType)?.componentType
|
||||
other as? JeArrayType ?: return false
|
||||
|
||||
return componentType == other.componentType
|
||||
&& isRaw == other.isRaw
|
||||
}
|
||||
|
||||
override fun hashCode() = componentType.hashCode()
|
||||
override fun hashCode(): Int {
|
||||
var result = componentType.hashCode()
|
||||
result = 31 * result + isRaw.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -39,7 +39,8 @@ fun createDeclaredType(psiClass: PsiClass, typeArgs: List<PsiType>): PsiClassRef
|
||||
class JeDeclaredType(
|
||||
override val psiType: PsiClassType,
|
||||
val psiClass: PsiClass,
|
||||
val enclosingDeclaredType: DeclaredType? = null
|
||||
val enclosingDeclaredType: DeclaredType? = null,
|
||||
val isRaw: Boolean = false
|
||||
) : JePsiType(), JeTypeWithManager, DeclaredType {
|
||||
override fun getKind() = TypeKind.DECLARED
|
||||
|
||||
@@ -52,6 +53,8 @@ class JeDeclaredType(
|
||||
return when (psiType) {
|
||||
is PsiClassReferenceType -> psiType.parameters.map { it.toJeType(psiManager) }
|
||||
is PsiClassType -> {
|
||||
if (isRaw) return emptyList()
|
||||
|
||||
val substitutor = psiType.resolveGenerics().substitutor
|
||||
val psiClass = psiType.resolve() ?: return psiType.parameters.map { it.toJeType(psiManager) }
|
||||
|
||||
@@ -89,14 +92,24 @@ class JeDeclaredType(
|
||||
return enclosingType == other.enclosingType
|
||||
&& psiClass == other.psiClass
|
||||
&& typeArguments == other.typeArguments
|
||||
&& isRaw == other.isRaw
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = enclosingType.hashCode()
|
||||
result = 31 * result + psiClass.hashCode()
|
||||
result = 31 * result + typeArguments.hashCode()
|
||||
result = 31 * result + isRaw.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString() = psiType.getCanonicalText(false)
|
||||
override fun toString() = buildString {
|
||||
append(psiClass.qualifiedName ?: psiClass.name)
|
||||
val typeArgs = typeArguments
|
||||
if (typeArgs.isNotEmpty()) {
|
||||
append('<')
|
||||
append(typeArguments.joinToString(","))
|
||||
append('>')
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-4
@@ -24,18 +24,28 @@ import javax.lang.model.type.TypeVisitor
|
||||
|
||||
class JeIntersectionType(
|
||||
override val psiType: PsiIntersectionType,
|
||||
override val psiManager: PsiManager
|
||||
override val psiManager: PsiManager,
|
||||
private val isRaw: Boolean
|
||||
) : JePsiType(), JeTypeWithManager, IntersectionType {
|
||||
override fun getKind() = TypeKind.INTERSECTION
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitIntersection(this, p)
|
||||
|
||||
override fun getBounds() = psiType.superTypes.map { it.toJeType(psiManager) }
|
||||
override fun getBounds() = psiType.superTypes.map { it.toJeType(psiManager, isRaw = isRaw) }
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
return bounds == (other as? JeIntersectionType)?.bounds
|
||||
other as? JeIntersectionType ?: return false
|
||||
|
||||
return bounds == other.bounds
|
||||
&& isRaw == other.isRaw
|
||||
}
|
||||
|
||||
override fun hashCode() = bounds.hashCode()
|
||||
override fun hashCode(): Int {
|
||||
var result = bounds.hashCode()
|
||||
result = 31 * result + isRaw.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString() = bounds.joinToString("&")
|
||||
}
|
||||
+7
-5
@@ -30,27 +30,29 @@ import javax.lang.model.type.TypeVisitor
|
||||
class JeMethodExecutableTypeMirror(
|
||||
val psi: PsiMethod,
|
||||
val signature: MethodSignature? = null,
|
||||
val returnType: PsiType? = null
|
||||
val returnType: PsiType? = null,
|
||||
val isRaw: Boolean = false
|
||||
) : JeTypeMirror, JeTypeWithManager, ExecutableType {
|
||||
override fun getKind() = TypeKind.EXECUTABLE
|
||||
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitExecutable(this, p)
|
||||
|
||||
override fun getReturnType() = (returnType ?: psi.returnType)?.let { it.toJeType(psi.manager) } ?: JeVoidType
|
||||
override fun getReturnType() = (returnType ?: psi.returnType)?.let { it.toJeType(psi.manager, isRaw = isRaw) } ?: JeVoidType
|
||||
|
||||
override fun getReceiverType() = psi.getReceiverTypeMirror()
|
||||
|
||||
override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType(psi.manager) }
|
||||
override fun getThrownTypes() = psi.throwsList.referencedTypes.map { it.toJeType(psi.manager, isRaw = isRaw) }
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = psi.manager
|
||||
|
||||
override fun getParameterTypes(): List<TypeMirror> {
|
||||
signature?.parameterTypes?.let { types -> return types.map { it.toJeType(psi.manager) } }
|
||||
return psi.parameterList.parameters.map { it.type.toJeType(psi.manager) }
|
||||
signature?.parameterTypes?.let { types -> return types.map { it.toJeType(psi.manager, isRaw = isRaw) } }
|
||||
return psi.parameterList.parameters.map { it.type.toJeType(psi.manager, isRaw = isRaw) }
|
||||
}
|
||||
|
||||
override fun getTypeVariables(): List<JeTypeVariableType> {
|
||||
if (isRaw) return emptyList()
|
||||
val typeParameters = signature?.typeParameters ?: psi.typeParameters
|
||||
return typeParameters.map { JeTypeVariableType(PsiTypesUtil.getClassType(it), it) }
|
||||
}
|
||||
|
||||
+45
-11
@@ -23,40 +23,74 @@ import javax.lang.model.type.TypeKind
|
||||
import javax.lang.model.type.TypeVisitor
|
||||
import javax.lang.model.type.WildcardType
|
||||
|
||||
class JeWildcardType(override val psiType: PsiWildcardType) : JePsiType(), JeTypeWithManager, WildcardType {
|
||||
class JeWildcardType(
|
||||
override val psiType: PsiWildcardType,
|
||||
private val isRaw: Boolean
|
||||
) : JePsiType(), JeTypeWithManager, WildcardType {
|
||||
override fun getKind() = TypeKind.WILDCARD
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitWildcard(this, p)
|
||||
|
||||
override fun getSuperBound() = psiType.superBound.toJeType(psiManager)
|
||||
override fun getExtendsBound() = psiType.extendsBound.toJeType(psiManager)
|
||||
override fun getSuperBound() = psiType.superBound.toJeType(psiManager, isRaw = isRaw)
|
||||
override fun getExtendsBound() = psiType.extendsBound.toJeType(psiManager, isRaw = isRaw)
|
||||
|
||||
override val psiManager: PsiManager
|
||||
get() = psiType.manager
|
||||
|
||||
override fun equals(other: Any?): Boolean{
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
return psiType == (other as? JeWildcardType)?.psiType
|
||||
other as? JeWildcardType ?: return false
|
||||
|
||||
return superBound == other.superBound
|
||||
&& extendsBound == other.extendsBound
|
||||
&& isRaw == other.isRaw
|
||||
}
|
||||
|
||||
override fun hashCode() = psiType.hashCode()
|
||||
override fun hashCode(): Int {
|
||||
var result = superBound.hashCode()
|
||||
result = 31 * result + extendsBound.hashCode()
|
||||
result = 31 * result + isRaw.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString() = when {
|
||||
psiType.isExtends -> "? extends $extendsBound"
|
||||
psiType.isSuper -> "? super $superBound"
|
||||
else -> "?"
|
||||
}
|
||||
}
|
||||
|
||||
class JeCapturedWildcardType(
|
||||
override val psiType: PsiCapturedWildcardType,
|
||||
override val psiManager: PsiManager
|
||||
override val psiManager: PsiManager,
|
||||
private val isRaw: Boolean
|
||||
) : JePsiType(), JeTypeWithManager, WildcardType {
|
||||
override fun getKind() = TypeKind.WILDCARD
|
||||
override fun <R : Any?, P : Any?> accept(v: TypeVisitor<R, P>, p: P) = v.visitWildcard(this, p)
|
||||
|
||||
override fun getSuperBound() = psiType.lowerBound.toJeType(psiManager)
|
||||
override fun getExtendsBound() = psiType.upperBound.toJeType(psiManager)
|
||||
override fun getSuperBound() = psiType.lowerBound.toJeType(psiManager, isRaw = isRaw)
|
||||
override fun getExtendsBound() = psiType.upperBound.toJeType(psiManager, isRaw = isRaw)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other?.javaClass != javaClass) return false
|
||||
return psiType == (other as? JeWildcardType)?.psiType
|
||||
other as? JeCapturedWildcardType ?: return false
|
||||
|
||||
return superBound == other.superBound
|
||||
&& extendsBound == other.extendsBound
|
||||
&& isRaw == other.isRaw
|
||||
}
|
||||
|
||||
override fun hashCode() = psiType.hashCode()
|
||||
override fun hashCode(): Int {
|
||||
var result = superBound.hashCode()
|
||||
result = 31 * result + extendsBound.hashCode()
|
||||
result = 31 * result + isRaw.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toString() = when {
|
||||
psiType.wildcard.isSuper -> "? extends $extendsBound"
|
||||
psiType.wildcard.isExtends -> "? super $superBound"
|
||||
else -> "?"
|
||||
}
|
||||
}
|
||||
@@ -42,22 +42,21 @@ fun TypeKind?.toJePrimitiveType() = PSI_PRIMITIVES_MAP[TYPE_KIND_TO_PSI_PRIMITIV
|
||||
|
||||
fun PsiType.toJePrimitiveType() = PSI_PRIMITIVES_MAP[this]
|
||||
|
||||
fun PsiType.toJeType(manager: PsiManager): TypeMirror = when (this) {
|
||||
fun PsiType.toJeType(manager: PsiManager, isRaw: Boolean = false): TypeMirror = when (this) {
|
||||
PsiType.VOID -> JeVoidType
|
||||
PsiType.NULL -> JeNullType
|
||||
is PsiPrimitiveType -> PSI_PRIMITIVES_MAP[this] ?: JeErrorType
|
||||
is PsiArrayType -> JeArrayType(this, manager)
|
||||
is PsiWildcardType -> JeWildcardType(this)
|
||||
is PsiCapturedWildcardType -> JeCapturedWildcardType(this, manager)
|
||||
is PsiArrayType -> JeArrayType(this, manager, isRaw)
|
||||
is PsiWildcardType -> JeWildcardType(this, isRaw)
|
||||
is PsiCapturedWildcardType -> JeCapturedWildcardType(this, manager, isRaw)
|
||||
is PsiClassType -> {
|
||||
val resolvedClass = this.resolve()
|
||||
when (resolvedClass) {
|
||||
is PsiTypeParameter -> JeTypeVariableType(this, resolvedClass)
|
||||
is PsiClass -> JeDeclaredType(this, resolvedClass)
|
||||
is PsiClass -> JeDeclaredType(this, resolvedClass, isRaw = isRaw)
|
||||
else -> JeErrorType
|
||||
}
|
||||
}
|
||||
is PsiIntersectionType -> JeIntersectionType(this, manager)
|
||||
is PsiIntersectionType -> JeIntersectionType(this, manager, isRaw)
|
||||
else -> JeErrorType
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user