Context (@NotNull PsiElement element) { if (!element.isValid() || element instanceof PsiMethodReferenceExpression) return null; boolean isJava7OrHigher = PsiUtil.isLanguageLevel7OrHigher(element); List<PsiClassType> unhandledExceptions = new ArrayList<>(ExceptionUtil.getOwnUnhandledExceptions(element)); if (unhandledExceptions.isEmpty()) return null; List<PsiTryStatement> tryStatements = getTryStatements(element); List<PsiCatchSection> sections = tryStatements.stream() .flatMap(stmt -> findSuitableSections(Arrays.asList(stmt.getCatchSections()), unhandledExceptions, isJava7OrHigher).stream()) .filter(catchSection -> { PsiParameter parameter = catchSection.getParameter(); if (parameter == null) return false; return parameter.getTypeElement() != null; }) .collect(Collectors.toList()); if (sections.isEmpty()) return null; return new Context(sections, unhandledExceptions); }