A problem about PsiClass.getSuperClass in Junit

I want to write some test cases about PsiClass, but I cann't get a psiClass's superClass in my test case.
Is there something I made mistakes?

I try to wrtie Test Case as follow
1) Create a local Java File "DemoTest.Java"

package myTest;
import myTest.MyBaseClass;
public class myBaseClassImpl extends MyBaseClass {
   <caret>
}


2) Wrtie a TestCase extends AndroidTestCase

3) Add a Class by text and Configure File in myFixture

myFixture.setTestDataPath(MyBaseDataPath);
myFixture.addClass( "package myTest; public class MyBaseClass{}");
myFixture.configureByFiles("DemoTest.java");


4) Try to get superClass, but it returns null

PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
while (element != null) {
     if (element instanceof PsiClass) {
          PsiClass psiClass = (PsiClas)element;
          PsiClass superClass = psiClass.getSuperClass(); // it returns null
     }
     element = element.parent();
}

1 comment
Comment actions Permalink

I found that both this two ways can work correctly, but I still didn't know why.

  • Change the case extends LightCodeInsightFixtureTestCase
  • Move the local file DemoTest.Java from testData/DemoTest.java to testData/src/DemoTest.Java, and change the configureByFiles method
    myFixture.configureByFiles("src/DemoTest.java");
0

Please sign in to leave a comment.