Is there a performance implication when casting source psi to language specific psi?

Answered

I was wondering if this casting is okay to have, in cases where i know i only will be dealing with kotlin source code. 

override fun createUastHandler(context: JavaContext): UElementHandler {
  return object : UElementHandler() {
    override fun visitMethod(node: UMethod) {
      val ktFunc = node.sourcePsi?.cast<KtFunction>() ?: return

Can it have any performance implications or any other issues, if i cast sourcepsi to kotlin specific psi?

2 comments
Comment actions Permalink

Hi,

If you know you are dealing with the Kotlin code only, then what's the reason for using UAST?

Technically, I don't see any issues with this cast in your code.

0
Comment actions Permalink

Yeah, i thought the same, technically it should be fine. I was working on an existing android-lint for jet-pack compose, which extends from Uast, somewhere down the line i casted it back to kotlin psi and i was wondering if it can have any over-head.

I agree with directly working on language specific psi, but wanted to understand if in uast tree, if we do cast back to language specific psi at any point, would it have any perf issues.

 

Thanks for clarifying.

0

Please sign in to leave a comment.