mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-55507 - IOE: PsiJavaParserFacadeImpl.createStatementFromText
This commit is contained in:
+15
-2
@@ -255,7 +255,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
final PsiParameter parameter = foreachStatement.getIterationParameter();
|
||||
final PsiIfStatement ifStmt = extractIfStatement(body);
|
||||
|
||||
String foreEachText = body.getText();
|
||||
String foreEachText = wrapInBlock(body);
|
||||
String iterated = iteratedValue.getText();
|
||||
if (ifStmt != null) {
|
||||
final PsiExpression condition = ifStmt.getCondition();
|
||||
@@ -264,7 +264,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
LOG.assertTrue(thenBranch != null);
|
||||
if (InheritanceUtil.isInheritor(iteratedValue.getType(), CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
body = thenBranch;
|
||||
foreEachText = thenBranch.getText();
|
||||
foreEachText = wrapInBlock(thenBranch);
|
||||
iterated += ".stream().filter(" + parameter.getName() + " -> " + condition.getText() +")";
|
||||
}
|
||||
}
|
||||
@@ -298,6 +298,19 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String wrapInBlock(PsiStatement body) {
|
||||
|
||||
if (body instanceof PsiExpressionStatement) {
|
||||
return ((PsiExpressionStatement)body).getExpression().getText();
|
||||
}
|
||||
|
||||
final String bodyText = body.getText();
|
||||
if (!(body instanceof PsiBlockStatement)) {
|
||||
return "{" + bodyText + "}";
|
||||
}
|
||||
return bodyText;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ReplaceWithCollectCallFix implements LocalQuickFix {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
foo.stream().filter(s -> s == null).forEach(s -> {
|
||||
int i = 0;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace with forEach" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
for (String s : fo<caret>o) {
|
||||
if (s == null) int i = 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user