mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
IDEA-165942 Inspection to replace method call in a loop with bulk operation
This commit is contained in:
+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);
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
names.addAll(persons);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
names.addAll(persons);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "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));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<CharSequence, Integer> repo, Iterable<String> stringsToSave) {
|
||||
repo.save(stringsToSave);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<Iterable<String>, Integer> repo, Iterable<List<String>> stringsToSave) {
|
||||
repo.save(stringsToSave);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
persons.removeAll(toRemove);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
persons.removeAll(toRemove);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
Arrays.stream(arr).forEach(result<caret>::add);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
for(int i = 0; i<persons.size(); i = i + 1) {
|
||||
Person p = persons.get(i);
|
||||
names.<caret>add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "false"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -16,8 +16,8 @@ public class Main {
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends String> c) {
|
||||
for (String e : <caret>c) {
|
||||
add(e);
|
||||
for (String e : c) {
|
||||
a<caret>dd(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -15,8 +15,8 @@ public class Main {
|
||||
}
|
||||
|
||||
public boolean myAdd(Collection<? extends String> c) {
|
||||
for (String e : <caret>c) {
|
||||
this.add(e);
|
||||
for (String e : c) {
|
||||
this.<caret>add(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "false"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(Iterable<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
persons.forEach(p -> {
|
||||
names<caret>.add(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
persons.forEach(p -> {
|
||||
names<caret>.add(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -6,8 +6,8 @@ class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
Sample sm = new Sample();
|
||||
for (String s : fo<caret>o) {
|
||||
sm.foo.add(s);
|
||||
for (String s : foo) {
|
||||
<caret>sm.foo.add(s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
// "Replace with addAll" "true"
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -6,7 +6,7 @@ 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);
|
||||
for(Integer i : arr)
|
||||
result.<caret>add(i);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "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 (int idx = 0; idx < arr.length; idx++) {
|
||||
result.<caret>add(arr[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
Stream.of(arr).forEachOrdered(<caret>result::add);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
for (Person person : persons) {
|
||||
<caret>names.add(person);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<CharSequence, Integer> repo, Iterable<String> stringsToSave) {
|
||||
stringsToSave.forEach(<caret>repo::save);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "false"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<CharSequence, Integer> repo, Iterable<List<String>> stringsToSave) {
|
||||
stringsToSave.forEach(<caret>repo::save);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<Iterable<String>, Integer> repo, Iterable<List<String>> stringsToSave) {
|
||||
stringsToSave.forEach(<caret>repo::save);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
for (Iterator<Person> it = toRemove.iterator(); it.hasNext(); )
|
||||
persons<caret>.remove(it.next());
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
Iterator<Person> it = toRemove.iterator();
|
||||
while (it.hasNext()) {
|
||||
Person person = it.next();
|
||||
persons<caret>.remove(person);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user