boolean (@NotNull PsiElement element, @Nullable PsiElement stopAt) { PsiElement parent = element.getParent(); while (parent != null && parent != stopAt && !(parent instanceof PsiMember) && !(parent instanceof PsiLambdaExpression)) { if (parent instanceof PsiTryStatement tryStatement) { final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock(); if (finallyBlock != null && PsiTreeUtil.isAncestor(finallyBlock, element, true)) { return true; } } parent = parent.getParent(); } return false; }