diff options
author | Carsten Hammer | 2019-05-21 14:56:45 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2019-06-10 18:13:13 +0000 |
commit | ac20bd173d9d6703a6a4ed50b8ede54cbe89af13 (patch) | |
tree | 21d26d0f3c88b514e4137aae530013b80a10cc45 | |
parent | fff24aab1c4598e4e9c20c35093ef1a27e546aa5 (diff) | |
download | rt.equinox.p2-ac20bd173d9d6703a6a4ed50b8ede54cbe89af13.tar.gz rt.equinox.p2-ac20bd173d9d6703a6a4ed50b8ede54cbe89af13.tar.xz rt.equinox.p2-ac20bd173d9d6703a6a4ed50b8ede54cbe89af13.zip |
Replace chain of ifs with switch
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: I48eb75c813d73c5b9e95cbb0d5e244bee4507feb
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
11 files changed, 182 insertions, 132 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/VersionFormatParser.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/VersionFormatParser.java index b85e793a2..87b7485e5 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/VersionFormatParser.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/VersionFormatParser.java @@ -293,16 +293,20 @@ class VersionFormatParser { void toString(StringBuffer sb) { if (min == 0) { - if (max == 1) - sb.append('?'); - else if (max == Integer.MAX_VALUE) - sb.append('*'); - else { - sb.append('{'); - sb.append(min); - sb.append(','); - sb.append(max); - sb.append('}'); + switch (max) { + case 1: + sb.append('?'); + break; + case Integer.MAX_VALUE: + sb.append('*'); + break; + default: + sb.append('{'); + sb.append(min); + sb.append(','); + sb.append(max); + sb.append('}'); + break; } } else if (max == Integer.MAX_VALUE) { if (min == 1) @@ -1384,20 +1388,26 @@ class VersionFormatParser { boolean enumCaseSensitive = true; boolean enumOptional = false; boolean enumBegins = false; - while (current < eos) { - char c = format.charAt(current); - if (c == 'i') { + OUTER: + while (current < eos) { + char c = format.charAt(current); + switch (c) { + case 'i': enumCaseSensitive = false; current++; - } else if (c == 'b') { + break; + case 'b': enumBegins = true; current++; - } else if (c == '?') { + break; + case '?': enumOptional = true; current++; - } else break; + default: + break OUTER; } + } // Ensure that all identifiers are unique and make them // lower case if necessary @@ -1599,82 +1609,87 @@ class VersionFormatParser { throw formatException(Messages.premature_end_of_format); char c = format.charAt(current); - if (c == 'p') { - // =pad(<raw-element>); - // - if (processing.padValue != null) - throw formatException(Messages.pad_defined_more_then_once); - if (processing.ignore) - throw formatException(Messages.cannot_combine_ignore_with_other_instruction); - ++current; - processing.padValue = parseRawElement(); - } else if (c == '!') { - // =ignore; - // - if (processing.ignore) - throw formatException(Messages.ignore_defined_more_then_once); - if (processing.padValue != null || processing.characters != null || processing.rangeMin != 0 || processing.rangeMax != Integer.MAX_VALUE || processing.defaultValue != null) - throw formatException(Messages.cannot_combine_ignore_with_other_instruction); - ++current; - processing.ignore = true; - } else if (c == '[') { - // =[<character group]; - // - if (processing.characters != null) - throw formatException(Messages.character_group_defined_more_then_once); - if (processing.ignore) - throw formatException(Messages.cannot_combine_ignore_with_other_instruction); - parseCharacterGroup(processing); - } else if (c == '{') { - if (current + 1 == eos) - throw formatException(Messages.premature_end_of_format); - - if (VersionParser.isDigit(format.charAt(current + 1))) { - // ={min,max}; + switch (c) { + case 'p': + // =pad(<raw-element>); // - if (processing.rangeMin != 0 || processing.rangeMax != Integer.MAX_VALUE) - throw formatException(Messages.range_defined_more_then_once); + if (processing.padValue != null) + throw formatException(Messages.pad_defined_more_then_once); if (processing.ignore) throw formatException(Messages.cannot_combine_ignore_with_other_instruction); - int[] minMax = parseMinMax(); - processing.rangeMin = minMax[0]; - processing.rangeMax = minMax[1]; - } else { - // ={enum1,enum2,...}; + ++current; + processing.padValue = parseRawElement(); + break; + case '!': + // =ignore; // - if (processing.enumInstruction != null) - throw formatException(Messages.enum_defined_more_then_once); - parseEnum(processing); - } - } else { - // =<raw-element>; - if (processing.defaultValue != null) - throw formatException(Messages.default_defined_more_then_once); - if (processing.ignore) - throw formatException(Messages.cannot_combine_ignore_with_other_instruction); - Comparable<?> dflt = parseRawElement(); - processing.defaultValue = dflt; - if (current < eos && format.charAt(current) == '{') { - // =m{<translated min char>} - // =''{<translated max char>,<max char repeat>} - if (++current == eos) - throw formatException(Messages.premature_end_of_format); - processing.oppositeTranslationChar = format.charAt(current++); - if (current == eos) + if (processing.ignore) + throw formatException(Messages.ignore_defined_more_then_once); + if (processing.padValue != null || processing.characters != null || processing.rangeMin != 0 || processing.rangeMax != Integer.MAX_VALUE || processing.defaultValue != null) + throw formatException(Messages.cannot_combine_ignore_with_other_instruction); + ++current; + processing.ignore = true; + break; + case '[': + // =[<character group]; + // + if (processing.characters != null) + throw formatException(Messages.character_group_defined_more_then_once); + if (processing.ignore) + throw formatException(Messages.cannot_combine_ignore_with_other_instruction); + parseCharacterGroup(processing); + break; + case '{': + if (current + 1 == eos) throw formatException(Messages.premature_end_of_format); + if (VersionParser.isDigit(format.charAt(current + 1))) { + // ={min,max}; + // + if (processing.rangeMin != 0 || processing.rangeMax != Integer.MAX_VALUE) + throw formatException(Messages.range_defined_more_then_once); + if (processing.ignore) + throw formatException(Messages.cannot_combine_ignore_with_other_instruction); + int[] minMax = parseMinMax(); + processing.rangeMin = minMax[0]; + processing.rangeMax = minMax[1]; + } else { + // ={enum1,enum2,...}; + // + if (processing.enumInstruction != null) + throw formatException(Messages.enum_defined_more_then_once); + parseEnum(processing); + } + break; + default: + // =<raw-element>; + if (processing.defaultValue != null) + throw formatException(Messages.default_defined_more_then_once); + if (processing.ignore) + throw formatException(Messages.cannot_combine_ignore_with_other_instruction); + Comparable<?> dflt = parseRawElement(); + processing.defaultValue = dflt; + if (current < eos && format.charAt(current) == '{') { + // =m{<translated min char>} + // =''{<translated max char>,<max char repeat>} + if (++current == eos) + throw formatException(Messages.premature_end_of_format); + processing.oppositeTranslationChar = format.charAt(current++); + if (current == eos) + throw formatException(Messages.premature_end_of_format); - if (dflt == VersionVector.MINS_VALUE) { - processing.oppositeTranslationRepeat = 3; - if (format.charAt(current) == ',') { - ++current; - processing.oppositeTranslationRepeat = parseIntegerLiteral(); + if (dflt == VersionVector.MINS_VALUE) { + processing.oppositeTranslationRepeat = 3; + if (format.charAt(current) == ',') { + ++current; + processing.oppositeTranslationRepeat = parseIntegerLiteral(); + } + } else if (dflt != VersionVector.MAXS_VALUE) { + current -= 2; + throw formatException(Messages.only_max_and_empty_string_defaults_can_have_translations); } - } else if (dflt != VersionVector.MAXS_VALUE) { - current -= 2; - throw formatException(Messages.only_max_and_empty_string_defaults_can_have_translations); + assertChar('}'); } - assertChar('}'); - } + break; } assertChar(';'); } diff --git a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/PublisherResult.java b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/PublisherResult.java index 4ebdb6351..87f36eeb2 100644 --- a/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/PublisherResult.java +++ b/bundles/org.eclipse.equinox.p2.publisher/src/org/eclipse/equinox/p2/publisher/PublisherResult.java @@ -101,15 +101,21 @@ public class PublisherResult extends IndexProvider<IInstallableUnit> implements @Override public void merge(IPublisherResult result, int mode) { - if (mode == MERGE_MATCHING) { - addIUs(result.getIUs(null, ROOT), ROOT); - addIUs(result.getIUs(null, NON_ROOT), NON_ROOT); - } else if (mode == MERGE_ALL_ROOT) { - addIUs(result.getIUs(null, ROOT), ROOT); - addIUs(result.getIUs(null, NON_ROOT), ROOT); - } else if (mode == MERGE_ALL_NON_ROOT) { - addIUs(result.getIUs(null, ROOT), NON_ROOT); - addIUs(result.getIUs(null, NON_ROOT), NON_ROOT); + switch (mode) { + case MERGE_MATCHING: + addIUs(result.getIUs(null, ROOT), ROOT); + addIUs(result.getIUs(null, NON_ROOT), NON_ROOT); + break; + case MERGE_ALL_ROOT: + addIUs(result.getIUs(null, ROOT), ROOT); + addIUs(result.getIUs(null, NON_ROOT), ROOT); + break; + case MERGE_ALL_NON_ROOT: + addIUs(result.getIUs(null, ROOT), NON_ROOT); + addIUs(result.getIUs(null, NON_ROOT), NON_ROOT); + break; + default: + break; } } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF index 04d974bf5..70b3dbab7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.repository.tools/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.equinox.p2.repository.tools;singleton:=true -Bundle-Version: 2.2.200.qualifier +Bundle-Version: 2.2.300.qualifier Bundle-Activator: org.eclipse.equinox.p2.internal.repository.tools.Activator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/pom.xml b/bundles/org.eclipse.equinox.p2.repository.tools/pom.xml index 958d5e369..06f8403e7 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/pom.xml +++ b/bundles/org.eclipse.equinox.p2.repository.tools/pom.xml @@ -9,6 +9,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.p2.repository.tools</artifactId> - <version>2.2.200-SNAPSHOT</version> + <version>2.2.300-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Utility.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Utility.java index ef40ead83..cb950faf2 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Utility.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/comparator/java/Utility.java @@ -377,15 +377,21 @@ public class Utility { throw new IllegalArgumentException(); } c = string[p]; - if (c == Signature.C_SEMICOLON) { + switch (c) { + case Signature.C_SEMICOLON: // all done return p; - } else if (c == Signature.C_GENERIC_START) { + case Signature.C_GENERIC_START: int e = scanTypeArgumentSignatures(string, p); p = e; - } else if (c == Signature.C_DOT || c == '/') { + break; + case Signature.C_DOT: + case '/': int id = scanIdentifier(string, p + 1); p = id; + break; + default: + break; } p++; } diff --git a/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF index edbc39be9..056559c14 100644 --- a/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundleName Bundle-SymbolicName: org.eclipse.equinox.p2.ui;singleton:=true -Bundle-Version: 2.5.500.qualifier +Bundle-Version: 2.5.600.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.ui.ProvUIActivator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.ui/pom.xml b/bundles/org.eclipse.equinox.p2.ui/pom.xml index a8c3b2bd7..81d1b38ac 100644 --- a/bundles/org.eclipse.equinox.p2.ui/pom.xml +++ b/bundles/org.eclipse.equinox.p2.ui/pom.xml @@ -5,7 +5,7 @@ are made available under the terms of the Eclipse Distribution License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/org/documents/edl-v10.php - + Contributors: Igor Fedorenko - initial implementation --> @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.p2.ui</artifactId> - <version>2.5.500-SNAPSHOT</version> + <version>2.5.600-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ApplyProfileChangesDialog.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ApplyProfileChangesDialog.java index b5dcb35e7..bfa3f5e20 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ApplyProfileChangesDialog.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ApplyProfileChangesDialog.java @@ -69,12 +69,18 @@ public class ApplyProfileChangesDialog extends MessageDialog { */ @Override protected void buttonPressed(int id) { - if (id == 0) { // YES - returnCode = PROFILE_RESTART; - } else if (id == 1) { // NO - returnCode = PROFILE_IGNORE; - } else { - returnCode = PROFILE_APPLYCHANGES; + switch (id) { + case 0: + // YES + returnCode = PROFILE_RESTART; + break; + case 1: + // NO + returnCode = PROFILE_IGNORE; + break; + default: + returnCode = PROFILE_APPLYCHANGES; + break; } super.buttonPressed(id); diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUPatternFilter.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUPatternFilter.java index 9514a9fb9..cf62da98b 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUPatternFilter.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUPatternFilter.java @@ -39,14 +39,22 @@ public class AvailableIUPatternFilter extends PatternFilter { super(); for (int i = 0; i < columnConfig.length; i++) { int field = columnConfig[i].getColumnType(); - if (field == IUColumnConfig.COLUMN_ID) - checkId = true; - else if (field == IUColumnConfig.COLUMN_NAME) - checkName = true; - else if (field == IUColumnConfig.COLUMN_DESCRIPTION) - checkDescription = true; - else if (field == IUColumnConfig.COLUMN_VERSION) - checkVersion = true; + switch (field) { + case IUColumnConfig.COLUMN_ID: + checkId = true; + break; + case IUColumnConfig.COLUMN_NAME: + checkName = true; + break; + case IUColumnConfig.COLUMN_DESCRIPTION: + checkDescription = true; + break; + case IUColumnConfig.COLUMN_VERSION: + checkVersion = true; + break; + default: + break; + } } } diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/MetadataRepositoryElementComparator.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/MetadataRepositoryElementComparator.java index 60fc7c88f..bde96da77 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/MetadataRepositoryElementComparator.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/viewers/MetadataRepositoryElementComparator.java @@ -55,16 +55,21 @@ public class MetadataRepositoryElementComparator extends ViewerComparator { int compare(MetadataRepositoryElement repo1, MetadataRepositoryElement repo2, int sortKey, int direction) { String key1, key2; - if (sortKey == RepositoryDetailsLabelProvider.COL_NAME) { - // Compare the repo names - key1 = repo1.getName(); - key2 = repo2.getName(); - } else if (sortKey == RepositoryDetailsLabelProvider.COL_LOCATION) { - key1 = URIUtil.toUnencodedString(repo1.getLocation()); - key2 = URIUtil.toUnencodedString(repo2.getLocation()); - } else { // COL_ENABLEMENT - key1 = repo1.isEnabled() ? ENABLED : BLANK; - key2 = repo2.isEnabled() ? ENABLED : BLANK; + switch (sortKey) { + case RepositoryDetailsLabelProvider.COL_NAME: + // Compare the repo names + key1 = repo1.getName(); + key2 = repo2.getName(); + break; + case RepositoryDetailsLabelProvider.COL_LOCATION: + key1 = URIUtil.toUnencodedString(repo1.getLocation()); + key2 = URIUtil.toUnencodedString(repo2.getLocation()); + break; + default: + // COL_ENABLEMENT + key1 = repo1.isEnabled() ? ENABLED : BLANK; + key2 = repo2.isEnabled() ? ENABLED : BLANK; + break; } // If the key is blank (no location, or disabled)..it should appear last if (key1.length() == 0 && key2.length() > 0) diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java index 3a5dbce02..73e02c7e0 100644 --- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java +++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java @@ -410,13 +410,17 @@ public class RepositoryManipulationPage extends PreferencePage implements IWorkb TableColumn tc = new TableColumn(table, SWT.NONE, i); tc.setResizable(true); tc.setText(columnHeaders[i]); - if (i == RepositoryDetailsLabelProvider.COL_ENABLEMENT) { - tc.setWidth(convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_SMALL_COLUMN_WIDTH)); - tc.setAlignment(SWT.CENTER); - } else if (i == RepositoryDetailsLabelProvider.COL_NAME) { - tc.setWidth(convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_COLUMN_WIDTH)); - } else { - tc.setWidth(convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_PRIMARY_COLUMN_WIDTH)); + switch (i) { + case RepositoryDetailsLabelProvider.COL_ENABLEMENT: + tc.setWidth(convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_SMALL_COLUMN_WIDTH)); + tc.setAlignment(SWT.CENTER); + break; + case RepositoryDetailsLabelProvider.COL_NAME: + tc.setWidth(convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_COLUMN_WIDTH)); + break; + default: + tc.setWidth(convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_PRIMARY_COLUMN_WIDTH)); + break; } tc.addSelectionListener(new SelectionListener() { @Override |