How to check if PsiElement is a kotlin constant Follow
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?
Please sign in to leave a comment.
There is quite useful action View PSI Structure that is enabled in so-called internal mode http://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html :
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)
Thanks for the tipps!
I opened https://github.com/JetBrains/intellij-community/pull/1678 and used the visitor here https://github.com/JetBrains/intellij-community/pull/1678/files#diff-18106261245e00b0e9cf958fc4b077006359069ad528075566509418d11d9e57R114 .
Is this the correct way to use it?