Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2020-03-14 11:57:03 +0000
committerCarsten Hammer2020-04-21 19:54:21 +0000
commit61b67eb5c221afba067e55eed231c749b33c6140 (patch)
treefeb267d48434f2ec3a58974fbdf50ec86ec45611
parente33cf060c7cd163675a031f95eff05605cc45d79 (diff)
downloadeclipse.platform.text-I20200426-1800.tar.gz
eclipse.platform.text-I20200426-1800.tar.xz
eclipse.platform.text-I20200426-1800.zip
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>
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java12
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/rulers/RulerColumnPlacement.java13
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java46
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/templates/ColumnLayout.java11
4 files changed, 56 insertions, 26 deletions
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 2ab5a846de6..dcb00151040 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 @@ public class TemplateTranslator {
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 29628e9f35d..86237aeea39 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 @@ public final class RulerColumnPlacement {
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 ed3d77f07a3..22b270c3f7c 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 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
// 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 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
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 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
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 f0d77999ae1..af873b2d172 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 @@ final class ColumnLayout extends Layout {
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<>();

Back to the top