How to check if PsiElement is a kotlin constant


I'm currently trying to solve KTIJ-4841 (Introduce const for Kotlin) and have a basic working version.
Current problem is that my current implementation of determining whether a PsiElement is a compile time constant, is very lacking and not working for `1 + 1`.

I found `CompileTimeConstantChecker` which looks like the right fit, but I could not figure out how to to instantiate it, because of the constructor Parameters.

So either how do I instatiate the above class inside a `RefactoringActionHandler` or how to properly check if an PsiElement is constant?

Comment actions Permalink

There is quite useful action View PSI Structure that is enabled in so-called internal mode :

so, `1` has a node type is KtNodeTypes.INTEGER_CONSTANT ( psi element is a KtConstantExpression) , while `1+1` is a KtBinaryExpression - where you have to run a visitor to check that all subexpressions are constants (and no operators like `+`/`-`/etc overloads)


Please sign in to leave a comment.