openrewrite / openrewrite/rewrite-static-analysis

Recipe: `for` loop can be replaced with `enhanced for`

Open
#73 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

Before :


List<String> elements = List.of("Hello","World");

for (int i = 0 ; i < elements.size(); i++){
       System.out.println(elements.get(i));
 }

After :


List<String> elements = List.of("Hello","World");

for (String element : elements) {
      System.out.println(element);
 }

See : https://www.cis.upenn.edu/~matuszek/General/JavaSyntax/enhanced-for-loops.html

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the repository's existing static-analysis recipes and tests to find where a recipe for Java indexed loops belongs. Compare the issue's before and after examples and the linked enhanced-for-loop reference. Done means the recipe identifies the shown index-based iteration pattern and verifies the enhanced-loop result with tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.