Getting PsiType for PsiReferenceExpression... static call treated differently than non-static call ?

it would seem awkward to mee, to differentiate between static and non-static methods, if I need to find the Type of the call-site
Why is the static Type not available ?

PsiReferenceExpression at object-invocation has PsiType (property 'type' in PsiViewer) :

see attachment invoke-instance.png

PsiReferenceExpression at Static-invocation has *no* PsiType (instead, the class of the static method is given in canonicalText, text and qualifiedName) :

see attachment invoke-static.png

Message was edited by: j w



Attachment(s):
invoke-static.png
invoke-instance.png
0
7 comments

What are you trying to accomplish? If you want to understand the method from which class is being called, you need to resolve the method reference (PsiReferenceExpression.getReference().resolve()) and look at the containing class of the method to which it resolves to. This works equally for static and non-static calls.

0

I'm trying to get the
Type (PsiType? sorry, not yet an expert in the
Java-PSI API) on which
the method is invoked.

Thanks for your hint ! ... will try that.

0

...basically, I wanted to get (Psi)Type information from

com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl#getType

And this gives me null in case of a reference to a class (ie static method call)
In case of an instance method call, this method gives me the expected PsiType of the class of the object


(all this by using PsiViewer, btw)

0

What are you trying to do in your plugin? What do you need the PsiType for?


0

Find all Types (classes) on which methods are invoked

more generally: find all 'collaborators' of the class

0

Then you do need to use the approach I initially suggested, with resolving the references. This will give you more correct results in the presence of inheritance, when the class calls a superclass method through a subclass reference or an object of the subclass type.

Your observations about PsiType are correct. A value is something that has a type; a static class reference is not a value and does not have a type.

0

Thanks so much!

0

Please sign in to leave a comment.