How to add PsiPackage to PsiJavaFile


I have troubles with such a simple thing - setting the package statement in psi java file. I'm able to create the class, add it to the PsiFile. All imports are automatically done, based on the extended class and the exceptions that overridden methods throw, but all this is at the class level. The package in my understanding should go to the PsiJavaFile containing the newly created class, so I create the package statement as Psi object and try to set ti to the psi file object. Whatever I try, I get either an exception or no package statement at all. Does someone know, what is the correct path to go? Any reference to the Psi tree model?


1 comment
Comment actions Permalink

The way I do it is through setting the parent of the PsiJavaFile i.e. a source PsiDirectory:

PsiJavaFile file = ...
PsiDirectory dir = ...

If you want I have several utilities that could be useful to create/find directories. Let me know.



Please sign in to leave a comment.