From 53320a109f895c9db0eeec713f091068e1d58daa Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 6 Nov 2023 14:40:29 +0200 Subject: [PATCH] fix: refactoring and removed overrided remove method --- .../core/IDFCoreLaunchConfigProvider.java | 47 ++----------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java index 8fce45da9..0184ec257 100644 --- a/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java +++ b/bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java @@ -2,7 +2,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.launch.CoreBuildGenericLaunchConfigProvider; @@ -11,12 +10,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.launchbar.core.ILaunchBarManager; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.target.ILaunchTarget; -import com.espressif.idf.core.IDFCorePlugin; - public class IDFCoreLaunchConfigProvider extends CoreBuildGenericLaunchConfigProvider { @@ -31,15 +27,9 @@ public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IProject project = descriptor.getAdapter(IProject.class); if (project != null) { - Map projectConfigs = configs.get(project); - if (projectConfigs == null) - { - projectConfigs = new HashMap<>(); - configs.put(project, projectConfigs); - } String targetConfig = descriptor.getName(); - configuration = projectConfigs.get(targetConfig); + configuration = configs.computeIfAbsent(project, key -> new HashMap<>()).get(targetConfig); if (configuration == null) { // do we already have one with the descriptor? @@ -48,7 +38,7 @@ public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, { configuration = createLaunchConfiguration(descriptor, target); } - projectConfigs.put(configuration.getName(), configuration); + configs.get(project).put(configuration.getName(), configuration); } } return configuration; @@ -81,43 +71,12 @@ public boolean launchConfigurationAdded(ILaunchConfiguration configuration) thro } if (configuration.exists()) { - Map projectConfigs = configs.get(project); - if (projectConfigs == null) - { - projectConfigs = new HashMap<>(); - configs.put(project, projectConfigs); - } - - projectConfigs.put(configuration.getName(), configuration); + configs.computeIfAbsent(project, key -> new HashMap<>()).put(configuration.getName(), configuration); } return ownsLaunchConfiguration(configuration); } - @Override - public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException - { - ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); - for (Entry> projectEntry : configs.entrySet()) - { - Map projectConfigs = projectEntry.getValue(); - for (Entry entry : projectConfigs.entrySet()) - { - if (configuration.equals(entry.getValue())) - { - projectConfigs.remove(entry.getKey()); - if (projectConfigs.isEmpty()) - { - configs.remove(projectEntry.getKey()); - launchBarManager.launchObjectRemoved(projectEntry.getKey()); - } - return true; - } - } - } - return false; - } - @Override public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException {