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:
Yan Zhulanow
2016-09-09 23:52:56 +03:00
committed by Yan Zhulanow
parent 8d2a4c3f91
commit f7f8cff00d
3 changed files with 16 additions and 2 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.annotation.processing.impl
import com.intellij.psi.*
import com.intellij.psi.impl.source.PsiImmediateClassType
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.*
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> {
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()
return psiType.superTypes.map { it.toJeType(psiManager) }
}
@@ -7,4 +7,8 @@ annotation class Anno
@Anno
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>
@@ -157,6 +157,10 @@ class ProcessorTests : AbstractProcessorTest() {
assertEquals(1, cai.typeArguments.size)
val typeArg = cai.typeArguments.first()
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 ->