mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-205308 'Replace with max()' produces uncompilable source
This commit is contained in:
+4
-4
@@ -28,6 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.intellij.psi.util.PsiUtil.skipParenthesizedExprDown;
|
||||
import static com.intellij.util.ObjectUtils.tryCast;
|
||||
@@ -462,8 +463,8 @@ class FindExtremumMigration extends BaseStreamApiMigration {
|
||||
|
||||
|
||||
final TerminalBlock terminalBlock;
|
||||
PsiType variableType = variable.getType();
|
||||
if(!variableType.equals(myExtremum.getType())) {
|
||||
PsiType variableType = myLoopVarExpression.getType();
|
||||
if(!Objects.equals(variableType, myExtremum.getType())) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(variable.getProject());
|
||||
PsiExpression variableExpr = factory.createExpressionFromText(name, variable);
|
||||
terminalBlock = blockWithMap.add(new StreamApiMigrationInspection.MapOp(variableExpr, variable, type));
|
||||
@@ -526,8 +527,7 @@ class FindExtremumMigration extends BaseStreamApiMigration {
|
||||
|
||||
PsiExpression extremumInitializer = extremum.getInitializer();
|
||||
if (!ExpressionUtils.isEvaluatedAtCompileTime(extremumInitializer)) return null;
|
||||
return new PrimitiveExtremumTerminal(comparison.isMax(), terminalBlock, comparisonLoopVarExpr, extremum, extremumInitializer
|
||||
);
|
||||
return new PrimitiveExtremumTerminal(comparison.isMax(), terminalBlock, comparisonLoopVarExpr, extremum, extremumInitializer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with max()" "true"
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class Scratch {
|
||||
native int scale();
|
||||
|
||||
private static Integer getMaxScale(Collection<Scratch> updated) {
|
||||
int maxScale = updated.stream().mapToInt(Scratch::scale).filter(b -> b >= 0).max().orElse(0);
|
||||
return maxScale;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with max()" "true"
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class Scratch {
|
||||
native int scale();
|
||||
|
||||
private static Integer getMaxScale(Collection<Scratch> updated) {
|
||||
int maxScale = 0;
|
||||
f<caret>or (Scratch b : updated) {
|
||||
if (maxScale < b.scale()) {
|
||||
maxScale = b.scale();
|
||||
}
|
||||
}
|
||||
return maxScale;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user