IDEA-167263 Stream API migration does not work when replacing simple loop on array of primitive types (int, long, double)

This commit is contained in:
Tagir Valeev
2017-01-30 14:00:52 +03:00
parent b01ac7a17b
commit e8c6ba183b
3 changed files with 25 additions and 1 deletions
@@ -242,7 +242,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
static boolean isAddAllCall(TerminalBlock tb) {
PsiMethodCallExpression call = tb.getSingleMethodCall();
if (call == null) return false;
if (call == null || tb.getVariable().getType() instanceof PsiPrimitiveType) return false;
if (!ExpressionUtils.isReferenceTo(call.getArgumentList().getExpressions()[0], tb.getVariable())) return false;
if (!"add".equals(call.getMethodExpression().getReferenceName())) return false;
PsiExpression qualifierExpression = call.getMethodExpression().getQualifierExpression();
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
final double[] array = new double[10];
final List<Double> list = Arrays.stream(array).boxed().collect(Collectors.toList());
// Cannot be replaced with list.addAll()
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.*;
public class Test {
public static void main(String[] args) {
final double[] array = new double[10];
final List<Double> list = new ArrayList<>();
// Cannot be replaced with list.addAll()
for (double d : ar<caret>ray) {
list.add(d);
}
}
}