Get packet name of a non-java PsiElement


I got a non-java element selected in a java module. This element is of type PsiElement. Now I want to optain the package name.

With java files I got a solution:  ((PsiJavaFile) element.getContainingFile()).getPackageName()


But with a non java file (XML for instance), I got no clue, how to get the package name...


What's the best way to proceed?


Thanks in advance


1 comment
Comment actions Permalink

I just found it by myself:

PsiDirectory psiDirectory = ((PsiFile) element).getParent();

Please sign in to leave a comment.