Skip to content

Commit 4616eea

Browse files
authored
fix: refactoring and removed overrided remove method (#851)
1 parent 5669571 commit 4616eea

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5-
import java.util.Map.Entry;
65

76
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
87
import org.eclipse.cdt.debug.core.launch.CoreBuildGenericLaunchConfigProvider;
@@ -11,12 +10,9 @@
1110
import org.eclipse.core.runtime.CoreException;
1211
import org.eclipse.debug.core.ILaunchConfiguration;
1312
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
14-
import org.eclipse.launchbar.core.ILaunchBarManager;
1513
import org.eclipse.launchbar.core.ILaunchDescriptor;
1614
import org.eclipse.launchbar.core.target.ILaunchTarget;
1715

18-
import com.espressif.idf.core.IDFCorePlugin;
19-
2016
public class IDFCoreLaunchConfigProvider extends CoreBuildGenericLaunchConfigProvider
2117
{
2218

@@ -31,15 +27,9 @@ public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor,
3127
IProject project = descriptor.getAdapter(IProject.class);
3228
if (project != null)
3329
{
34-
Map<String, ILaunchConfiguration> projectConfigs = configs.get(project);
35-
if (projectConfigs == null)
36-
{
37-
projectConfigs = new HashMap<>();
38-
configs.put(project, projectConfigs);
39-
}
4030

4131
String targetConfig = descriptor.getName();
42-
configuration = projectConfigs.get(targetConfig);
32+
configuration = configs.computeIfAbsent(project, key -> new HashMap<>()).get(targetConfig);
4333
if (configuration == null)
4434
{
4535
// do we already have one with the descriptor?
@@ -48,7 +38,7 @@ public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor,
4838
{
4939
configuration = createLaunchConfiguration(descriptor, target);
5040
}
51-
projectConfigs.put(configuration.getName(), configuration);
41+
configs.get(project).put(configuration.getName(), configuration);
5242
}
5343
}
5444
return configuration;
@@ -81,43 +71,12 @@ public boolean launchConfigurationAdded(ILaunchConfiguration configuration) thro
8171
}
8272
if (configuration.exists())
8373
{
84-
Map<String, ILaunchConfiguration> projectConfigs = configs.get(project);
85-
if (projectConfigs == null)
86-
{
87-
projectConfigs = new HashMap<>();
88-
configs.put(project, projectConfigs);
89-
}
90-
91-
projectConfigs.put(configuration.getName(), configuration);
74+
configs.computeIfAbsent(project, key -> new HashMap<>()).put(configuration.getName(), configuration);
9275
}
9376

9477
return ownsLaunchConfiguration(configuration);
9578
}
9679

97-
@Override
98-
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException
99-
{
100-
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
101-
for (Entry<IProject, Map<String, ILaunchConfiguration>> projectEntry : configs.entrySet())
102-
{
103-
Map<String, ILaunchConfiguration> projectConfigs = projectEntry.getValue();
104-
for (Entry<String, ILaunchConfiguration> entry : projectConfigs.entrySet())
105-
{
106-
if (configuration.equals(entry.getValue()))
107-
{
108-
projectConfigs.remove(entry.getKey());
109-
if (projectConfigs.isEmpty())
110-
{
111-
configs.remove(projectEntry.getKey());
112-
launchBarManager.launchObjectRemoved(projectEntry.getKey());
113-
}
114-
return true;
115-
}
116-
}
117-
}
118-
return false;
119-
}
120-
12180
@Override
12281
public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException
12382
{

0 commit comments

Comments
 (0)