mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace to computeIfAbsent() in several places using new Java 8 migration quick-fix
This commit is contained in:
+4
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -181,23 +181,13 @@ public abstract class AbstractIdeModifiableModelsProvider extends IdeModelsProvi
|
||||
|
||||
@NotNull
|
||||
private ModuleRootModel getRootModel(Module module) {
|
||||
ModifiableRootModel result = myModifiableRootModels.get(module);
|
||||
if (result == null) {
|
||||
result = doGetModifiableRootModel(module);
|
||||
myModifiableRootModels.put(module, result);
|
||||
}
|
||||
return result;
|
||||
return myModifiableRootModels.computeIfAbsent(module, k -> doGetModifiableRootModel(module));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ModifiableFacetModel getModifiableFacetModel(Module module) {
|
||||
ModifiableFacetModel result = myModifiableFacetModels.get(module);
|
||||
if (result == null) {
|
||||
result = doGetModifiableFacetModel(module);
|
||||
myModifiableFacetModels.put(module, result);
|
||||
}
|
||||
return result;
|
||||
return myModifiableFacetModels.computeIfAbsent(module, k -> doGetModifiableFacetModel(module));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,12 +223,7 @@ public abstract class AbstractIdeModifiableModelsProvider extends IdeModelsProvi
|
||||
|
||||
@Override
|
||||
public Library.ModifiableModel getModifiableLibraryModel(Library library) {
|
||||
Library.ModifiableModel result = myModifiableLibraryModels.get(library);
|
||||
if (result == null) {
|
||||
result = doGetModifiableLibraryModel(library);
|
||||
myModifiableLibraryModels.put(library, result);
|
||||
}
|
||||
return result;
|
||||
return myModifiableLibraryModels.computeIfAbsent(library, k -> doGetModifiableLibraryModel(library));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -92,7 +92,6 @@ public abstract class AbstractNavBarUI implements NavBarUI {
|
||||
final boolean selected = item.isSelected() && item.isFocused();
|
||||
boolean nextSelected = item.isNextSelected() && navbar.hasFocus();
|
||||
|
||||
Map<ImageType, BufferedImage> cached = myCache.get(item);
|
||||
|
||||
ImageType type;
|
||||
if (floating) {
|
||||
@@ -105,16 +104,9 @@ public abstract class AbstractNavBarUI implements NavBarUI {
|
||||
}
|
||||
}
|
||||
|
||||
if (cached == null) {
|
||||
cached = new HashMap<>();
|
||||
myCache.put(item, cached);
|
||||
}
|
||||
Map<ImageType, BufferedImage> cached = myCache.computeIfAbsent(item, k -> new HashMap<>());
|
||||
|
||||
BufferedImage image = cached.get(type);
|
||||
if (image == null) {
|
||||
image = drawToBuffer(item, floating, toolbarVisible, selected, navbar);
|
||||
cached.put(type, image);
|
||||
}
|
||||
BufferedImage image = cached.computeIfAbsent(type, k -> drawToBuffer(item, floating, toolbarVisible, selected, navbar));
|
||||
|
||||
UIUtil.drawImage(g, image, 0, 0, null);
|
||||
|
||||
|
||||
+2
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,12 +46,7 @@ public abstract class AbstractProjectNode extends ProjectViewNode<Project> {
|
||||
final String[] path = ModuleManager.getInstance(getProject()).getModuleGroupPath(module);
|
||||
if (path != null) {
|
||||
final String topLevelGroupName = path[0];
|
||||
List<Module> moduleList = groups.get(topLevelGroupName);
|
||||
if (moduleList == null) {
|
||||
moduleList = new ArrayList<>();
|
||||
groups.put(topLevelGroupName, moduleList);
|
||||
}
|
||||
moduleList.add(module);
|
||||
groups.computeIfAbsent(topLevelGroupName, k -> new ArrayList<>()).add(module);
|
||||
nonGroupedModules.remove(module);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,22 +110,11 @@ public abstract class AbstractMemberInfoStorage<T extends PsiElement, C extends
|
||||
}
|
||||
|
||||
protected LinkedHashSet<C> getSubclasses(C aClass) {
|
||||
LinkedHashSet<C> result = myClassToSubclassesMap.get(aClass);
|
||||
if(result == null) {
|
||||
result = new LinkedHashSet<>();
|
||||
myClassToSubclassesMap.put(aClass, result);
|
||||
}
|
||||
return result;
|
||||
return myClassToSubclassesMap.computeIfAbsent(aClass, k -> new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
public Set<M> getDuplicatedMemberInfos(C baseClass) {
|
||||
HashSet<M> result = myTargetClassToDuplicatedMemberInfosMap.get(baseClass);
|
||||
|
||||
if(result == null) {
|
||||
result = buildDuplicatedMemberInfos(baseClass);
|
||||
myTargetClassToDuplicatedMemberInfosMap.put(baseClass, result);
|
||||
}
|
||||
return result;
|
||||
return myTargetClassToDuplicatedMemberInfosMap.computeIfAbsent(baseClass, k -> buildDuplicatedMemberInfos(baseClass));
|
||||
}
|
||||
|
||||
private HashSet<M> buildDuplicatedMemberInfos(C baseClass) {
|
||||
|
||||
@@ -4694,12 +4694,7 @@ public class AbstractTreeUi {
|
||||
|
||||
private void _addNodeAction(Object element, NodeAction action, @NotNull Map<Object, List<NodeAction>> map) {
|
||||
maybeSetBusyAndScheduleWaiterForReady(true, element);
|
||||
List<NodeAction> list = map.get(element);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
map.put(element, list);
|
||||
}
|
||||
list.add(action);
|
||||
map.computeIfAbsent(element, k -> new ArrayList<>()).add(action);
|
||||
|
||||
addActivity();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,12 +27,7 @@ import java.util.Map;
|
||||
|
||||
public class ActionGroupUtil {
|
||||
private static Presentation getPresentation(AnAction action, Map<AnAction, Presentation> action2presentation) {
|
||||
Presentation presentation = action2presentation.get(action);
|
||||
if (presentation == null) {
|
||||
presentation = action.getTemplatePresentation().clone();
|
||||
action2presentation.put(action, presentation);
|
||||
}
|
||||
return presentation;
|
||||
return action2presentation.computeIfAbsent(action, k -> action.getTemplatePresentation().clone());
|
||||
}
|
||||
|
||||
public static boolean isGroupEmpty(@NotNull ActionGroup actionGroup, @NotNull AnActionEvent e) {
|
||||
|
||||
+6
-27
@@ -25,6 +25,7 @@ import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
@@ -82,11 +83,7 @@ public class AbbreviationManagerImpl extends AbbreviationManager implements Pers
|
||||
if (actions != null && actions.size() > 0) {
|
||||
for (Element action : actions) {
|
||||
final String actionId = action.getAttributeValue("id");
|
||||
LinkedHashSet<String> values = myActionId2Abbreviations.get(actionId);
|
||||
if (values == null) {
|
||||
values = new LinkedHashSet<>(1);
|
||||
myActionId2Abbreviations.put(actionId, values);
|
||||
}
|
||||
LinkedHashSet<String> values = myActionId2Abbreviations.computeIfAbsent(actionId, k -> new LinkedHashSet<>(1));
|
||||
|
||||
final List<Element> abbreviation = action.getChildren("abbreviation");
|
||||
if (abbreviation != null) {
|
||||
@@ -94,12 +91,7 @@ public class AbbreviationManagerImpl extends AbbreviationManager implements Pers
|
||||
final String abbrValue = abbr.getAttributeValue("name");
|
||||
if (abbrValue != null) {
|
||||
values.add(abbrValue);
|
||||
List<String> actionIds = myAbbreviation2ActionId.get(abbrValue);
|
||||
if (actionIds == null) {
|
||||
actionIds = new ArrayList<>();
|
||||
myAbbreviation2ActionId.put(abbrValue, actionIds);
|
||||
}
|
||||
actionIds.add(actionId);
|
||||
myAbbreviation2ActionId.computeIfAbsent(abbrValue, k -> new ArrayList<>()).add(actionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,11 +102,7 @@ public class AbbreviationManagerImpl extends AbbreviationManager implements Pers
|
||||
|
||||
@Override
|
||||
public Set<String> getAbbreviations() {
|
||||
final Set<String> result = new HashSet<>();
|
||||
for (Set<String> abbrs : myActionId2Abbreviations.values()) {
|
||||
result.addAll(abbrs);
|
||||
}
|
||||
return result;
|
||||
return myActionId2Abbreviations.values().stream().flatMap(Set::stream).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,12 +122,7 @@ public class AbbreviationManagerImpl extends AbbreviationManager implements Pers
|
||||
|
||||
|
||||
public void register(String abbreviation, String actionId, Map<String, LinkedHashSet<String>> storage) {
|
||||
LinkedHashSet<String> abbreviations = storage.get(actionId);
|
||||
if (abbreviations == null) {
|
||||
abbreviations = new LinkedHashSet<>(1);
|
||||
storage.put(actionId, abbreviations);
|
||||
}
|
||||
abbreviations.add(abbreviation);
|
||||
storage.computeIfAbsent(actionId, k -> new LinkedHashSet<>(1)).add(abbreviation);
|
||||
}
|
||||
|
||||
public void register(String abbreviation, String actionId, boolean fromPluginXml) {
|
||||
@@ -152,11 +135,7 @@ public class AbbreviationManagerImpl extends AbbreviationManager implements Pers
|
||||
register(abbreviation, actionId, myPluginsActionId2Abbreviations);
|
||||
}
|
||||
|
||||
List<String> ids = myAbbreviation2ActionId.get(abbreviation);
|
||||
if (ids == null) {
|
||||
ids = new ArrayList<>(0);
|
||||
myAbbreviation2ActionId.put(abbreviation, ids);
|
||||
}
|
||||
List<String> ids = myAbbreviation2ActionId.computeIfAbsent(abbreviation, k -> new ArrayList<>(0));
|
||||
|
||||
if (!ids.contains(actionId)) {
|
||||
ids.add(actionId);
|
||||
|
||||
+2
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -993,12 +993,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Disposab
|
||||
myId2Index.put(actionId, myRegisteredActionsCount++);
|
||||
myAction2Id.put(action, actionId);
|
||||
if (pluginId != null && !(action instanceof ActionGroup)){
|
||||
THashSet<String> pluginActionIds = myPlugin2Id.get(pluginId);
|
||||
if (pluginActionIds == null){
|
||||
pluginActionIds = new THashSet<>();
|
||||
myPlugin2Id.put(pluginId, pluginActionIds);
|
||||
}
|
||||
pluginActionIds.add(actionId);
|
||||
myPlugin2Id.computeIfAbsent(pluginId, k -> new THashSet<>()).add(actionId);
|
||||
}
|
||||
action.registerCustomShortcutSet(new ProxyShortcutSet(actionId, myKeymapManager), null);
|
||||
}
|
||||
|
||||
+2
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@ package com.intellij.ide.util.treeView;
|
||||
|
||||
import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.openapi.util.AsyncResult;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
@@ -526,12 +525,7 @@ abstract class AbstractTreeBuilderTest extends BaseTreeTestCase<BaseTreeTestCase
|
||||
}
|
||||
|
||||
private void onElementAction(String action, NodeElement element) {
|
||||
ElementEntry entry = myElementUpdate.get(element);
|
||||
if (entry == null) {
|
||||
entry = new ElementEntry(element);
|
||||
myElementUpdate.put(element, entry);
|
||||
}
|
||||
entry.onElementAction(action);
|
||||
myElementUpdate.computeIfAbsent(element, k -> new ElementEntry(element)).onElementAction(action);
|
||||
|
||||
if (myElementUpdateHook != null) {
|
||||
myElementUpdateHook.onElementAction(action, element);
|
||||
|
||||
+2
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -394,12 +394,7 @@ public abstract class AbstractCommonUpdateAction extends AbstractVcsAction {
|
||||
|
||||
private void putExceptions(final HotfixData key, @NotNull final List<VcsException> list) {
|
||||
if (list.isEmpty()) return;
|
||||
List<VcsException> exceptionList = myGroupedExceptions.get(key);
|
||||
if (exceptionList == null) {
|
||||
exceptionList = new ArrayList<>();
|
||||
myGroupedExceptions.put(key, exceptionList);
|
||||
}
|
||||
exceptionList.addAll(list);
|
||||
myGroupedExceptions.computeIfAbsent(key, k -> new ArrayList<>()).addAll(list);
|
||||
}
|
||||
|
||||
private void doVfsRefresh() {
|
||||
|
||||
+2
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -72,12 +72,7 @@ public abstract class AbstractFunctionContext implements FunctionContext {
|
||||
}
|
||||
|
||||
protected static synchronized FunctionContext getInstance(ContextType contextType, Factory<FunctionContext> factory) {
|
||||
FunctionContext context = ourInstances.get(contextType);
|
||||
if (context == null) {
|
||||
context = factory.create();
|
||||
ourInstances.put(contextType, context);
|
||||
}
|
||||
return context;
|
||||
return ourInstances.computeIfAbsent(contextType, k -> factory.create());
|
||||
}
|
||||
|
||||
public Map<Pair<QName, Integer>, Function> getFunctions() {
|
||||
|
||||
Reference in New Issue
Block a user