Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2020-01-12 15:41:12 +0000
committerLars Vogel2020-02-07 06:46:17 +0000
commitaada320ac9b1d463031f9356923568a511e9278c (patch)
tree32c75434be17f230e47044fa4c85686010060999
parent403b7ce270e2f3874f924dd30710127a9c9456cc (diff)
downloadeclipse.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>
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java20
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java116
-rw-r--r--org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/ExtensionData.java22
-rw-r--r--org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java13
-rw-r--r--org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURL.java55
5 files changed, 143 insertions, 83 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java
index 312e10633..45e318034 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/CheatsheetSearchParticipant.java
@@ -85,19 +85,27 @@ public class CheatsheetSearchParticipant extends SearchParticipantXML {
@Override
protected void handleStartElement(String name, Attributes attributes,
IParsedXMLContent data) {
- if (name.equals(IParserTags.CHEATSHEET)) {
+ switch (name) {
+ case IParserTags.CHEATSHEET:
data.setTitle(attributes.getValue(IParserTags.TITLE));
data.addText(attributes.getValue(IParserTags.TITLE));
- } else if (name.equals(ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET)) {
+ break;
+ case ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET:
data.addText(attributes.getValue(ICompositeCheatsheetTags.NAME));
data.setTitle(attributes.getValue(ICompositeCheatsheetTags.NAME));
- } else if (name.equals(IParserTags.ITEM)) {
+ break;
+ case IParserTags.ITEM:
data.addText(attributes.getValue(IParserTags.TITLE));
- } else if (name.equals(IParserTags.SUBITEM)) {
+ break;
+ case IParserTags.SUBITEM:
data.addText(attributes.getValue(IParserTags.LABEL));
- } else if (name.equals(ICompositeCheatsheetTags.TASK )
- || name.equals(ICompositeCheatsheetTags.TASK_GROUP)) {
+ break;
+ case ICompositeCheatsheetTags.TASK:
+ case ICompositeCheatsheetTags.TASK_GROUP:
data.addText(attributes.getValue(ICompositeCheatsheetTags.NAME));
+ break;
+ default:
+ break;
}
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
index 296af80a3..18f4bb3f0 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
@@ -443,18 +443,22 @@ public class CheatSheetParser implements IStatusContainer {
isLeadingTrimRequired = false;
} else if(node.getNodeType() == Node.ELEMENT_NODE) {
// handle <b></b> and <br/>
- if(node.getNodeName().equals(IParserTags.BOLD)) {
+ switch (node.getNodeName()) {
+ case IParserTags.BOLD:
containsMarkup = true;
text.append(IParserTags.BOLD_START_TAG);
text.append(node.getFirstChild().getNodeValue());
text.append(IParserTags.BOLD_END_TAG);
isLeadingTrimRequired = false;
- } else if(node.getNodeName().equals(IParserTags.BREAK)) {
+ break;
+ case IParserTags.BREAK:
containsMarkup = true;
text.append(IParserTags.BREAK_TAG);
isLeadingTrimRequired = true;
- } else {
+ break;
+ default:
warnUnknownMarkupElement(startNode, nodeName, node);
+ break;
}
}
}
@@ -565,13 +569,17 @@ public class CheatSheetParser implements IStatusContainer {
if (attribute == null || attributeName == null)
continue;
- if (attributeName.equals(IParserTags.CONTEXTID)) {
+ switch (attributeName) {
+ case IParserTags.CONTEXTID:
item.setContextId(attribute.getNodeValue());
- } else if (attributeName.equals(IParserTags.HREF)) {
+ break;
+ case IParserTags.HREF:
item.setHref(attribute.getNodeValue());
- } else {
+ break;
+ default:
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ATTRIBUTE, (new Object[] {attributeName, introNode.getNodeName()}));
addStatus(IStatus.WARNING, message, null);
+ break;
}
}
}
@@ -593,11 +601,14 @@ public class CheatSheetParser implements IStatusContainer {
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
checker.checkElement(node.getNodeName());
- if(node.getNodeName().equals(IParserTags.ACTION)) {
+ switch (node.getNodeName()) {
+ case IParserTags.ACTION:
handleExecutable(item, node, new Action());
- } else if(node.getNodeName().equals(IParserTags.COMMAND)) {
+ break;
+ case IParserTags.COMMAND:
handleExecutable(item, node, new CheatSheetCommand());
- } else if(node.getNodeName().equals(IParserTags.DESCRIPTION)) {
+ break;
+ case IParserTags.DESCRIPTION:
if (hasDescription) {
String message = NLS.bind(Messages.ERROR_PARSING_MULTIPLE_DESCRIPTION, (new Object[] {itemNode.getNodeName()}));
addStatus(IStatus.ERROR, message, null);
@@ -605,21 +616,28 @@ public class CheatSheetParser implements IStatusContainer {
hasDescription = true;
handleDescription(item, node);
}
- } else if(node.getNodeName().equals(IParserTags.ON_COMPLETION)) {
+ break;
+ case IParserTags.ON_COMPLETION:
handleOnCompletion(item, node);
- } else if(node.getNodeName().equals(IParserTags.SUBITEM)) {
+ break;
+ case IParserTags.SUBITEM:
handleSubItem(item, node);
- } else if(node.getNodeName().equals(IParserTags.CONDITIONALSUBITEM)) {
+ break;
+ case IParserTags.CONDITIONALSUBITEM:
handleConditionalSubItem(item, node);
- } else if(node.getNodeName().equals(IParserTags.REPEATEDSUBITM)) {
+ break;
+ case IParserTags.REPEATEDSUBITM:
handleRepeatedSubItem(item, node);
- } else if(node.getNodeName().equals(IParserTags.PERFORMWHEN)) {
+ break;
+ case IParserTags.PERFORMWHEN:
handlePerformWhen(item, node);
- } else {
+ break;
+ default:
if(node.getNodeType() != Node.TEXT_NODE && node.getNodeType() != Node.COMMENT_NODE ) {
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ELEMENT, (new Object[] {node.getNodeName(), itemNode.getNodeName()}));
addStatus(IStatus.WARNING, message, null);
}
+ break;
}
}
@@ -647,18 +665,24 @@ public class CheatSheetParser implements IStatusContainer {
if (attribute == null || attributeName == null)
continue;
- if (attributeName.equals(IParserTags.TITLE)) {
+ switch (attributeName) {
+ case IParserTags.TITLE:
title = true;
item.setTitle(attribute.getNodeValue());
- } else if (attributeName.equals(IParserTags.CONTEXTID)) {
+ break;
+ case IParserTags.CONTEXTID:
item.setContextId(attribute.getNodeValue());
- } else if (attributeName.equals(IParserTags.HREF)) {
+ break;
+ case IParserTags.HREF:
item.setHref(attribute.getNodeValue());
- } else if (attributeName.equals(IParserTags.SKIP)) {
+ break;
+ case IParserTags.SKIP:
item.setSkip(attribute.getNodeValue().equals(TRUE_STRING));
- } else if (attributeName.equals(IParserTags.DIALOG)) {
+ break;
+ case IParserTags.DIALOG:
item.setDialog(attribute.getNodeValue().equals(TRUE_STRING));
- } else {
+ break;
+ default:
AbstractItemExtensionElement[] ie = handleUnknownItemAttribute(attribute, itemNode);
if (ie != null) {
itemExtensionElements.add(ie);
@@ -666,6 +690,7 @@ public class CheatSheetParser implements IStatusContainer {
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ATTRIBUTE, (new Object[] {attributeName, itemNode.getNodeName()}));
addStatus(IStatus.WARNING, message, null);
}
+ break;
}
}
}
@@ -718,17 +743,21 @@ public class CheatSheetParser implements IStatusContainer {
NodeList nodes = performWhenNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
- if(node.getNodeName().equals(IParserTags.ACTION)) {
+ switch (node.getNodeName()) {
+ case IParserTags.ACTION:
exeutable = true;
handleExecutable(performWhen, node, new Action());
- } else if(node.getNodeName().equals(IParserTags.COMMAND)) {
+ break;
+ case IParserTags.COMMAND:
exeutable = true;
handleExecutable(performWhen, node, new CheatSheetCommand());
- } else {
+ break;
+ default:
if(node.getNodeType() != Node.TEXT_NODE && node.getNodeType() != Node.COMMENT_NODE ) {
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ELEMENT, (new Object[] {node.getNodeName(), performWhenNode .getNodeName()}));
addStatus(IStatus.WARNING, message, null);
}
+ break;
}
}
@@ -813,13 +842,17 @@ public class CheatSheetParser implements IStatusContainer {
Node node = nodes.item(i);
checker.checkElement(node.getNodeName());
- if(node.getNodeName().equals(IParserTags.ACTION)) {
+ switch (node.getNodeName()) {
+ case IParserTags.ACTION:
handleExecutable(subItem, node, new Action());
- } else if(node.getNodeName().equals(IParserTags.COMMAND)) {
+ break;
+ case IParserTags.COMMAND:
handleExecutable(subItem, node, new CheatSheetCommand());
- } else if(node.getNodeName().equals(IParserTags.PERFORMWHEN)) {
+ break;
+ case IParserTags.PERFORMWHEN:
handlePerformWhen(subItem, node);
- } else if (node.getNodeName().equals(IParserTags.DESCRIPTION)) {
+ break;
+ case IParserTags.DESCRIPTION:
if (subItem.isFormatted()) {
String message = NLS.bind(
Messages.ERROR_PARSING_MULTIPLE_DESCRIPTION,
@@ -828,11 +861,13 @@ public class CheatSheetParser implements IStatusContainer {
} else {
handleSubItemDescription(subItem, node);
}
- } else {
+ break;
+ default:
if(node.getNodeType() != Node.TEXT_NODE && node.getNodeType() != Node.COMMENT_NODE ) {
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ELEMENT, (new Object[] {node.getNodeName(), subItemNode.getNodeName()}));
addStatus(IStatus.WARNING, message, null);
}
+ break;
}
}
handleSubItemAttributes(subItem, subItemNode);
@@ -851,15 +886,20 @@ public class CheatSheetParser implements IStatusContainer {
if (attribute == null || attributeName == null)
continue;
- if (attributeName.equals(IParserTags.LABEL)) {
+ switch (attributeName) {
+ case IParserTags.LABEL:
subItem.setLabel(attribute.getNodeValue());
- } else if (attributeName.equals(IParserTags.SKIP)) {
+ break;
+ case IParserTags.SKIP:
subItem.setSkip(attribute.getNodeValue().equals(TRUE_STRING));
- } else if (attributeName.equals(IParserTags.WHEN)) {
+ break;
+ case IParserTags.WHEN:
subItem.setWhen(attribute.getNodeValue());
- } else {
+ break;
+ default:
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ATTRIBUTE, (new Object[] {attributeName, subItemNode.getNodeName()}));
addStatus(IStatus.WARNING, message, null);
+ break;
}
}
}
@@ -1028,22 +1068,26 @@ public class CheatSheetParser implements IStatusContainer {
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
- if(node.getNodeName().equals(IParserTags.ITEM)) {
+ switch (node.getNodeName()) {
+ case IParserTags.ITEM:
hasItem = true;
Item item = handleItem(node);
cheatSheet.addItem(item);
- } else if(node.getNodeName().equals(IParserTags.INTRO)) {
+ break;
+ case IParserTags.INTRO:
if (hasIntro) {
addStatus(IStatus.ERROR, Messages.ERROR_PARSING_MORE_THAN_ONE_INTRO, null);
} else {
hasIntro = true;
handleIntroNode(cheatSheet, node);
}
- } else {
+ break;
+ default:
if(node.getNodeType() != Node.TEXT_NODE && node.getNodeType() != Node.COMMENT_NODE ) {
String message = NLS.bind(Messages.WARNING_PARSING_UNKNOWN_ELEMENT, (new Object[] {node.getNodeName(), rootnode.getNodeName()}));
addStatus(IStatus.WARNING, message, null);
}
+ break;
}
}
diff --git a/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/ExtensionData.java b/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/ExtensionData.java
index 3b851988c..2fc9eaa09 100644
--- a/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/ExtensionData.java
+++ b/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/ExtensionData.java
@@ -73,18 +73,28 @@ public class ExtensionData extends BaseData {
this.name = name;
this.implicit = implicit;
if (importance != null) {
- if (importance.equals(IUniversalIntroConstants.HIGH))
+ switch (importance) {
+ case IUniversalIntroConstants.HIGH:
fImportance = HIGH;
- else if (importance.equals(IUniversalIntroConstants.MEDIUM))
+ break;
+ case IUniversalIntroConstants.MEDIUM:
fImportance = MEDIUM;
- else if (importance.equals(IUniversalIntroConstants.LOW))
+ break;
+ case IUniversalIntroConstants.LOW:
fImportance = LOW;
- else if (importance.equals(IUniversalIntroConstants.CALLOUT))
+ break;
+ case IUniversalIntroConstants.CALLOUT:
fImportance = CALLOUT;
- else if (importance.equals(IUniversalIntroConstants.NEW))
+ break;
+ case IUniversalIntroConstants.NEW:
fImportance = NEW;
- else if (importance.equals(IUniversalIntroConstants.HIDDEN))
+ break;
+ case IUniversalIntroConstants.HIDDEN:
fImportance = HIDDEN;
+ break;
+ default:
+ break;
+ }
}
}
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();
+ }
}

Back to the top