How to obtain the class and inheritance tree of..


Sorry, newbie question, but I'm stuck:


Given a psiElement (PsiVariable, PsiField, PsiMethod, PsiClass) linked
to a typed java "thing" (variable, field, constant, method), how can I

- obtain the class of the "thing"
- obtain the inheritance tree of the "thing" class


Example 1:
-





Given 'log', I must assert that its class 'MyLogger' extends

org.apache.log4j.Logger


Example 2:
-




Given 'isDebugEnabled()', I must assert that it is, or extends :

org.apache.log4j.Category.isDebugEnabled()


Alain

2 comments
Comment actions Permalink


"Alain Ravet" <alain.ravet.list@wanadoo.be> wrote in message
news:bm198v$d0v$1@is.intellij.net...
>

Sorry, newbie question, but I'm stuck:

>
>

Given a psiElement (PsiVariable, PsiField, PsiMethod, PsiClass) linked
to a typed java "thing" (variable, field, constant, method), how can I

>

- obtain the class of the "thing"
- obtain the inheritance tree of the "thing" class

>
>

Example 1:
---------

    MyLogger log = ...;
> ]]>

>
>

Given 'log', I must assert that its class 'MyLogger' extends

>

org.apache.log4j.Logger


boolean InheritanceUtil.isInheritor(PsiClass candidateClass, PsiClass
baseClass, boolean checkDeep) {

or

boolean PsiType.isAssignableFrom(PsiType type)

>
>

Example 2:
---------

         if (l.isDebugEnabled()) ...
> ]]>

>

Given 'isDebugEnabled()', I must assert that it is, or extends :

>

org.apache.log4j.Category.isDebugEnabled()

>
PsiMethod[] PsiSuperMethodUtil.findSuperMethods(PsiMethod method)

or better InheritanceUtil.isInhertior(((PsiClassType)l.getType()).resolve(),
PsiManager.getInstance(xxx).findClass("org.apache.log4j.Category"), true)
with all necessary checks for nulls.


0

Please sign in to leave a comment.