Create subclass with PSI

 Hi! 

I am trying to create a subclass with PSI. I havent figured out how to make one without without useing the createClassFromText method. But when I try that and try to add methods to it afterwards it just seems to create some _Dummy_ class and adds the method to it instead.

It feels like I missed something.. I would really appraciate some help if someone knows how to do this :)

Thanks!

/Johan

2 comments
PsiElementFactory factory = JavaPsiFacade.getInstance(element.getProject()).getElementFactory();
PsiClass clazz = factory.createClassFromText("void test() {}", null);
clazz.setName("Test");

someRealPsiFile.add(clazz);

You could change name afterwards, or you could use 

factory.createClass("Test");
0

you can

PsiClass clazz = factory.createClassFromText("public class A {}", null).getInnerClasses()[0];
0

Please sign in to leave a comment.