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: I936f634408bce4b867ca8794debe1a12500e0de6
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java
index 2ab5a84..dcb0015 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java
@@ -197,21 +197,23 @@
 			buffer.append(string.substring(complete, matcher.start()));
 
 			// check the escaped sequence
-			if ("$".equals(matcher.group())) { //$NON-NLS-1$
+			switch (matcher.group()) {
+			case "$": //$NON-NLS-1$
 				fail(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$
-			} else if ("$$".equals(matcher.group())) { //$NON-NLS-1$
+				break;
+			case "$$": //$NON-NLS-1$
 				// escaped $
 				buffer.append('$');
-			} else {
+				break;
+			default:
 				// parse variable
 				String name= matcher.group(1);
 				String typeName= matcher.group(2);
 				String params= matcher.group(3);
 				TemplateVariableType type= createType(typeName, params);
-
 				updateOrCreateVariable(variables, name, type, buffer.length());
-
 				buffer.append(name);
+				break;
 			}
 			complete= matcher.end();
 		}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/rulers/RulerColumnPlacement.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/rulers/RulerColumnPlacement.java
index 29628e9..86237ae 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/rulers/RulerColumnPlacement.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/rulers/RulerColumnPlacement.java
@@ -63,12 +63,19 @@
 		for (IConfigurationElement child : children) {
 			String name= child.getName();
 			ExtensionPointHelper childHelper= new ExtensionPointHelper(child);
+			if (name == null) {
+				childHelper.fail(RulerColumnMessages.RulerColumnPlacement_illegal_child_msg);
+				continue;
+			}
 			boolean before;
-			if (AFTER.equals(name))
+			switch (name) {
+			case AFTER:
 				before= false;
-			else if (BEFORE.equals(name))
+				break;
+			case BEFORE:
 				before= true;
-			else {
+				break;
+			default:
 				childHelper.fail(RulerColumnMessages.RulerColumnPlacement_illegal_child_msg);
 				continue;
 			}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
index ed3d77f..22b270c 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
@@ -4584,18 +4584,28 @@
 			// There is a separate handler for font preference changes
 			return;
 
-		if (PREFERENCE_COLOR_FOREGROUND.equals(property) || PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) ||
-				PREFERENCE_COLOR_BACKGROUND.equals(property) ||	PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) ||
-				PREFERENCE_COLOR_SELECTION_FOREGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT.equals(property) ||
-				PREFERENCE_COLOR_SELECTION_BACKGROUND.equals(property) ||	PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT.equals(property))
-		{
-			initializeViewerColors(fSourceViewer);
-		} else if (PREFERENCE_COLOR_FIND_SCOPE.equals(property)) {
-			initializeFindScopeColor(fSourceViewer);
-		} else if (PREFERENCE_USE_CUSTOM_CARETS.equals(property)) {
-			updateCaret();
-		} else if (PREFERENCE_WIDE_CARET.equals(property)) {
-			updateCaret();
+		if (property != null) {
+			switch (property) {
+			case PREFERENCE_COLOR_FOREGROUND:
+			case PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT:
+			case PREFERENCE_COLOR_BACKGROUND:
+			case PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT:
+			case PREFERENCE_COLOR_SELECTION_FOREGROUND:
+			case PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT:
+			case PREFERENCE_COLOR_SELECTION_BACKGROUND:
+			case PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT:
+				initializeViewerColors(fSourceViewer);
+				break;
+			case PREFERENCE_COLOR_FIND_SCOPE:
+				initializeFindScopeColor(fSourceViewer);
+				break;
+			case PREFERENCE_USE_CUSTOM_CARETS:
+			case PREFERENCE_WIDE_CARET:
+				updateCaret();
+				break;
+			default:
+				break;
+			}
 		}
 
 		if (affectsTextPresentation(event))
@@ -6686,11 +6696,14 @@
 
 			String text= null;
 
-			if (ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION.equals(category))
+			switch (category) {
+			case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION:
 				text= getCursorPosition();
-			else if (ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE.equals(category))
+				break;
+			case ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE:
 				text= isEditorInputReadOnly() ? fReadOnlyLabel : fWritableLabel;
-			else if (ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE.equals(category)) {
+				break;
+			case ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE:
 				InsertMode mode= getInsertMode();
 				if (fIsOverwriting)
 					text= fOverwriteModeLabel;
@@ -6698,6 +6711,9 @@
 					text= fInsertModeLabel;
 				else if (SMART_INSERT == mode)
 					text= fSmartInsertModeLabel;
+				break;
+			default:
+				break;
 			}
 
 			field.setText(text == null ? fErrorLabel : text);
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/ColumnLayout.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/ColumnLayout.java
index f0d7799..af873b2 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/ColumnLayout.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/ColumnLayout.java
@@ -58,12 +58,17 @@
 	private static int COLUMN_TRIM;
 	static {
 		String platform= SWT.getPlatform();
-		if ("win32".equals(platform)) //$NON-NLS-1$
+		switch (platform) {
+		case "win32": //$NON-NLS-1$
 			COLUMN_TRIM= 4;
-		else if ("carbon".equals(platform)) //$NON-NLS-1$
+			break;
+		case "carbon": //$NON-NLS-1$
 			COLUMN_TRIM= 24;
-		else
+			break;
+		default:
 			COLUMN_TRIM= 3;
+			break;
+		}
 	}
 
 	private List<ColumnLayoutData> columns= new ArrayList<>();