boolean (@NotNull PsiElement element, @NotNull Document copyDocument, int newOffset) { if (!PsiUtil.isLanguageLevel7OrHigher(element)) return false; PsiExpression initializer = JavaPostfixTemplatesUtils.getTopmostExpression(element); if (initializer == null) return false; final PsiType type = initializer.getType(); if (!(type instanceof PsiClassType)) return false; final PsiClass aClass = ((PsiClassType)type).resolve(); Project project = element.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiClass autoCloseable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, ProjectScope.getLibrariesScope(project)); if (!InheritanceUtil.isInheritorOrSelf(aClass, autoCloseable, true)) return false; return true; }