Stream API Migration: do not add type arguments if a type is a wildcard type

This commit is contained in:
Tagir Valeev
2016-10-25 11:10:08 +07:00
parent 0a312354c7
commit 4ce59ee865
3 changed files with 24 additions and 1 deletions
@@ -993,7 +993,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
operationName = "mapToObj";
}
PsiExpression expression = myType == null ? myExpression : RefactoringUtil.convertInitializerToNormalExpression(myExpression, myType);
if(myType != null && !(myType instanceof PsiPrimitiveType)) {
if(myType != null && !(myType instanceof PsiPrimitiveType) && !(myType instanceof PsiCapturedWildcardType)) {
operationName = "<"+myType.getCanonicalText()+">"+operationName;
}
return "." + operationName + "(" + LambdaUtil.createLambda(myVariable, expression) + ")";
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class A {
public List<? super Integer> sum() {
List<? super Integer> result = IntStream.range(0, 10).mapToObj(i -> i * 2).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.*;
class A {
public List<? super Integer> sum() {
List<? super Integer> result = new ArrayList<>();
for(i<caret>nt i=0; i<10; i++) {
result.add(i*2);
}
return result;
}
}