@Nullable
protected PsiDocCommentOwner getContainer(final PsiElement context) {
if (context == null || !context.getManager().isInProject(context)) {
return null;
}
final PsiFile containingFile = context.getContainingFile();
if (containingFile == null) {
// for PsiDirectory
return null;
}
if (!containingFile.getLanguage().isKindOf(JavaLanguage.INSTANCE) || context instanceof PsiFile) {
return null;
}
PsiElement container = context;
while (container instanceof PsiAnonymousClass || !(container instanceof PsiDocCommentOwner) || container instanceof PsiTypeParameter) {
container = PsiTreeUtil.getParentOfType(container, PsiDocCommentOwner.class);