openrewrite / openrewrite/rewrite-static-analysis

Replace copy with iteration with a constructor call

Open
#72 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 :


Map<String,String> a = new Hashmap<>();
a.add("hello","world");

Map<String,String> b = new HashMap<>();

for (Map.Entry<String, String> s : a.entrySet()){
 b.put(s.getKey(),s.getValue());
 }


// Lists
List<Integer> l1 = new ArrayList<>();
l1.add(1);

List<Integer> l2  = new ArrayList<>();

for (Integer i : l1){
l2.add(i);
}


After :


Map<String,String> a = new Hashmap<>();
a.add("hello","world");
Map<String, String> b = new HashMap<>(a);

// Lists
List<Integer> l1 = new ArrayList<>();
l1.add(1);

List<Integer> l2  = new ArrayList<>(l1);

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 Java before-and-after examples in the issue and locating the corresponding static-analysis recipe in this repository. Done means the map and list copy loops shown in the issue are identified as replaceable by collection-constructor calls, with coverage for the demonstrated forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Refactor
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.