mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java8ReplaceMapGetInspection: missing statements.length check is added (EA-91331)
This commit is contained in:
+1
@@ -132,6 +132,7 @@ public class Java8ReplaceMapGetInspection extends BaseJavaBatchLocalInspectionTo
|
||||
if (!(statement instanceof PsiBlockStatement)) return null;
|
||||
// like val = new ArrayList<>(); map.put(key, val);
|
||||
PsiStatement[] statements = ((PsiBlockStatement)statement).getCodeBlock().getStatements();
|
||||
if (statements.length != 2) return null;
|
||||
putCall = extractPutCall(statements[1]);
|
||||
if (putCall == null) return null;
|
||||
PsiExpression[] putArguments = putCall.getArgumentList().getExpressions();
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "false"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMap(Map<String, List<String>> map, String key, String value) {
|
||||
List<String> list = map.get(key);
|
||||
if(list == nul<caret>l) {
|
||||
list = new ArrayList<>();
|
||||
map.put(key, list);
|
||||
System.out.println("Added new!");
|
||||
}
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "false"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
public void testMap(Map<String, List<String>> map, String key, String value) {
|
||||
List<String> list = map.get(key);
|
||||
if(list == nul<caret>l) {
|
||||
}
|
||||
list.add(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user