Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHannes Wellmann2021-02-11 20:10:12 +0000
committerHannes Wellmann2021-02-11 21:34:07 +0000
commitab4870b76608bafa5e0ce9140d904f58e24bf7fc (patch)
treeb46752c356cbcbbb964bf11a654b85ba7cba01b8
parenta41f459946f4d2efc87756f70964a4f3fa63b8c4 (diff)
downloadeclipse.platform.debug-ab4870b76608bafa5e0ce9140d904f58e24bf7fc.tar.gz
eclipse.platform.debug-ab4870b76608bafa5e0ce9140d904f58e24bf7fc.tar.xz
eclipse.platform.debug-ab4870b76608bafa5e0ce9140d904f58e24bf7fc.zip
CommonTab: add utility to get LaunchConfig attributes without ExceptionY20210212-1200I20210212-1840I20210211-1810
This avoids try-catch blocks when getting an attribute and increases readability of the methods that contains logic. In the method updateConfigFromFavorites now the update continues with the default-value instead of stopping inbetween, if getAttribute throws a CoreException. Change-Id: I204520f37edd86fa4b3b81ba770f32ba5f4c46dd Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java169
1 files changed, 86 insertions, 83 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java
index de4dd1bd4..5e34555e7 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/CommonTab.java
@@ -628,20 +628,13 @@ public class CommonTab extends AbstractLaunchConfigurationTab {
* @param configuration the local configuration
*/
private void updateConsoleOutput(ILaunchConfiguration configuration) {
- boolean outputToConsole = true;
- String stdinFromFile = null;
- String outputFile = null;
- boolean append = false;
- boolean mergeOutput = false;
+ boolean outputToConsole = getAttribute(configuration, IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true);
+ String stdinFromFile = getAttribute(configuration, IDebugUIConstants.ATTR_CAPTURE_STDIN_FILE, (String) null);
+ String outputFile = getAttribute(configuration, IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String) null);
+ boolean append = getAttribute(configuration, IDebugUIConstants.ATTR_APPEND_TO_FILE, false);
+ boolean mergeOutput = getAttribute(configuration, DebugPlugin.ATTR_MERGE_OUTPUT, false);
boolean supportsMergeOutput = false;
-
try {
- outputToConsole = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true);
- stdinFromFile = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_STDIN_FILE, (String) null);
-
- outputFile = configuration.getAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_FILE, (String)null);
- append = configuration.getAttribute(IDebugUIConstants.ATTR_APPEND_TO_FILE, false);
- mergeOutput = configuration.getAttribute(DebugPlugin.ATTR_MERGE_OUTPUT, false);
supportsMergeOutput = configuration.getType().supportsOutputMerging();
} catch (CoreException e) {
}
@@ -688,11 +681,7 @@ public class CommonTab extends AbstractLaunchConfigurationTab {
* @param configuration the local configuration
*/
private void updateEncoding(ILaunchConfiguration configuration) {
- String encoding = null;
- try {
- encoding = configuration.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String)null);
- } catch (CoreException e) {
- }
+ String encoding = getAttribute(configuration, DebugPlugin.ATTR_CONSOLE_ENCODING, (String) null);
String defaultEncoding = getDefaultEncoding(configuration);
fDefaultEncodingButton.setText(MessageFormat.format(LaunchConfigurationsMessages.CommonTab_2, defaultEncoding));
fDefaultEncodingButton.pack();
@@ -715,13 +704,7 @@ public class CommonTab extends AbstractLaunchConfigurationTab {
* @return whether the configuration is configured to launch in the background
*/
public static boolean isLaunchInBackground(ILaunchConfiguration configuration) {
- boolean launchInBackground= true;
- try {
- launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
- } catch (CoreException ce) {
- DebugUIPlugin.log(ce);
- }
- return launchInBackground;
+ return getAttribute(configuration, IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
}
/**
@@ -732,29 +715,26 @@ public class CommonTab extends AbstractLaunchConfigurationTab {
private void updateFavoritesFromConfig(ILaunchConfiguration config) {
fFavoritesTable.setInput(config);
fFavoritesTable.setCheckedElements(new Object[]{});
- try {
- List<String> groups = config.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, new ArrayList<>());
- if (groups.isEmpty()) {
- // check old attributes for backwards compatible
- if (config.getAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, false)) {
- groups.add(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP);
- }
- if (config.getAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, false)) {
- groups.add(IDebugUIConstants.ID_RUN_LAUNCH_GROUP);
- }
+ List<String> groups = getAttribute(config, IDebugUIConstants.ATTR_FAVORITE_GROUPS, new ArrayList<>());
+
+ if (groups.isEmpty()) {
+ // check old attributes for backwards compatible
+ if (getAttribute(config, IDebugUIConstants.ATTR_DEBUG_FAVORITE, false)) {
+ groups.add(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP);
}
- if (!groups.isEmpty()) {
- List<LaunchGroupExtension> list = new ArrayList<>();
- for (String id : groups) {
- LaunchGroupExtension extension = getLaunchConfigurationManager().getLaunchGroup(id);
- if (extension != null) {
- list.add(extension);
- }
+ if (getAttribute(config, IDebugUIConstants.ATTR_RUN_FAVORITE, false)) {
+ groups.add(IDebugUIConstants.ID_RUN_LAUNCH_GROUP);
+ }
+ }
+ if (!groups.isEmpty()) {
+ List<LaunchGroupExtension> list = new ArrayList<>();
+ for (String id : groups) {
+ LaunchGroupExtension extension = getLaunchConfigurationManager().getLaunchGroup(id);
+ if (extension != null) {
+ list.add(extension);
}
- fFavoritesTable.setCheckedElements(list.toArray());
}
- } catch (CoreException e) {
- DebugUIPlugin.log(e);
+ fFavoritesTable.setCheckedElements(list.toArray());
}
}
@@ -796,49 +776,72 @@ public class CommonTab extends AbstractLaunchConfigurationTab {
*/
@SuppressWarnings("deprecation")
private void updateConfigFromFavorites(ILaunchConfigurationWorkingCopy config) {
- try {
- Object[] checked = fFavoritesTable.getCheckedElements();
- boolean debug = config.getAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, false);
- boolean run = config.getAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, false);
- if (debug || run) {
- // old attributes
- List<LaunchGroupExtension> groups = new ArrayList<>();
- int num = 0;
- if (debug) {
- groups.add(getLaunchConfigurationManager().getLaunchGroup(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP));
- num++;
- }
- if (run) {
- num++;
- groups.add(getLaunchConfigurationManager().getLaunchGroup(IDebugUIConstants.ID_RUN_LAUNCH_GROUP));
- }
- // see if there are any changes
- if (num == checked.length) {
- boolean different = false;
- for (Object checked1 : checked) {
- if (!groups.contains(checked1)) {
- different = true;
- break;
- }
- }
- if (!different) {
- return;
+ Object[] checked = fFavoritesTable.getCheckedElements();
+ boolean debug = getAttribute(config, IDebugUIConstants.ATTR_DEBUG_FAVORITE, false);
+ boolean run = getAttribute(config, IDebugUIConstants.ATTR_RUN_FAVORITE, false);
+ if (debug || run) {
+ // old attributes
+ List<LaunchGroupExtension> groups = new ArrayList<>();
+ int num = 0;
+ if (debug) {
+ groups.add(getLaunchConfigurationManager().getLaunchGroup(IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP));
+ num++;
+ }
+ if (run) {
+ num++;
+ groups.add(getLaunchConfigurationManager().getLaunchGroup(IDebugUIConstants.ID_RUN_LAUNCH_GROUP));
+ }
+ // see if there are any changes
+ if (num == checked.length) {
+ boolean different = false;
+ for (Object checked1 : checked) {
+ if (!groups.contains(checked1)) {
+ different = true;
+ break;
}
}
- }
- config.setAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, (String)null);
- config.setAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, (String)null);
- List<String> groups = null;
- for (Object c : checked) {
- LaunchGroupExtension group = (LaunchGroupExtension) c;
- if (groups == null) {
- groups = new ArrayList<>();
+ if (!different) {
+ return;
}
- groups.add(group.getIdentifier());
}
- config.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, groups);
- } catch (CoreException e) {
- DebugUIPlugin.log(e);
+ }
+ config.setAttribute(IDebugUIConstants.ATTR_DEBUG_FAVORITE, (String) null);
+ config.setAttribute(IDebugUIConstants.ATTR_RUN_FAVORITE, (String) null);
+ List<String> groups = null;
+ for (Object c : checked) {
+ LaunchGroupExtension group = (LaunchGroupExtension) c;
+ if (groups == null) {
+ groups = new ArrayList<>();
+ }
+ groups.add(group.getIdentifier());
+ }
+ config.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, groups);
+ }
+
+ private static boolean getAttribute(ILaunchConfiguration config, String attribute, boolean defaultValue) {
+ try {
+ return config.getAttribute(attribute, defaultValue);
+ } catch (CoreException ce) {
+ DebugUIPlugin.log(ce);
+ return defaultValue;
+ }
+ }
+
+ private static String getAttribute(ILaunchConfiguration config, String attribute, String defaultValue) {
+ try {
+ return config.getAttribute(attribute, defaultValue);
+ } catch (CoreException ce) {
+ DebugUIPlugin.log(ce);
+ return defaultValue;
+ }
+ }
+
+ private static List<String> getAttribute(ILaunchConfiguration config, String attribute, List<String> defaultValue) {
+ try {
+ return config.getAttribute(attribute, defaultValue);
+ } catch (CoreException ce) {
+ DebugUIPlugin.log(ce);
+ return defaultValue;
}
}

Back to the top