PHP Psi Elements comparison not working
Hi,
I'm trying to develop a plugin for PhpStorm but i'm facing some problems with PHP Psi elements. I'm trying to add a LineMarkerProvider for string literals, checking if the parent's element is a StringLiteralExpression, but it always returns false, even when the PsiViewer shows that there are SLE elements in the document.
There is the code (Kotlin) I used to get the element:
private fun getString(element: PsiElement): StringLiteralExpression? {
val parent = element.parent as? StringLiteralExpression ?: return null
return parent
}
Any idea ?
Please sign in to leave a comment.
Hi Nicolas,
I'd recommend you to put a breakpoint and take a look at runtime what you get as a parent. Alternatively, you can write something like this
println(element.parent.javaClass)Hi,
I've added some logs, and here the results.*
Code:
Result
class com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl
class com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl
class com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl
class com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl
true
false
I really don't understand what happends.
Please check that php-openapi.jar has a provided scope. It seems it's included in your plugin but it shouldn't be because it's provided by PhpStorm itself.
Thanks to you I finally found the problem. It does not come from php-openapi.jar which which already had a provided scope, but from php.jar which I added in the modules. Once I removed it, everything works perfectly.
Thanks for your help.