void (PsiMethod containingMethod, @NotNull PsiExpression expr, PsiExpression @Nullable [] occurences, IntSet suspects) { final IntIterator iterator = suspects.iterator(); while (iterator.hasNext()) { final int paramNum = iterator.nextInt(); PsiParameter[] psiParameters = containingMethod.getParameterList().getParameters(); if (paramNum >= psiParameters.length) continue; PsiParameter parameter = psiParameters[paramNum]; ReferencesSearch.search(parameter, parameter.getResolveScope(), false).forEach(reference -> { PsiElement element = reference.getElement(); boolean stillCanBeRemoved = isAncestor(expr, element, false) || PsiUtil.isInsideJavadocComment(getPhysical(element)); if (!stillCanBeRemoved && occurences != null) { for (PsiExpression occurence : occurences) { if (isAncestor(occurence, element, false)) { stillCanBeRemoved = true; break; } } } if (!stillCanBeRemoved) { iterator.remove(); return false; } return true; }); } }