for loop -> forEach call chain inspection

This commit is contained in:
Anna Kozlova
2014-02-25 22:03:28 +01:00
parent e967a04b4b
commit 9b637e541b
14 changed files with 383 additions and 1 deletions
@@ -0,0 +1,12 @@
// "Replace with forEach" "true"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
{
foo.forEach(this::bar);
}
void bar(String s){}
}
@@ -0,0 +1,10 @@
// "Replace with forEach" "true"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
{
foo.stream().filter(s -> s != null).forEach(System.out::println);
}
}
@@ -0,0 +1,15 @@
// "Replace with forEach" "false"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
{
for (String s : fo<caret>o) {
if (s == null) {
break;
}
}
}
}
@@ -0,0 +1,15 @@
// "Replace with forEach" "false"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
{
for (String s : fo<caret>o) {
if (s == null) {
continue;
}
}
}
}
@@ -0,0 +1,14 @@
// "Replace with forEach" "true"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
{
for (String s : fo<caret>o) {
bar(s)
}
}
void bar(String s){}
}
@@ -0,0 +1,11 @@
// "Replace with forEach" "false"
class Sample {
void foo(It it){
for (String s : i<caret>t) {
if (s == null) {
}
}
}
}
abstract class It implements Iterable<String> {}
@@ -0,0 +1,14 @@
// "Replace with forEach" "true"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
{
for (String s : fo<caret>o) {
if (s != null) {
System.out.println(s);
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with forEach" "false"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
String foo(){
boolean b = true;
for (String s : f<caret>oo) {
if (s == null) {
b = false;
}
}
return null;
}
}
@@ -0,0 +1,15 @@
// "Replace with forEach" "false"
import java.util.ArrayList;
import java.util.List;
class Sample {
List<String> foo = new ArrayList<>();
String foo(){
for (String s : fo<caret>o) {
if (s == null) {
return s;
}
}
return null;
}
}