InspectionGadget and PsiElement: how to create a extract PsiType from a String

I'm trying to use PsiType.isAssignable method to find out the inheritance relationship between two classes.
However, all I have is two strings, each of them is fully qualified name of their respective classes.

Is there a way to create a PsiExpression and then get the PsiType out of it?

I did try to use expName.getType(), but it gave me NullPointerException.

Anyone can shed a light on this matter?

thanks before

7 comments

sorry the subject should be: InspectionGadget and PsiElement: how to create PsiType from a String

0

yogi herinto wrote:

I'm trying to use PsiType.isAssignable method to find out the inheritance relationship between two classes.
However, all I have is two strings, each of them is fully qualified name of their respective classes.

Is there a way to create a PsiExpression and then get the PsiType out of it?

I did try to use expName.getType(), but it gave me NullPointerException.

Anyone can shed a light on this matter?

thanks before

PsiManager.getInstance(project).getElementFactory().createTypeByFQClassName("java.lang.Object")

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Thanks for your prompt reply, it works perfectly!
however, since it's deprectaed, is there an equivalent method to this one? not that I'm not satisfied, I'm so happy w/ this, but I'm just curious

0

yogi herinto wrote:

Thanks for your prompt reply, it works perfectly!
however, since it's deprectaed, is there an equivalent method to this one? not that I'm not satisfied, I'm so happy w/ this, but I'm just curious

That this method is indended to be replaced with contains an additional
parameter GlobalSearchScope specifying the scope the class should be
searched in. Check out static methods in GlobalSearchScope for avaliable
variants. Calling a deprecated method is equivalent to specifying
GlobalSearchScope.allScope(project) to the proper one.

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

Alternatively,

PsiManager.getInstance(project).findClass("java.lang.Object"),

and then use the .isInheritor() method on PsiClass.

Your post says InspectionGadget in the title. If you're looking to extend IG, I'm always interested in ideas for new inspections.

--Dave Griffith

0

I took you up on this and filed a few requests (one new inspection, one
new intention and one bug with an existing inspection)

http://www.intellij.net/tracker/idea/viewSCR?publicId=39847
http://www.intellij.net/tracker/idea/viewSCR?publicId=39848
http://www.intellij.net/tracker/idea/viewSCR?publicId=39849

Do they sound reasonable?
R

0


I just commented on the two that are IG or IPP related. Then other is a bug in a built-in inspection, and JetBrains has to handle that.

--Dave Griffith

0

Please sign in to leave a comment.