mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-167088 Stream API migration: allow resulting StringBuilder usages in concatenation
This commit is contained in:
@@ -618,6 +618,15 @@ class CollectMigration extends BaseStreamApiMigration {
|
||||
String name = usage.getMethodExpression().getReferenceName();
|
||||
if (usageArgs.length == 0 && ("toString".equals(name) || "length".equals(name))) return true;
|
||||
}
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(element.getParent());
|
||||
if (parent instanceof PsiPolyadicExpression &&
|
||||
((PsiPolyadicExpression)parent).getOperationTokenType().equals(JavaTokenType.PLUS)) {
|
||||
return true;
|
||||
}
|
||||
if (parent instanceof PsiAssignmentExpression &&
|
||||
((PsiAssignmentExpression)parent).getOperationTokenType().equals(JavaTokenType.PLUSEQ)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})) {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static String test(List<String> list) {
|
||||
String sb;
|
||||
System.out.println("hello");
|
||||
sb = list.stream().filter(s -> !s.isEmpty()).map(String::trim).collect(Collectors.joining());
|
||||
String s = "Result: ";
|
||||
s += sb;
|
||||
System.out.println(s);
|
||||
return "[" + sb + "]";
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Test {
|
||||
static String test(List<String> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
System.out.println("hello");
|
||||
for(String s : li<caret>st) {
|
||||
if(!s.isEmpty()) {
|
||||
sb.append(s.trim());
|
||||
}
|
||||
}
|
||||
String s = "Result: ";
|
||||
s += sb;
|
||||
System.out.println(s);
|
||||
return "[" + sb + "]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user