mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-160946 Labeled continue is excluded; understand if(..) continue else {...}; more tests
This commit is contained in:
+12
-7
@@ -1014,9 +1014,10 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
// extract filter
|
||||
if(getSingleStatement() instanceof PsiIfStatement) {
|
||||
PsiIfStatement ifStatement = (PsiIfStatement)getSingleStatement();
|
||||
if(ifStatement.getElseBranch() != null || ifStatement.getCondition() == null) return null;
|
||||
replaceWith(ifStatement.getThenBranch());
|
||||
return new FilterOp(ifStatement.getCondition(), myVariable, false);
|
||||
if(ifStatement.getElseBranch() == null && ifStatement.getCondition() != null) {
|
||||
replaceWith(ifStatement.getThenBranch());
|
||||
return new FilterOp(ifStatement.getCondition(), myVariable, false);
|
||||
}
|
||||
}
|
||||
// extract flatMap
|
||||
if(getSingleStatement() instanceof PsiForeachStatement) {
|
||||
@@ -1047,7 +1048,7 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
}
|
||||
}
|
||||
}
|
||||
if(myStatements.length > 1) {
|
||||
if(myStatements.length >= 1) {
|
||||
PsiStatement first = myStatements[0];
|
||||
// extract map
|
||||
if(first instanceof PsiDeclarationStatement) {
|
||||
@@ -1077,15 +1078,19 @@ public class StreamApiMigrationInspection extends BaseJavaBatchLocalInspectionTo
|
||||
// extract filter with negation
|
||||
if(first instanceof PsiIfStatement) {
|
||||
PsiIfStatement ifStatement = (PsiIfStatement)first;
|
||||
if(ifStatement.getElseBranch() != null || ifStatement.getCondition() == null) return null;
|
||||
if(ifStatement.getCondition() == null) return null;
|
||||
PsiStatement branch = ifStatement.getThenBranch();
|
||||
if(branch instanceof PsiBlockStatement) {
|
||||
PsiStatement[] statements = ((PsiBlockStatement)branch).getCodeBlock().getStatements();
|
||||
if(statements.length == 1)
|
||||
branch = statements[0];
|
||||
}
|
||||
if(!(branch instanceof PsiContinueStatement)) return null;
|
||||
myStatements = Arrays.copyOfRange(myStatements, 1, myStatements.length);
|
||||
if(!(branch instanceof PsiContinueStatement) || ((PsiContinueStatement)branch).getLabelIdentifier() != null) return null;
|
||||
if(ifStatement.getElseBranch() != null) {
|
||||
myStatements[0] = ifStatement.getElseBranch();
|
||||
} else {
|
||||
myStatements = Arrays.copyOfRange(myStatements, 1, myStatements.length);
|
||||
}
|
||||
flatten();
|
||||
return new FilterOp(ifStatement.getCondition(), myVariable, true);
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Map.Entry::getValue).filter(Objects::nonNull).flatMap(Collection::stream).map(String::trim).filter(trimmed -> !trimmed.isEmpty()).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = map.entrySet().stream().filter(entry -> !entry.getKey().isEmpty()).map(Map.Entry::getValue).filter(Objects::nonNull).flatMap(Collection::stream).map(String::trim).filter(trimmed -> !trimmed.isEmpty()).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for(Map.Entry<String, List<String>> entry : map.en<caret>trySet()) {
|
||||
if(entry.getKey().isEmpty()) continue;
|
||||
List<String> list = entry.getValue();
|
||||
if(list == null) continue;
|
||||
for(String str : list) {
|
||||
String trimmed = str.trim();
|
||||
if(trimmed.isEmpty()) continue;
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace with collect" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for(Map.Entry<String, List<String>> entry : map.en<caret>trySet()) {
|
||||
if(entry.getKey().isEmpty()) continue;
|
||||
else {
|
||||
List<String> list = entry.getValue();
|
||||
if (list == null) continue;
|
||||
for (String str : list) {
|
||||
String trimmed = str.trim();
|
||||
if (trimmed.isEmpty()) continue;
|
||||
else result.add(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace with forEach" "false"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
|
||||
public List<String> test(Map<String, List<String>> map) {
|
||||
List<String> result = new ArrayList<>();
|
||||
outer:
|
||||
for(Map.Entry<String, List<String>> entry : map.ent<caret>rySet()) {
|
||||
if(entry.getKey().isEmpty()) continue;
|
||||
List<String> list = entry.getValue();
|
||||
if(list == null) continue;
|
||||
for(String str : list) {
|
||||
String trimmed = str.trim();
|
||||
if(trimmed.isEmpty()) continue outer;
|
||||
result.add(trimmed);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user