mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
IDEA-160802 fixed case with collection summing
This commit is contained in:
+5
-5
@@ -801,7 +801,6 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
PsiElement element = ((PsiReferenceExpression)operand).resolve();
|
||||
if (!(element instanceof PsiLocalVariable)) return;
|
||||
PsiLocalVariable var = (PsiLocalVariable)element;
|
||||
final StringBuilder builder = generateStream(iteratedValue, intermediateOps);
|
||||
|
||||
PsiExpression addend = extractAddend(assignment);
|
||||
if (addend == null) return;
|
||||
@@ -819,10 +818,11 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
else {
|
||||
typeName = "Int";
|
||||
}
|
||||
builder.append(".mapTo").append(typeName).append('(');
|
||||
builder.append(compoundLambdaOrMethodReference(tb.getVariable(), addend, "java.util.function.To" + typeName + "Function",
|
||||
new PsiType[]{tb.getVariable().getType()}));
|
||||
builder.append(").sum()");
|
||||
intermediateOps.add(".mapTo" + typeName + "(" +
|
||||
compoundLambdaOrMethodReference(tb.getVariable(), addend, "java.util.function.To" + typeName + "Function",
|
||||
new PsiType[]{tb.getVariable().getType()})+")");
|
||||
final StringBuilder builder = generateStream(iteratedValue, intermediateOps);
|
||||
builder.append(".sum()");
|
||||
replaceWithNumericAddition(project, foreachStatement, var, builder, typeName.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
int getAge();
|
||||
}
|
||||
|
||||
public long test(List<Person> collection) {
|
||||
long i = collection.stream().mapToLong(Person::getAge).sum();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with sum()" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
interface Person {
|
||||
int getAge();
|
||||
}
|
||||
|
||||
public long test(List<Person> collection) {
|
||||
long i = 0;
|
||||
for(Person person : collecti<caret>on) {
|
||||
i = i + person.getAge();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user