RedundantCollectionOperationHandler (PsiMethodCallExpression call) { PsiExpressionStatement statement = tryCast(call.getParent(), PsiExpressionStatement.class); if (statement == null) return null; PsiMethodCallExpression arg = tryCast(ExpressionUtils.resolveExpression(call.getArgumentList().getExpressions()[0]), PsiMethodCallExpression.class); if (!INDEX_OF.test(arg)) return null; PsiExpression qualifier1 = call.getMethodExpression().getQualifierExpression(); PsiExpression qualifier2 = arg.getMethodExpression().getQualifierExpression(); if (qualifier1 == null || qualifier2 == null || !PsiEquivalenceUtil.areElementsEquivalent(qualifier1, qualifier2)) return null; if (!PsiTreeUtil.isAncestor(statement, arg, true)) { PsiDeclarationStatement declaration = PsiTreeUtil.getParentOfType(arg, PsiDeclarationStatement.class); if (declaration == null || declaration.getDeclaredElements().length != 1) return null; if (PsiTreeUtil.skipWhitespacesAndCommentsForward(declaration) != statement) return null; } return new RedundantIndexOfHandler(); }