PsiPackage (DataContext dataContext) { PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext); if (psiFile == null) return null; PsiDirectory containingDirectory = psiFile.getContainingDirectory(); if (containingDirectory == null || !containingDirectory.isValid()) return null; return JavaDirectoryService.getInstance().getPackage(containingDirectory); }