PsiElement[] (@NotNull PsiElement expr, @NotNull PsiElement scope) { ArrayList<PsiElement> occurrences = new ArrayList<>(); BiPredicate<PsiElement, PsiElement> comparator = (element1, element2) -> { if (element1 != null && element1.equals(element2)) return true; return element1 instanceof GrParameter param1 && element2 instanceof GrParameter param2 && param1.getName().equals(param2.getName()); }; if (scope instanceof GrLoopStatement) { PsiElement son = expr; while (son.getParent() != null && !(son.getParent() instanceof GrLoopStatement)) { son = son.getParent(); } assert scope.equals(son.getParent()); collectOccurrences(expr, son, occurrences, comparator, false); } else { collectOccurrences(expr, scope, occurrences, comparator, scope instanceof GrTypeDefinition || scope instanceof GroovyFileBase); } return PsiUtilCore.toPsiElementArray(occurrences); }