void (PsiForeachStatement loop) { PsiMethodCallExpression entrySetCall = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(loop.getIteratedValue()), PsiMethodCallExpression.class); if (entrySetCall == null) return; PsiElement body = loop.getBody(); if (body == null) return; PsiParameter entryParameter = loop.getIterationParameter(); CommentTracker ct = new CommentTracker(); String replacementExpression = createReplacementExpression(entrySetCall, entryParameter, body, ct); ct.replaceAndRestoreComments(loop, replacementExpression + ";"); }