mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix codegen for natural order: IDEA-CR-23874
This commit is contained in:
+9
-12
@@ -243,13 +243,6 @@ class FindExtremumMigration extends BaseStreamApiMigration {
|
||||
boolean isNegated);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getLambdaText(PsiExpression loopVarExpression, TerminalBlock terminalBlock) {
|
||||
return ExpressionUtils.isReferenceTo(loopVarExpression, terminalBlock.getVariable())
|
||||
? CommonClassNames.JAVA_UTIL_COMPARATOR + ".naturalOrder()"
|
||||
: LambdaUtil.createLambda(terminalBlock.getVariable(), loopVarExpression);
|
||||
}
|
||||
|
||||
//Person maxPerson = null;
|
||||
//int maxAge = 0;
|
||||
//for (Person person : personList) {
|
||||
@@ -301,7 +294,7 @@ class FindExtremumMigration extends BaseStreamApiMigration {
|
||||
TerminalBlock blockWithFilter =
|
||||
myTerminalBlock.add(new StreamApiMigrationInspection.FilterOp(condition, myTerminalBlock.getVariable(), false));
|
||||
|
||||
String lambdaText = getLambdaText(myExtremumKeyExpr, myTerminalBlock);
|
||||
String lambdaText = LambdaUtil.createLambda(myTerminalBlock.getVariable(), myExtremumKeyExpr);
|
||||
String comparator;
|
||||
if(myComparator == null) {
|
||||
comparator = CommonClassNames.JAVA_UTIL_COMPARATOR + "." + method + "(" + lambdaText + ")";
|
||||
@@ -566,10 +559,14 @@ class FindExtremumMigration extends BaseStreamApiMigration {
|
||||
if (loopVarExpressionType == null) return null;
|
||||
final String comparator;
|
||||
if(myComparator == null) {
|
||||
String method = getComparingMethod(loopVarExpressionType);
|
||||
if (method == null) return null;
|
||||
String lambdaText = getLambdaText(myLoopVarExpression, myTerminalBlock);
|
||||
comparator = CommonClassNames.JAVA_UTIL_COMPARATOR + "." + method + "(" + lambdaText + ")";
|
||||
if(ExpressionUtils.isReferenceTo(myLoopVarExpression, myTerminalBlock.getVariable())) {
|
||||
comparator = CommonClassNames.JAVA_UTIL_COMPARATOR + ".naturalOrder()";
|
||||
} else {
|
||||
String method = getComparingMethod(loopVarExpressionType);
|
||||
if (method == null) return null;
|
||||
String lambdaText = LambdaUtil.createLambda(myTerminalBlock.getVariable(), myLoopVarExpression);
|
||||
comparator = CommonClassNames.JAVA_UTIL_COMPARATOR + "." + method + "(" + lambdaText + ")";
|
||||
}
|
||||
} else {
|
||||
String comparatorName = myComparator.getName();
|
||||
if(comparatorName == null) return null;
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public class Main {
|
||||
new Person("James", 25),
|
||||
new Person("Kelly", 12)
|
||||
);
|
||||
Person minPerson = personList.stream().filter(p -> p.getAge() > 13).min(Comparator.comparing(Comparator.naturalOrder())).orElse(null);
|
||||
Person minPerson = personList.stream().filter(p -> p.getAge() > 13).min(Comparator.naturalOrder()).orElse(null);
|
||||
|
||||
return minPerson;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user