小编ZSp*_*tus的帖子

从 Kotlin Psi API 检索继承类全名

我\xe2\x80\x99m 尝试开发一个codegen IDEA-Plugin。这个插件应该分析KtClass继承并获取所有继承类的全名(例如 com.example.config.TestConfig)

\n

我尝试通过查看 PsiViewer 来查找任何有用的信息。我发现KtClass的所有继承信息都存储在 中KtSuperTypeEntry,并且我尽力获取继承类的全名。

\n

上课Dest

\n
data class Dest(\n    val stringValue: String = "123",\n    override val stringConfig: String = "123",\n    override val iConfigStr: String = "123",\n    val b: B = B(),\n    val c: List<List<Set<Map<String, out Any?>>>> = listOf(),\n    val config: Config? = Config()\n) : Config()\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. superTypeListEntry.typeAsUserType.referenceExpression.getReferencedName() -return->"Config"
  2. \n
  3. superTypeListEntry.importReceiverMembers() -return->null
  4. \n
\n

看起来SuperTypeListEntry只包含继承类的简单名称信息。

\n

我还尝试通过 KtFile 查找继承类全名,但不知道继承类何时作为通配符在此 KtFile 中导入:

\n
fun KtSuperTypeListEntry.getType(ktFile: KtFile): String …
Run Code Online (Sandbox Code Playgroud)

compiler-construction intellij-plugin kotlin intellij-platform-psi

6
推荐指数
1
解决办法
817
查看次数