Kapt: Return substituted supertypes in directSupertypes() for immediate class types (KT-13746)
(cherry picked from commit 3aae990) (cherry picked from commit 198115b)
This commit is contained in:
committed by
Yan Zhulanow
parent
8d2a4c3f91
commit
f7f8cff00d
+7
-1
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.annotation.processing.impl
|
package org.jetbrains.kotlin.annotation.processing.impl
|
||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
|
import com.intellij.psi.impl.source.PsiImmediateClassType
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.util.*
|
import com.intellij.psi.util.*
|
||||||
import org.jetbrains.kotlin.java.model.JeElement
|
import org.jetbrains.kotlin.java.model.JeElement
|
||||||
@@ -124,7 +125,12 @@ class KotlinTypes(val javaPsiFacade: JavaPsiFacade, val psiManager: PsiManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun directSupertypes(t: TypeMirror): List<TypeMirror> {
|
override fun directSupertypes(t: TypeMirror): List<TypeMirror> {
|
||||||
if (t is NoType) throw IllegalArgumentException("Invalid type: $t")
|
if (t is NoType || t is ExecutableType) throw IllegalArgumentException("Invalid type: $t")
|
||||||
|
|
||||||
|
if (t is JeDeclaredType && t.psiType is PsiImmediateClassType) {
|
||||||
|
return t.psiClass.superTypes.map { it.toJeType(psiManager) }
|
||||||
|
}
|
||||||
|
|
||||||
val psiType = (t as? JePsiType)?.psiType as? PsiClassType ?: return emptyList()
|
val psiType = (t as? JePsiType)?.psiType as? PsiClassType ?: return emptyList()
|
||||||
return psiType.superTypes.map { it.toJeType(psiManager) }
|
return psiType.superTypes.map { it.toJeType(psiManager) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,8 @@ annotation class Anno
|
|||||||
@Anno
|
@Anno
|
||||||
class B : A<String>()
|
class B : A<String>()
|
||||||
|
|
||||||
class C<T : CharSequence> : A<T>()
|
class C<T : CharSequence> : A<T>()
|
||||||
|
|
||||||
|
interface I2<X>
|
||||||
|
open class B2<X>
|
||||||
|
class A2<T : CharSequence> : B2<T>(), I2<T>
|
||||||
+4
@@ -157,6 +157,10 @@ class ProcessorTests : AbstractProcessorTest() {
|
|||||||
assertEquals(1, cai.typeArguments.size)
|
assertEquals(1, cai.typeArguments.size)
|
||||||
val typeArg = cai.typeArguments.first()
|
val typeArg = cai.typeArguments.first()
|
||||||
assertTrue(typeArg is TypeVariable)
|
assertTrue(typeArg is TypeVariable)
|
||||||
|
|
||||||
|
val a2 = env.findClass("A2")
|
||||||
|
val i2 = env.typeUtils.directSupertypes(a2.asType()).first { it.toString().matches("I2(<.*>)?".toRegex()) } as JeDeclaredType
|
||||||
|
assertEquals("I2<T>", i2.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testErasureSimple() = test("ErasureSimple", "*") { set, roundEnv, env ->
|
fun testErasureSimple() = test("ErasureSimple", "*") { set, roundEnv, env ->
|
||||||
|
|||||||
Reference in New Issue
Block a user