Get packet name of a non-java PsiElement

Hi

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

Stefan

0
1 comment
Avatar
Permanently deleted user

I just found it by myself:

PsiDirectory psiDirectory = ((PsiFile) element).getParent();
ProjectRootManager.getInstance(project).getFileIndex().getPackageNameByDirectory(psiDirectory.getVirtualFile());
0

Please sign in to leave a comment.