void (@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) { PsiExpression expression = ObjectUtils.tryCast(startElement, PsiExpression.class); if (expression == null) return; PsiElement anchor = FOR_NAME_MATCHER.matches(expression) ? null : PsiTreeUtil.getParentOfType(expression, PsiCallExpression.class); CommentTracker ct = new CommentTracker(); PsiExpression ref = (PsiExpression)ct.replaceAndRestoreComments(expression, myCharsetExpression); JavaCodeStyleManager.getInstance(project).shortenClassReferences(ref); if (anchor == null) return; while (true) { PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(anchor, PsiTryStatement.class, true, PsiMember.class, PsiLambdaExpression.class); if (tryStatement == null) break; PsiCodeBlock tryBlock = tryStatement.getTryBlock(); boolean inTry = PsiTreeUtil.isAncestor(tryBlock, anchor, true); PsiResourceList resourceList = tryStatement.getResourceList(); boolean inResource = PsiTreeUtil.isAncestor(resourceList, anchor, true); if (inTry || inResource) { for (PsiParameter parameter : tryStatement.getCatchBlockParameters()) { List<PsiTypeElement> typeElements = PsiUtil.getParameterTypeElements(parameter); for (PsiTypeElement element : typeElements) { PsiType type = element.getType(); if (type.equalsToText("java.io.UnsupportedEncodingException") || type.equalsToText("java.io.IOException")) { Set<PsiClassType> unhandledExceptions = StreamEx.of(tryBlock, resourceList).nonNull() .flatCollection(block -> ExceptionUtil.collectUnhandledExceptions(block, block)) .toSet(); if (!ContainerUtil.exists(unhandledExceptions, ue -> ue.isAssignableFrom(type) || type.isAssignableFrom(ue))) { if (parameter.getType() instanceof PsiDisjunctionType) { DeleteMultiCatchFix.deleteCaughtExceptionType(element); } else { DeleteCatchFix.deleteCatch(parameter); } } return; } if (type.equalsToText(JAVA_LANG_EXCEPTION) || type.equalsToText(JAVA_LANG_THROWABLE)) { return; } } } } anchor = tryStatement; } }