Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-29 13:48:33 -0400
committerKarsten Thoms2019-06-13 06:41:20 -0400
commit99e752f89849a969a3cd0235ea9a766e4a15bc9c (patch)
tree65f3ba1ce86376c0b5525e88151c2fad8a3dd7aa /org.eclipse.debug.ui/ui
parentff36325e43f71a96a7927f2a5089af77e28f228b (diff)
downloadeclipse.platform.debug-99e752f89849a969a3cd0235ea9a766e4a15bc9c.tar.gz
eclipse.platform.debug-99e752f89849a969a3cd0235ea9a766e4a15bc9c.tar.xz
eclipse.platform.debug-99e752f89849a969a3cd0235ea9a766e4a15bc9c.zip
Replace chain of ifs with switchI20190614-0330I20190613-1800
Sometimes if statements are chained and form a series of == comparisons against constants. Such situation is more readable if written using switch statement. Change-Id: I699710eb77cb7b84e34d32ec1460daab696c8591 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
Diffstat (limited to 'org.eclipse.debug.ui/ui')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/StringVariablePreferencePage.java7
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionDropAdapter.java13
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java46
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/TableRenderingPropertiesPage.java22
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java43
5 files changed, 74 insertions, 57 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/StringVariablePreferencePage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/StringVariablePreferencePage.java
index 227b2fb5a..9b136deaf 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/StringVariablePreferencePage.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/StringVariablePreferencePage.java
@@ -320,14 +320,15 @@ public class StringVariablePreferencePage extends PreferencePage implements IWor
IDialogConstants.NO_LABEL,
IDialogConstants.CANCEL_LABEL }, 0);
int overWrite= dialog.open();
- if (overWrite == 0) {
+ switch (overWrite) {
+ case 0:
currentVariable.setValue(value);
currentVariable.setDescription(description);
variableTable.update(currentVariable, null);
return true;
- } else if(overWrite == 1){
+ case 1:
return false;
- } else {
+ default:
return true; // Cancel was pressed, return true so operation is ended
}
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionDropAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionDropAdapter.java
index ac62f4d55..4412f3ec8 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionDropAdapter.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionDropAdapter.java
@@ -172,13 +172,16 @@ public class ExpressionDropAdapter extends ViewerDropAdapter {
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
- if (fDropType == DROP_TYPE_EXPRESSION){
+ switch (fDropType) {
+ case DROP_TYPE_EXPRESSION:
return validateExpressionDrop(target);
- } else if (fDropType == DROP_TYPE_VARIABLE){
+ case DROP_TYPE_VARIABLE:
return validateVariableDrop(target);
- } else if (fDropType == DROP_TYPE_WATCH_ADAPTABLE_ELEMENT){
- return validateWatchAdaptableDrop(target);
- }
+ case DROP_TYPE_WATCH_ADAPTABLE_ELEMENT:
+ return validateWatchAdaptableDrop(target);
+ default:
+ break;
+ }
} else if (TextTransfer.getInstance().isSupportedType(transferType)) {
return validateTextDrop(target);
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java
index 8416dbbb9..ba0fcad7f 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/SignedIntegerRendering.java
@@ -42,32 +42,30 @@ public class SignedIntegerRendering extends AbstractIntegerRendering {
String ret;
long result = 0;
- if (columnSize == 1)
- {
+ switch (columnSize) {
+ case 1:
result = byteArray[0];
- }
- else if (columnSize == 2)
- {
+ break;
+ case 2:
result = RenderingsUtil.convertByteArrayToShort(byteArray, endianess);
- }
- else if (columnSize == 4)
- {
+ break;
+ case 4:
result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess);
- }
- else if (columnSize == 8)
- {
+ break;
+ case 8:
result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess);
- }
- else if (columnSize == 16)
+ break;
+ case 16:
{
BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess);
return bigRet.toString();
}
- else
+ default:
{
BigInteger bigRet = RenderingsUtil.convertByteArrayToSignedBigInt(byteArray, endianess, columnSize);
return bigRet.toString();
}
+ }
ret = Long.valueOf(result).toString();
@@ -78,28 +76,31 @@ public class SignedIntegerRendering extends AbstractIntegerRendering {
{
try {
byte[] bytes;
- if (colSize == 1)
- {
+ switch (colSize) {
+ case 1:
byte x = Byte.parseByte(newValue);
bytes = new byte[1];
bytes[0] = x;
- }
- else if (colSize == 2)
+ break;
+ case 2:
{
short i = Short.parseShort(newValue);
bytes = RenderingsUtil.convertShortToByteArray(i, endianess);
+ break;
}
- else if (colSize == 4)
+ case 4:
{
int i = Integer.parseInt(newValue);
bytes = RenderingsUtil.convertIntToByteArray(i, endianess);
+ break;
}
- else if (colSize == 8)
+ case 8:
{
long i = Long.parseLong(newValue);
bytes = RenderingsUtil.convertLongToByteArray(i, endianess);
+ break;
}
- else if (colSize == 16)
+ case 16:
{
// special case for colSize == 16
// need to represent number in Big Integer
@@ -108,7 +109,7 @@ public class SignedIntegerRendering extends AbstractIntegerRendering {
return bytes;
}
- else
+ default:
{
BigInteger i = new BigInteger(newValue);
@@ -130,6 +131,7 @@ public class SignedIntegerRendering extends AbstractIntegerRendering {
bytes = RenderingsUtil.convertSignedBigIntToByteArray(i, endianess, colSize);
return bytes;
}
+ }
return bytes;
} catch (NumberFormatException e) {
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/TableRenderingPropertiesPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/TableRenderingPropertiesPage.java
index 3cb01fe2e..50dcc4eb5 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/TableRenderingPropertiesPage.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/TableRenderingPropertiesPage.java
@@ -122,12 +122,17 @@ public class TableRenderingPropertiesPage extends PropertyPage implements
String dataEndian = DebugUIMessages.TableRenderingPropertiesPage_12;
if (endianessKnown)
{
- if (endianess == RenderingsUtil.BIG_ENDIAN)
+ switch (endianess) {
+ case RenderingsUtil.BIG_ENDIAN:
dataEndian = DebugUIMessages.TableRenderingPropertiesPage_13;
- else if (endianess == RenderingsUtil.LITTLE_ENDIAN)
+ break;
+ case RenderingsUtil.LITTLE_ENDIAN:
dataEndian = DebugUIMessages.TableRenderingPropertiesPage_14;
- else
+ break;
+ default:
dataEndian = DebugUIMessages.TableRenderingPropertiesPage_15;
+ break;
+ }
}
addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_16, dataEndian);
@@ -139,16 +144,19 @@ public class TableRenderingPropertiesPage extends PropertyPage implements
String displayEndian = DebugUIMessages.TableRenderingPropertiesPage_17;
endianess = intRendering.getDisplayEndianess();
- if (endianess == RenderingsUtil.BIG_ENDIAN)
+ switch (endianess) {
+ case RenderingsUtil.BIG_ENDIAN:
displayEndian = DebugUIMessages.TableRenderingPropertiesPage_18;
- else if (endianess == RenderingsUtil.LITTLE_ENDIAN)
+ break;
+ case RenderingsUtil.LITTLE_ENDIAN:
displayEndian = DebugUIMessages.TableRenderingPropertiesPage_19;
- else
- {
+ break;
+ default:
if (endianessKnown)
displayEndian = dataEndian;
else
displayEndian = DebugUIMessages.TableRenderingPropertiesPage_20;
+ break;
}
addProperty(composite, DebugUIMessages.TableRenderingPropertiesPage_21, displayEndian);
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java
index 0888836f3..15626c562 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/renderings/UnsignedIntegerRendering.java
@@ -37,34 +37,31 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering {
String ret;
long result = 0;
- if (columnSize == 1)
- {
+ switch (columnSize) {
+ case 1:
result = byteArray[0];
result &= 0xff;
- }
- else if (columnSize == 2)
- {
+ break;
+ case 2:
result = RenderingsUtil.convertByteArrayToInt(byteArray, endianess);
- }
- else if (columnSize == 4)
- {
+ break;
+ case 4:
result = RenderingsUtil.convertByteArrayToLong(byteArray, endianess);
- }
- else if (columnSize == 8)
- {
+ break;
+ case 8:
BigInteger value = RenderingsUtil.convertByteArrayToUnsignedLong(byteArray, endianess);
return value.toString();
- }
- else if (columnSize == 16)
+ case 16:
{
BigInteger bigRet = RenderingsUtil.convertByteArrayToUnsignedBigInt(byteArray, endianess);
return bigRet.toString();
}
- else
+ default:
{
BigInteger bigRet = RenderingsUtil.convertByteArrayToUnsignedBigInt(byteArray, endianess, columnSize);
return bigRet.toString();
}
+ }
ret = Long.valueOf(result).toString();
@@ -75,32 +72,37 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering {
{
try {
byte[] bytes;
- if (colSize == 1)
+ switch (colSize) {
+ case 1:
{
short i = Short.parseShort(newValue);
bytes = RenderingsUtil.convertShortToByteArray(i, endianess);
bytes = extractBytes(bytes, endianess, colSize);
+ break;
}
// unsigned integer
- else if (colSize == 2)
+ case 2:
{
int i = Integer.parseInt(newValue);
bytes = RenderingsUtil.convertIntToByteArray(i, endianess);
bytes = extractBytes(bytes, endianess, colSize);
+ break;
}
- else if (colSize == 4)
+ case 4:
{
long i = Long.parseLong(newValue);
bytes = RenderingsUtil.convertLongToByteArray(i, endianess);
bytes = extractBytes(bytes, endianess, colSize);
+ break;
}
- else if (colSize == 8)
+ case 8:
{
BigInteger i = new BigInteger(newValue);
bytes = RenderingsUtil.convertBigIntegerToByteArray(i, endianess);
bytes = extractBytes(bytes, endianess, colSize);
+ break;
}
- else if (colSize == 16)
+ case 16:
{
BigInteger i = new BigInteger(newValue);
bytes = RenderingsUtil.convertUnsignedBigIntegerToByteArray(i, endianess);
@@ -108,13 +110,14 @@ public class UnsignedIntegerRendering extends AbstractIntegerRendering {
return bytes;
}
- else
+ default:
{
BigInteger i = new BigInteger(newValue);
bytes = RenderingsUtil.convertUnsignedBigIntToByteArray(i, endianess, colSize);
bytes = extractBytes(bytes, endianess, colSize);
return bytes;
}
+ }
return bytes;
} catch (NumberFormatException e) {

Back to the top