[Intellij IDEA Plugin Development]How can I detect a KtReference represented class is sub type of specified class? Follow
Answered
Hello, I am writing a codegen IDEA Plugin. But I'm stuck into detecting whether a KtDeclaration represented class is sub type of kotlin.collections.Collection .
When I receive a KtDeclaration, I can get KotlinType by this extension function:
fun KtDeclaration.type(): KotlinType? { ... }
KotlinType also provider other extension function to detect whether the represented class is sub type of other KotlinType's :
fun KotlinType.isSubtypeOf(superType: KotlinType): Boolean
But I have no idea to create an instance of KotlinType which represented class is kotlin.collections.Collection.
I have no idea whether this way is correct.
It there any better way to detect whether a KtDeclaration represented class is sub type of kotlin.collections.Collection?
Thank you! :)
Please sign in to leave a comment.
Finally, I find that in org.jetbrains.kotlin.types.typeUtil.TypeUtils.kt, there is a extensions function named KotlinType.supertypes()
which meet my needs.