mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Stream API Migration: fix cases when boxed collection is iterated with primitive parameter (inspired by PR https://github.com/JetBrains/intellij-community/pull/455 by FHannes)
This commit is contained in:
+16
-2
@@ -522,6 +522,19 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
return false;
|
||||
}
|
||||
|
||||
static String tryUnbox(PsiVariable variable) {
|
||||
PsiType type = variable.getType();
|
||||
String mapOp = null;
|
||||
if(type.equals(PsiType.INT)) {
|
||||
mapOp = "mapToInt";
|
||||
} else if(type.equals(PsiType.LONG)) {
|
||||
mapOp = "mapToLong";
|
||||
} else if(type.equals(PsiType.DOUBLE)) {
|
||||
mapOp = "mapToDouble";
|
||||
}
|
||||
return mapOp == null ? "" : "."+mapOp+"("+variable.getName()+" -> "+variable.getName()+")";
|
||||
}
|
||||
|
||||
private class StreamApiMigrationVisitor extends JavaElementVisitor {
|
||||
private final ProblemsHolder myHolder;
|
||||
private final boolean myIsOnTheFly;
|
||||
@@ -1155,7 +1168,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
|
||||
@Override
|
||||
String createReplacement() {
|
||||
return ParenthesesUtils.getText(myExpression, ParenthesesUtils.POSTFIX_PRECEDENCE) + ".stream()";
|
||||
return ParenthesesUtils.getText(myExpression, ParenthesesUtils.POSTFIX_PRECEDENCE) + ".stream()" + tryUnbox(myVariable);
|
||||
}
|
||||
|
||||
@Contract("null, _ -> false")
|
||||
@@ -1175,7 +1188,8 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
PsiClass iteratorClass = PsiUtil.resolveClassInClassTypeOnly(iteratedValueType);
|
||||
if (collectionClass == null ||
|
||||
!InheritanceUtil.isInheritorOrSelf(iteratorClass, collectionClass, true) ||
|
||||
isRawSubstitution(iteratedValueType, collectionClass)) {
|
||||
isRawSubstitution(iteratedValueType, collectionClass) ||
|
||||
!isSupported(statement.getIterationParameter().getType())) {
|
||||
return null;
|
||||
}
|
||||
return new CollectionStream(statement.getIterationParameter(), iteratedValue);
|
||||
|
||||
Reference in New Issue
Block a user