boolean (PsiElement element) { PsiElement parent = element.getParent(); while (parent instanceof PsiJavaCodeReferenceElement || parent instanceof PsiErrorElement || parent instanceof PsiTypeElement || parent instanceof PsiMethod || parent instanceof PsiVariable || parent instanceof PsiDeclarationStatement || parent instanceof PsiImportList || parent instanceof PsiDocComment) { parent = parent.getParent(); if (parent instanceof JspClassLevelDeclarationStatement) { parent = parent.getContext(); } } if (parent == null) return false; return (parent instanceof PsiJavaFile || parent instanceof PsiClass) && JavaKeywordCompletion.isEndOfBlock(element); }