PsiExpression (PsiMethodCallExpression expression, BulkMethodInfo info) { PsiExpression[] args = expression.getArgumentList().getExpressions(); if (args.length != info.getSimpleParametersCount()) return null; PsiElement parent = expression.getParent(); if (parent instanceof PsiLambdaExpression) { return findIterableForLambda((PsiLambdaExpression)parent, args, info); } if (parent instanceof PsiExpressionStatement expressionStatement) { if (expressionStatement.getParent() instanceof PsiCodeBlock codeBlock) { PsiStatement[] statements = codeBlock.getStatements(); if (codeBlock.getParent() instanceof PsiBlockStatement blockStatement) { if (statements.length == 1) { return findIterableForSingleStatement(blockStatement, args); } PsiElement blockParent = blockStatement.getParent(); if (statements.length == 2 && statements[1] == parent && blockParent instanceof PsiLoopStatement) { IteratorDeclaration declaration = IteratorDeclaration.fromLoop((PsiLoopStatement)blockParent); if (declaration != null) { if (args.length == 1 && ExpressionUtils.isReferenceTo(args[0], declaration.getNextElementVariable(statements[0]))) { return declaration.getIterable(); } else if (args.length == 2) { if (isGetKeyAndGetValue(args, declaration.getNextElementVariable(statements[0]))) { PsiMethodCallExpression entrySetCandidate = ObjectUtils.tryCast(declaration.getIterable(), PsiMethodCallExpression.class); if (MAP_ENTRY_SET.test(entrySetCandidate)) { return entrySetCandidate.getMethodExpression().getQualifierExpression(); } } } } if (blockParent instanceof PsiForStatement forStatement && statements[0] instanceof PsiDeclarationStatement declarationStatement) { PsiElement[] elements = declarationStatement.getDeclaredElements(); if (elements.length == 1 && elements[0] instanceof PsiLocalVariable var && ExpressionUtils.isReferenceTo(args[0], var)) { return findIterableForIndexedLoop(forStatement, var.getInitializer()); } } } } else if (codeBlock.getParent() instanceof PsiLambdaExpression && statements.length == 1) { return findIterableForLambda((PsiLambdaExpression)codeBlock.getParent(), args, info); } } else { return findIterableForSingleStatement(expressionStatement, args); } } return null; }