[英]How to get the type information of the ktExpression using kotlin PSI?
class Baz {
}
class Foo {
fun anotherAction() : Baz {
return Baz()
}
}
class Bar {
fun doAction() : Foo {
return Foo()
}
}
fun main() {
Bar()
.doAction()
.doAnotherAction()
}
Is there a way using kotlin PSI to get info about the type of the Bar().doAction()
expression?有没有办法使用 kotlin PSI 来获取有关
Bar().doAction()
表达式类型的信息? I need to figure out that return type of Bar().doAction()
or doAction()
is Foo
or that doAnotherAction
is a function of the class Foo
.我需要弄清楚
Bar().doAction()
或doAction()
的返回类型是Foo
或者doAnotherAction
是类Foo
的函数。 Basically, I'm trying to get the types of the KtExpression
-s基本上,我正在尝试获取
KtExpression
-s 的类型
I have BindingContext
generated (even though with some warnings) but trying to access the type info of the expression always returns null.我生成了
BindingContext
(即使有一些警告),但尝试访问表达式的类型信息总是返回 null。 I tried to use getResolvedCall(BindingContext)
and getCall(bindingContext)
but it also always returns null.我尝试使用
getResolvedCall(BindingContext)
和getCall(bindingContext)
但它也总是返回 null。
Also, accessing references
and reference
in the the above code expressions: KtDotQualifiedExpression
and KtCallExpression
also returns null.此外,访问上述代码表达式中的
references
和reference
: KtDotQualifiedExpression
和KtCallExpression
也返回 null。
BindingContext
生成正确,我使用了错误的文件和未分析的 psi 访问者,因此未包含在我使用的BindingContext
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.