mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix replace with computeIfAbsent when resulting var is not used (see also IDEA-166625)
This commit is contained in:
@@ -464,7 +464,7 @@ public class Java8MapApiInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
ct.deleteAndRestoreComments(conditional);
|
||||
}
|
||||
PsiVariable variable = condition.extractDeclaration();
|
||||
if(variable != null && ReferencesSearch.search(variable).findFirst() == null) {
|
||||
if (variable != null && !PsiTreeUtil.isAncestor(result, variable, true) && ReferencesSearch.search(variable).findFirst() == null) {
|
||||
new CommentTracker().deleteAndRestoreComments(variable);
|
||||
}
|
||||
CodeStyleManager.getInstance(project).reformat(result);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Test {
|
||||
interface Shift {}
|
||||
void foo(Map<String, List<Shift>> dayOfWeekAndShiftTypeToShiftListMap, String key){
|
||||
List<Shift> dayOfWeekAndShiftTypeToShiftList = dayOfWeekAndShiftTypeToShiftListMap.computeIfAbsent(key, k -> new ArrayList<>((6) / 7));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace with 'computeIfAbsent' method call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Test {
|
||||
interface Shift {}
|
||||
void foo(Map<String, List<Shift>> dayOfWeekAndShiftTypeToShiftListMap, String key){
|
||||
List<Shift> dayOfWeekAndShiftTypeToShiftList = dayOfWeekAndShiftTypeToShiftListMap.get(key);
|
||||
if (<caret>dayOfWeekAndShiftTypeToShiftList == null) {
|
||||
dayOfWeekAndShiftTypeToShiftList = new ArrayList<>((6) / 7);
|
||||
dayOfWeekAndShiftTypeToShiftListMap.put(key, dayOfWeekAndShiftTypeToShiftList);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user