openrewrite / openrewrite/rewrite-static-analysis
Replace copy with iteration with a constructor call
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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