Bug 548923 - Use switch over strings where possible

Change cascades of ifs which can be converted to switch over Strings.

The save action on some projects enforces to convert control statement
bodies to block.

Change-Id: Ibbaa58df369e2d3890892cbde0634c95c0c58a9a
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
diff --git a/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/AbstractJDITest.java b/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/AbstractJDITest.java
index 8667fe0..b4efcf8 100644
--- a/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/AbstractJDITest.java
+++ b/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/AbstractJDITest.java
@@ -969,42 +969,57 @@
 				} else {
 					String next = (i < args.length - 1) ? args[++i] : null;
 					// If specified, passed values override default values
-					if (arg.equals("-launcher")) {
-						vmLauncherName = next;
-					} else if (arg.equals("-address")) {
-						targetAddress = next;
-					} else if (arg.equals("-port")) {
-						fBackEndPort = Integer.parseInt(next);
-					} else if (arg.equals("-cp")) {
-						classPath = next;
-					} else if (arg.equals("-bp")) {
-						bootPath = next;
-					} else if (arg.equals("-vmtype")) {
-						vmType = next;
-					} else if (arg.equals("-stdout")) {
-						fStdoutFile = next;
-					} else if (arg.equals("-stderr")) {
-						fStderrFile = next;
-					} else if (arg.equals("-proxyout")) {
-						fProxyoutFile = next;
-					} else if (arg.equals("-proxyerr")) {
-						fProxyerrFile = next;
-					} else if (arg.equals("-vmcmd")) {
-						fVmCmd = next;
-					} else if (arg.equals("-vmargs")) {
-						fVmArgs = next;
-					} else if (arg.equals("-proxycmd")) {
-						fProxyCmd = next;
-					} else if (arg.equals("-trace")) {
-						if (next.equals("all")) {
-							fVMTraceFlags = com.sun.jdi.VirtualMachine.TRACE_ALL;
-						} else {
-							fVMTraceFlags = Integer.decode(next).intValue();
-						}
-					} else {
-						System.out.println("Invalid option: " + arg);
-						printUsage();
-						return false;
+					switch (arg) {
+						case "-launcher":
+							vmLauncherName = next;
+							break;
+						case "-address":
+							targetAddress = next;
+							break;
+						case "-port":
+							fBackEndPort = Integer.parseInt(next);
+							break;
+						case "-cp":
+							classPath = next;
+							break;
+						case "-bp":
+							bootPath = next;
+							break;
+						case "-vmtype":
+							vmType = next;
+							break;
+						case "-stdout":
+							fStdoutFile = next;
+							break;
+						case "-stderr":
+							fStderrFile = next;
+							break;
+						case "-proxyout":
+							fProxyoutFile = next;
+							break;
+						case "-proxyerr":
+							fProxyerrFile = next;
+							break;
+						case "-vmcmd":
+							fVmCmd = next;
+							break;
+						case "-vmargs":
+							fVmArgs = next;
+							break;
+						case "-proxycmd":
+							fProxyCmd = next;
+							break;
+						case "-trace":
+							if (next.equals("all")) {
+								fVMTraceFlags = com.sun.jdi.VirtualMachine.TRACE_ALL;
+							} else {
+								fVMTraceFlags = Integer.decode(next).intValue();
+							}
+							break;
+						default:
+							System.out.println("Invalid option: " + arg);
+							printUsage();
+							return false;
 					}
 				}
 			}
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelProvider.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelProvider.java
index c0ba5d3..57544eb 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelProvider.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelProvider.java
@@ -192,12 +192,16 @@
 	 * @param value preference value for PREF_SHOW_DETAILS
 	 */
 	private void determineSerializationMode(String value) {
-		if (value.equals(IJDIPreferencesConstants.INLINE_ALL)) {
-			fSerializeMode = SERIALIZE_NONE;
-		} else if (value.equals(IJDIPreferencesConstants.INLINE_FORMATTERS)) {
-			fSerializeMode = SERIALIZE_SOME;
-		} else {
-			fSerializeMode = SERIALIZE_ALL;
+		switch (value) {
+			case IJDIPreferencesConstants.INLINE_ALL:
+				fSerializeMode = SERIALIZE_NONE;
+				break;
+			case IJDIPreferencesConstants.INLINE_FORMATTERS:
+				fSerializeMode = SERIALIZE_SOME;
+				break;
+			default:
+				fSerializeMode = SERIALIZE_ALL;
+				break;
 		}
 	}
 
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java
index c8dd44b..c33cd85 100644
--- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java
+++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/Instruction.java
@@ -226,24 +226,38 @@
 	 */
 	protected IJavaType getPrimitiveType(String name) throws CoreException {
 		IJavaReferenceType type = null;
-		if ("boolean".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Boolean"); //$NON-NLS-1$
-		} else if ("byte".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Byte"); //$NON-NLS-1$
-		} else if ("char".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Character"); //$NON-NLS-1$
-		} else if ("double".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Double"); //$NON-NLS-1$
-		} else if ("float".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Float"); //$NON-NLS-1$
-		} else if ("int".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Integer"); //$NON-NLS-1$
-		} else if ("long".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Long"); //$NON-NLS-1$
-		} else if ("short".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Short"); //$NON-NLS-1$
-		} else if ("void".equals(name)) { //$NON-NLS-1$
-			type = (IJavaReferenceType) getType("java.lang.Void"); //$NON-NLS-1$
+		if (name != null) {
+			switch (name) {
+				case "boolean": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Boolean"); //$NON-NLS-1$
+					break;
+				case "byte": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Byte"); //$NON-NLS-1$
+					break;
+				case "char": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Character"); //$NON-NLS-1$
+					break;
+				case "double": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Double"); //$NON-NLS-1$
+					break;
+				case "float": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Float"); //$NON-NLS-1$
+					break;
+				case "int": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Integer"); //$NON-NLS-1$
+					break;
+				case "long": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Long"); //$NON-NLS-1$
+					break;
+				case "short": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Short"); //$NON-NLS-1$
+					break;
+				case "void": //$NON-NLS-1$
+					type = (IJavaReferenceType) getType("java.lang.Void"); //$NON-NLS-1$
+					break;
+				default:
+					break;
+			}
 		}
 		if (type != null) {
 			IJavaFieldVariable field = type.getField("TYPE"); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaClasspathVariablesInitializer.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaClasspathVariablesInitializer.java
index 9349441..1e26f61 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaClasspathVariablesInitializer.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaClasspathVariablesInitializer.java
@@ -62,12 +62,18 @@
 				systemLib = locations[0];
 			}
 			if (systemLib != null) {
-				if (variable.equals(JavaRuntime.JRELIB_VARIABLE)) {
-					newPath= systemLib.getSystemLibraryPath();
-				} else if (variable.equals(JavaRuntime.JRESRC_VARIABLE)) {
-					newPath= systemLib.getSystemLibrarySourcePath();
-				} else if (variable.equals(JavaRuntime.JRESRCROOT_VARIABLE)){
-					newPath= systemLib.getPackageRootPath();
+				switch (variable) {
+					case JavaRuntime.JRELIB_VARIABLE:
+						newPath = systemLib.getSystemLibraryPath();
+						break;
+					case JavaRuntime.JRESRC_VARIABLE:
+						newPath = systemLib.getSystemLibrarySourcePath();
+						break;
+					case JavaRuntime.JRESRCROOT_VARIABLE:
+						newPath = systemLib.getPackageRootPath();
+						break;
+					default:
+						break;
 				}
 				if (newPath == null) {
 					return;
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java
index bd7c3da..0c237e4 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java
@@ -252,30 +252,39 @@
 			for (int i = 0; i < configs.length; i++) {
 				IConfigurationElement element = configs[i];
 				String name = element.getName();
-				if (name.equals(ENVIRONMENT_ELEMENT)) {
-					String id = element.getAttribute("id"); //$NON-NLS-1$
-					if (id == null) {
-						LaunchingPlugin.log(NLS.bind("Execution environment must specify \"id\" attribute. Contributed by {0}.", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
-					} else {
-						IExecutionEnvironment env = new ExecutionEnvironment(element);
-						fEnvironments.add(env);
-						fEnvironmentsMap.put(id, env);
-					}
-				} else if (name.equals(ANALYZER_ELEMENT)) {
-					String id = element.getAttribute("id"); //$NON-NLS-1$
-					if (id == null) {
-						LaunchingPlugin.log(NLS.bind("Execution environment analyzer must specify \"id\" attribute. Contributed by {0}", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
-					} else {
-						fAnalyzers.put(id, new Analyzer(element));
-					}
-				} else if (name.equals(RULE_PARTICIPANT_ELEMENT)) {
-					String id = element.getAttribute("id"); //$NON-NLS-1$
-					if (id == null) {
-						LaunchingPlugin.log(NLS.bind("Execution environment rule participant must specify \"id\" attribute. Contributed by {0}", new String[]{element.getContributor().getName()})); //$NON-NLS-1$
-					} else {
-						// use a linked hash set to avoid duplicate rule participants
-						fRuleParticipants.add(new AccessRuleParticipant(element));
-					}
+				switch (name) {
+					case ENVIRONMENT_ELEMENT:
+						String id = element.getAttribute("id"); //$NON-NLS-1$
+						if (id == null) {
+							LaunchingPlugin.log(NLS.bind("Execution environment must specify \"id\" attribute. Contributed by {0}.", new String[] { //$NON-NLS-1$
+									element.getContributor().getName() }));
+						} else {
+							IExecutionEnvironment env = new ExecutionEnvironment(element);
+							fEnvironments.add(env);
+							fEnvironmentsMap.put(id, env);
+						}
+						break;
+					case ANALYZER_ELEMENT:
+						id = element.getAttribute("id"); //$NON-NLS-1$
+						if (id == null) {
+							LaunchingPlugin.log(NLS.bind("Execution environment analyzer must specify \"id\" attribute. Contributed by {0}", new String[] { //$NON-NLS-1$
+									element.getContributor().getName() }));
+						} else {
+							fAnalyzers.put(id, new Analyzer(element));
+						}
+						break;
+					case RULE_PARTICIPANT_ELEMENT:
+						id = element.getAttribute("id"); //$NON-NLS-1$
+						if (id == null) {
+							LaunchingPlugin.log(NLS.bind("Execution environment rule participant must specify \"id\" attribute. Contributed by {0}", new String[] { //$NON-NLS-1$
+									element.getContributor().getName() }));
+						} else {
+							// use a linked hash set to avoid duplicate rule participants
+							fRuleParticipants.add(new AccessRuleParticipant(element));
+						}
+						break;
+					default:
+						break;
 				}
 			}
 		}
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/StandardSourcePathProvider.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/StandardSourcePathProvider.java
index f06baba..657140e 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/StandardSourcePathProvider.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/StandardSourcePathProvider.java
@@ -70,31 +70,36 @@
 					all.add(entries[i]);
 					break;
 				case IRuntimeClasspathEntry.OTHER:
-					IRuntimeClasspathEntry2 entry = (IRuntimeClasspathEntry2)entries[i];
+					IRuntimeClasspathEntry2 entry = (IRuntimeClasspathEntry2) entries[i];
 					String typeId = entry.getTypeId();
 					IRuntimeClasspathEntry[] res = null;
-					if (typeId.equals(DefaultProjectClasspathEntry.TYPE_ID)) {
-						// add the resolved children of the project
-						IRuntimeClasspathEntry[] children = entry.getRuntimeClasspathEntries(configuration);
-						res = JavaRuntime.resolveSourceLookupPath(children, configuration);
-					} else if (typeId.equals(VariableClasspathEntry.TYPE_ID)) {
-						// add the archive itself - we currently do not allow a source attachment
-						res = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration);
-					} else {
-                        res = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration);
-                    }
+					switch (typeId) {
+						case DefaultProjectClasspathEntry.TYPE_ID:
+							// add the resolved children of the project
+							IRuntimeClasspathEntry[] children = entry.getRuntimeClasspathEntries(configuration);
+							res = JavaRuntime.resolveSourceLookupPath(children, configuration);
+							break;
+						case VariableClasspathEntry.TYPE_ID:
+							// add the archive itself - we currently do not allow a source attachment
+							res = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration);
+							break;
+						default:
+							res = JavaRuntime.resolveRuntimeClasspathEntry(entry, configuration);
+							break;
+					}
 					if (res != null) {
 						for (int j = 0; j < res.length; j++) {
 							all.add(res[j]);
-                            addManifestReferences(res[j], all);
+							addManifestReferences(res[j], all);
 						}
 					}
 					break;
+
 				default:
-					IRuntimeClasspathEntry[] resolved =JavaRuntime.resolveRuntimeClasspathEntry(entries[i], configuration);
+					IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveRuntimeClasspathEntry(entries[i], configuration);
 					for (int j = 0; j < resolved.length; j++) {
 						all.add(resolved[j]);
-                        addManifestReferences(resolved[j], all);
+						addManifestReferences(resolved[j], all);
 					}
 					break;
 			}