Newbie Q: How to get (literal) expression types in PhpStorm plugin?

Answered

I'm trying to extend PhpInspectionsEA a bit, but i'm stuck with getting type informations even for simplest expressions.

for (final PsiElement expression : conditions) {
PhpType type = PhpTypeInfo.getType(expression, 2);

The results are a bit confusing for me (I'm looking for non-boolean expressions to report):

`1`

type.toString= type.isEmpty=true type.isComplete=true type.elementType().toString=

`1.0`

type.toString= type.isEmpty=true type.isComplete=true type.elementType().toString=


`[]`

type.toString=array type.isEmpty=false type.isComplete=true type.elementType().toString=mixed


`new stdClass()`

type.toString=\stdClass type.isEmpty=false type.isComplete=true type.elementType().toString=#E#C\stdClass|?

`true`

type.toString=#D\true|? type.isEmpty=false type.isComplete=false type.elementType().toString=#E#D\true|?

`false`

type.toString=#D\false|? type.isEmpty=false type.isComplete=false type.elementType().toString=#E#D\false|?

`$x=true;` `$x`

type.toString=bool type.isEmpty=false type.isComplete=true type.elementType().toString=

`$x=1;` `$x`

type.toString=int type.isEmpty=false type.isComplete=true type.elementType().toString=

 

So far it seems to me that PhpType is only for variable expressions, how do I get the type for literals?

0
2 comments

Thomas,

Try with the PsiViewer plugin to inspect the PSI structure of the file. It'll let you check any type of specific part of the document.

0
Avatar
Permanently deleted user

I think I got it after some debugging, here's the commit if anyone runs into the same problem https://github.com/tlamy/phpinspectionsea/commit/1a77977bce310595978fa67aa0772001dcb9f534

0

Please sign in to leave a comment.