mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-03 15:50:52 +07:00
IDEA-204917 "Loop can be collapsed with Stream API" creates uncompilable results in some cases
1. Look for references inside IntStream.iterate condition (Java9+) 2. When simplifying IntStream.range(...).map(i -> arr[i]) check if arr expression don't refer to i
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// "Replace with reduce()" "false"
|
||||
public class Foo {
|
||||
|
||||
boolean isAnyFalse(boolean[] array) {
|
||||
boolean status = true;
|
||||
|
||||
f<caret>or (int i = 0; i < array.length & status; i++) {
|
||||
status &= array[i];
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Matrix {
|
||||
|
||||
public double trace(final double[][] a) {
|
||||
double sum = IntStream.range(0, a.length).mapToDouble(i -> a[i][i]).sum();
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
public class Matrix {
|
||||
|
||||
public double trace(final double[][] a) {
|
||||
double sum = 0;
|
||||
|
||||
f<caret>or (int i = 0; i < a.length; i++) {
|
||||
sum += a[i][i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user