mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-165942 Inspection to replace method call in a loop with bulk operation
This commit is contained in:
-22
@@ -1,22 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends AbstractCollection<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean myAdd(Collection<? extends String> c) {
|
||||
this.addAll(c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
Sample sm = new Sample();
|
||||
sm.foo.addAll(foo);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
names.addAll(persons);
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
// "Replace with addAll" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends AbstractCollection<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends String> c) {
|
||||
for (String e : <caret>c) {
|
||||
add(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends AbstractCollection<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean myAdd(Collection<? extends String> c) {
|
||||
for (String e : <caret>c) {
|
||||
this.add(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
Sample sm = new Sample();
|
||||
for (String s : fo<caret>o) {
|
||||
sm.foo.add(s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// "Replace with addAll" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
for(Integer i : ar<caret>r)
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,12 +1,13 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace with collect" "false"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
// Handled by UseBulkOperationInspection
|
||||
List<Person> names = new ArrayList<>();
|
||||
for (Person person : pers<caret>ons) {
|
||||
for (Person person : p<caret>ersons) {
|
||||
names.add(person);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user