PsiJavaDocumentedElement (final PsiElement element) { PsiJavaDocumentedElement container = super.getContainer(element); if (container == null || container instanceof PsiClass){ return null; } while (container != null ) { final PsiClass parentClass = PsiTreeUtil.getParentOfType(container, PsiClass.class); if ((parentClass == null || container.getParent() instanceof PsiDeclarationStatement || container.getParent() instanceof PsiClass) && container instanceof PsiClass){ return container; } container = parentClass; } return null; }