diff options
author | Carsten Hammer | 2020-01-12 15:41:12 +0000 |
---|---|---|
committer | Lars Vogel | 2020-02-07 06:46:17 +0000 |
commit | aada320ac9b1d463031f9356923568a511e9278c (patch) | |
tree | 32c75434be17f230e47044fa4c85686010060999 /org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro | |
parent | 403b7ce270e2f3874f924dd30710127a9c9456cc (diff) | |
download | eclipse.platform.ua-aada320ac9b1d463031f9356923568a511e9278c.tar.gz eclipse.platform.ua-aada320ac9b1d463031f9356923568a511e9278c.tar.xz eclipse.platform.ua-aada320ac9b1d463031f9356923568a511e9278c.zip |
Use switch over strings where possible
Change cascades of ifs which can be converted to switch over Strings.
A switch statement might be faster than an if-then-else chain. And it
improves clarity.
The problem with if..else chain is that I have to look into all the if
conditions to understand what the program is doing. And the variable
might change in the chain processing.
Change-Id: If77bc5ffee41c236b56d82b226df4e55f6619bfc
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
Diffstat (limited to 'org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro')
2 files changed, 33 insertions, 35 deletions
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java index 79fb7182e..db66a14e3 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java @@ -398,13 +398,18 @@ public class IntroPartPresentation extends AbstractIntroElement { AbstractIntroPartImplementation implementation = null; try { - if (implementationType.equals(BROWSER_IMPL_KIND)) + switch (implementationType) { + case BROWSER_IMPL_KIND: implementation = //null; - new BrowserIntroPartImplementation(); - else if (implementationType.equals(FORMS_IMPL_KIND)) + new BrowserIntroPartImplementation(); + break; + case FORMS_IMPL_KIND: implementation = new FormIntroPartImplementation(); - else + break; + default: implementation = new TextIntroPartImplementation(); + break; + } } catch (Exception e) { Log.error("Could not instantiate implementation " //$NON-NLS-1$ + implementationType, e); diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURL.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURL.java index e75d7651d..eb08cf8ef 100644 --- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURL.java +++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURL.java @@ -155,63 +155,56 @@ public class IntroURL implements IIntroURL { } // check for all supported Intro actions first. - if (action.equals(CLOSE)) + switch (action) { + case CLOSE: return closeIntro(); - - else if (action.equals(SET_STANDBY_MODE)) + case SET_STANDBY_MODE: // Sets the state of the intro part. Does not care about passing // input to the part. return setStandbyState(getParameter(KEY_STANDBY)); - - else if (action.equals(SHOW_STANDBY)) + case SHOW_STANDBY: return handleStandbyState(getParameter(KEY_PART_ID), - getParameter(KEY_INPUT)); - - else if (action.equals(SHOW_HELP)) + getParameter(KEY_INPUT)); + case SHOW_HELP: // display the full Help System. return showHelp(); - - else if (action.equals(SHOW_HELP_TOPIC)) + case SHOW_HELP_TOPIC: // display a Help System Topic. It can be displayed in the Help // system window, or embedded as an intro page. // return showHelpTopic(getParameter(KEY_ID)); return showHelpTopic(getParameter(KEY_ID), getParameter(KEY_EMBED), - getParameter(KEY_EMBED_TARGET)); - - else if (action.equals(OPEN_BROWSER)) + getParameter(KEY_EMBED_TARGET)); + case OPEN_BROWSER: // display url in external browser return openBrowser(getParameter(KEY_URL), - getParameter(KEY_PLUGIN_ID)); - - if (action.equals(OPEN_URL)) + getParameter(KEY_PLUGIN_ID)); + default: + break; + } + switch (action) { + case OPEN_URL: // display url embedded in intro browser. return openURL(getParameter(KEY_URL), getParameter(KEY_PLUGIN_ID)); - - else if (action.equals(RUN_ACTION)) + case RUN_ACTION: // run an Intro action. Get the pluginId and the class keys. Pass // the parameters and the standby state. return runAction(getParameter(KEY_PLUGIN_ID), - getParameter(KEY_CLASS), parameters, getParameter(KEY_STANDBY)); - - else if (action.equals(EXECUTE)) + getParameter(KEY_CLASS), parameters, getParameter(KEY_STANDBY)); + case EXECUTE: // execute a serialized command return executeCommand(getParameter(KEY_COMAND), getParameter(KEY_STANDBY)); - - else if (action.equals(SHOW_PAGE)) + case SHOW_PAGE: // display an Intro Page. return showPage(getParameter(KEY_ID), getParameter(KEY_STANDBY)); - - else if (action.equals(SHOW_MESSAGE)) + case SHOW_MESSAGE: return showMessage(getParameter(KEY_MESSAGE)); - - else if (action.equals(NAVIGATE)) + case NAVIGATE: return navigate(getParameter(KEY_DIRECTION)); - - else if (action.equals(SWITCH_TO_LAUNCH_BAR)) + case SWITCH_TO_LAUNCH_BAR: return switchToLaunchBar(); - - else + default: return handleCustomAction(); + } } |