https://kotlinlang.org logo
#getting-started
Title
# getting-started
i

igor.wojda

03/15/2023, 1:32 PM
I am parsing Kotlin file using
org.jetbrains.kotlin:kotlin-compiler:1.8.10
lib I am getting instance of
KtFile
then instance of
KtClass
and finally instance of KtNamedFunction. I can verify: • function name -
ktNamedFunction.name == "invoke"
• function visibility
ktNamedFunction.isPublic
I wonder how can I checks if this function is
operator
(or
invoke operator
) ?
Copy code
class Foo() {
    operator fun invoke(taskId: TaskId) {
        
    }
}
w

Wout Werkman

03/15/2023, 1:49 PM
From what I understand it's only available on
KFunction
, not on
KFunction1
.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-function/
a

Albert Chang

03/15/2023, 2:12 PM
OP is talking about PSI, which is totally different from kotlin reflect. To answer the question, maybe
ktNamedFunction.modifierList?.hasModifier(KtTokens.OPERATOR_KEYWORD) == true
?
🙌 1
i

igor.wojda

03/15/2023, 2:15 PM
this is what I need thx Albert
👍 1
4 Views