PsiExpression (@NotNull PsiElementFactory factory, @NotNull String kVar, @NotNull String vVar, @NotNull MapLoopCondition loopCondition, @NotNull PsiExpression value, @NotNull CommentTracker tracker) { if (value instanceof PsiMethodCallExpression) { if (loopCondition.isKeyAccess(value)) return factory.createExpressionFromText("(" + kVar + "," + vVar + ") ->" + kVar, value); if (loopCondition.isValueAccess(value)) return factory.createExpressionFromText("(" + kVar + "," + vVar + ") ->" + vVar, value); } if (!loopCondition.isEntrySet()) { PsiParameter param = loopCondition.getIterParam(); VariableAccessUtils.getVariableReferences(param, value).forEach(ref -> ExpressionUtils.bindReferenceTo(ref, kVar)); } Collection<PsiMethodCallExpression> calls = PsiTreeUtil.collectElementsOfType(value, PsiMethodCallExpression.class); for (PsiMethodCallExpression call : calls) { if (loopCondition.isKeyAccess(call)) { tracker.replace(call, kVar); } else if (loopCondition.isValueAccess(call)) { tracker.replace(call, vVar); } } return factory.createExpressionFromText("(" + kVar + "," + vVar + ") ->" + tracker.text(value), value); }