boolean (@NotNull PsiMethodCallExpression call) { PsiMethod method = call.resolveMethod(); if (method == null) return false; PsiExpression qualifier = call.getMethodExpression().getQualifierExpression(); if (qualifier == null) return false; PsiCodeBlock block = PsiTreeUtil.getParentOfType(call, PsiCodeBlock.class, true, PsiLambdaExpression.class, PsiMember.class); if (block == null) return false; PsiStatement[] statements = block.getStatements(); int index = (int) StreamEx.of(statements).indexOf(s -> PsiTreeUtil.isAncestor(s, call, true)).orElse(-1); if (index == -1) return false; for (int i = Math.max(0, index - 2); i <= Math.min(statements.length - 1, index + 2); i++) { Integer otherIndex = SyntaxTraverser.psiTraverser(statements[i]).filter(PsiMethodCallExpression.class) .filter(c -> c != call) .filter(c -> method.isEquivalentTo(c.resolveMethod()) && EquivalenceChecker.getCanonicalPsiEquivalence() .expressionsAreEquivalent(qualifier, c.getMethodExpression().getQualifierExpression())) .map(c -> PsiUtil.skipParenthesizedExprDown(ArrayUtil.getFirstElement(c.getArgumentList().getExpressions()))) .filter(PsiLiteralValue.class) .map(PsiLiteralValue::getValue) .filter(Integer.class) .find(idx -> idx > 0 && idx < 10); if (otherIndex != null) { return true; } } return false; }