diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/VersionRange.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/VersionRange.java index 599a341fb..995c0f50a 100644 --- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/VersionRange.java +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/VersionRange.java @@ -50,22 +50,25 @@ public class VersionRange implements Serializable { private static int copyEscaped(String vr, int pos, String breakChars, StringBuilder sb) { int top = vr.length(); pos = VersionParser.skipWhite(vr, pos); - if (pos >= top) + if (pos >= top) { throw new IllegalArgumentException(); - + } char c = vr.charAt(pos); for (;;) { - if (c == '\\' && ++pos < top) + if (c == '\\' && ++pos < top) { c = vr.charAt(pos); - else { - if (c <= ' ') + } else { + if (c <= ' ') { return VersionParser.skipWhite(vr, pos); - if (breakChars != null && breakChars.indexOf(c) >= 0) + } + if (breakChars != null && breakChars.indexOf(c) >= 0) { break; + } } sb.append(c); - if (++pos >= top) + if (++pos >= top) { break; + } c = vr.charAt(pos); } return pos; @@ -83,15 +86,16 @@ public VersionRange(Version minVersion, boolean includeMin, Version maxVersion, maxVersion = Version.MAX_VERSION; } } else { - if (maxVersion == null) + if (maxVersion == null) { maxVersion = Version.MAX_VERSION; - else { - if (minVersion != maxVersion && minVersion.equals(maxVersion)) + } else { + if (minVersion != maxVersion && minVersion.equals(maxVersion)) { maxVersion = minVersion; - else if (!(minVersion.getFormat() == null ? maxVersion.getFormat() == null : minVersion.getFormat().equals(maxVersion.getFormat()))) { + } else if (!(minVersion.getFormat() == null ? maxVersion.getFormat() == null : minVersion.getFormat().equals(maxVersion.getFormat()))) { // We always allow the MIN and MAX boundaries - if (!(minVersion.equals(Version.emptyVersion) || maxVersion.equals(Version.MAX_VERSION))) + if (!(minVersion.equals(Version.emptyVersion) || maxVersion.equals(Version.MAX_VERSION))) { throw new IllegalArgumentException(NLS.bind(Messages.range_boundaries_0_and_1_cannot_have_different_formats, minVersion, maxVersion)); + } } } } @@ -136,38 +140,42 @@ public VersionRange(String versionRange) { position[0] = pos; fmt = parseFormat(versionRange, position); pos = position[0]; - if (pos >= versionRange.length()) + if (pos >= versionRange.length()) { throw new IllegalArgumentException(NLS.bind(Messages.format_must_be_delimited_by_colon_0, versionRange)); - + } c = versionRange.charAt(pos); - if (c != ':') + if (c != ':') { throw new IllegalArgumentException(NLS.bind(Messages.format_must_be_delimited_by_colon_0, versionRange)); + } ++pos; } pos = VersionParser.skipWhite(versionRange, pos); - if (pos >= top) + if (pos >= top) { throw new IllegalArgumentException(NLS.bind(Messages.premature_EOS_0, versionRange)); + } c = versionRange.charAt(pos); - } else + } else { fmt = VersionFormat.OSGI_FORMAT; - + } String minStr; String maxStr; StringBuilder sb = new StringBuilder(); if (c == '[' || c == '(') { includeMin = (c == '['); pos = copyEscaped(versionRange, ++pos, ",)]", sb); //$NON-NLS-1$ - if (pos >= top) + if (pos >= top) { throw new IllegalArgumentException(NLS.bind(Messages.premature_EOS_0, versionRange)); + } c = versionRange.charAt(pos++); - if (c != ',') + if (c != ',') { throw new IllegalArgumentException(NLS.bind(Messages.missing_comma_in_range_0, versionRange)); - + } minStr = sb.toString(); sb.setLength(0); pos = copyEscaped(versionRange, pos, ")]", sb); //$NON-NLS-1$ - if (pos >= top) + if (pos >= top) { throw new IllegalArgumentException(); + } maxStr = sb.toString(); c = versionRange.charAt(pos++); @@ -185,25 +193,27 @@ public VersionRange(String versionRange) { String origMax = null; pos = VersionParser.skipWhite(versionRange, pos); if (pos < top && versionRange.charAt(pos) == '/') { - if (++pos == top) + if (++pos == top) { throw new IllegalArgumentException(NLS.bind(Messages.original_stated_but_missing_0, versionRange)); + } position[0] = pos; fmt = parseFormat(versionRange, position); pos = VersionParser.skipWhite(versionRange, position[0]); if (pos < top) { boolean origUseIncDelims = false; c = versionRange.charAt(pos); - if (c != ':') + if (c != ':') { throw new IllegalArgumentException(NLS.bind(Messages.original_must_start_with_colon_0, versionRange)); - + } pos = VersionParser.skipWhite(versionRange, ++pos); - if (pos == top) + if (pos == top) { throw new IllegalArgumentException(NLS.bind(Messages.original_stated_but_missing_0, versionRange)); - + } c = versionRange.charAt(pos); if (c == '[' || c == '(') { - if (includeMin != (c == '[') || maxStr == null) + if (includeMin != (c == '[') || maxStr == null) { throw new IllegalArgumentException(NLS.bind(Messages.raw_and_original_must_use_same_range_inclusion_0, versionRange)); + } pos = VersionParser.skipWhite(versionRange, ++pos); origUseIncDelims = true; } @@ -214,21 +224,25 @@ public VersionRange(String versionRange) { origMin = sb.toString(); } else { pos = copyEscaped(versionRange, pos, ",])", sb); //$NON-NLS-1$ - if (pos >= top) + if (pos >= top) { throw new IllegalArgumentException(NLS.bind(Messages.premature_EOS_0, versionRange)); + } c = versionRange.charAt(pos++); - if (c != ',') + if (c != ',') { throw new IllegalArgumentException(NLS.bind(Messages.missing_comma_in_range_0, versionRange)); + } origMin = sb.toString(); sb.setLength(0); pos = copyEscaped(versionRange, pos, "])", sb); //$NON-NLS-1$ if (origUseIncDelims) { - if (pos >= top) + if (pos >= top) { throw new IllegalArgumentException(NLS.bind(Messages.premature_EOS_0, versionRange)); + } c = versionRange.charAt(pos++); - if (includeMax != (c == ']')) + if (includeMax != (c == ']')) { throw new IllegalArgumentException(NLS.bind(Messages.raw_and_original_must_use_same_range_inclusion_0, versionRange)); + } } origMax = sb.toString(); } @@ -236,21 +250,25 @@ public VersionRange(String versionRange) { } minVersion = VersionFormat.parseRaw(minStr, fmt, origMin); if (maxStr != null) { - if (maxStr.equals(minStr)) + if (maxStr.equals(minStr)) { maxVersion = minVersion; - else + } else { maxVersion = VersionFormat.parseRaw(maxStr, fmt, origMax); - } else + } + } else { maxVersion = Version.MAX_VERSION; + } } else { - if (fmt == null) + if (fmt == null) { fmt = VersionFormat.OSGI_FORMAT; + } minVersion = fmt.parse(minStr); if (maxStr != null) { - if (maxStr.equals(minStr)) + if (maxStr.equals(minStr)) { maxVersion = minVersion; - else + } else { maxVersion = fmt.parse(maxStr); + } } else { maxVersion = Version.MAX_VERSION; } @@ -293,9 +311,9 @@ public static VersionRange create(String versionRange) { private static IVersionFormat parseFormat(String versionRange, int[] position) { int pos = VersionParser.skipWhite(versionRange, position[0]); - if (!versionRange.startsWith("format(", pos)) //$NON-NLS-1$ + if (!versionRange.startsWith("format(", pos)) { //$NON-NLS-1$ return null; - + } pos += 7; int end = VersionParser.findEndOfFormat(versionRange, pos, versionRange.length()); try { @@ -354,8 +372,9 @@ public VersionRange intersect(VersionRange r2) { boolean resultMinIncluded; Version resultMin; if (minCompare == 0) { - if (maxCompare == 0 && includeMin == r2.getIncludeMinimum() && includeMax == r2.getIncludeMaximum()) + if (maxCompare == 0 && includeMin == r2.getIncludeMinimum() && includeMax == r2.getIncludeMaximum()) { return this; + } resultMin = minVersion; resultMinIncluded = includeMin && r2.getIncludeMinimum(); } else if (minCompare < 0) { @@ -380,9 +399,9 @@ public VersionRange intersect(VersionRange r2) { } int minMaxCmp = resultMin.compareTo(resultMax); - if (minMaxCmp < 0 || (minMaxCmp == 0 && resultMinIncluded && resultMaxIncluded)) + if (minMaxCmp < 0 || (minMaxCmp == 0 && resultMinIncluded && resultMaxIncluded)) { return new VersionRange(resultMin, resultMinIncluded, resultMax, resultMaxIncluded); - + } return null; } @@ -397,13 +416,13 @@ public VersionRange intersect(VersionRange r2) { * false otherwise */ public boolean isIncluded(Version version) { - if (version == null) + if (version == null) { return false; - - if (minVersion == maxVersion) + } + if (minVersion == maxVersion) { // Can only happen when both includeMin and includeMax are true return minVersion.equals(version); - + } int minCheck = includeMin ? 0 : -1; int maxCheck = includeMax ? 0 : 1; return minVersion.compareTo(version) <= minCheck && maxVersion.compareTo(version) >= maxCheck; @@ -483,17 +502,19 @@ public void toString(StringBuilder result) { boolean hasOriginal = (minVersion.getOriginal() != null || maxVersion.getOriginal() != null); if (fmt != null || hasOriginal) { result.append('/'); - if (fmt != null) + if (fmt != null) { fmt.toString(result); + } if (hasOriginal) { result.append(':'); if (gtEqual) { ((BasicVersion) minVersion).originalToString(result, true); } else { - if (Version.emptyVersion.equals(minVersion)) + if (Version.emptyVersion.equals(minVersion)) { ((BasicVersion) minVersion).rawToString(result, true); - else + } else { ((BasicVersion) minVersion).originalToString(result, true); + } result.append(','); ((BasicVersion) maxVersion).originalToString(result, true); } @@ -504,15 +525,17 @@ public void toString(StringBuilder result) { // Preserve singletons during deserialization private Object readResolve() { VersionRange vr = this; - if (equals(emptyRange)) + if (equals(emptyRange)) { vr = emptyRange; + } return vr; } private void validateRange() { int cmp = minVersion.compareTo(maxVersion); - if (!(cmp < 0 || (cmp == 0 && includeMin && includeMax))) + if (!(cmp < 0 || (cmp == 0 && includeMin && includeMax))) { throw new IllegalArgumentException(NLS.bind(Messages.range_min_0_is_not_less_then_range_max_1, minVersion, maxVersion)); + } } }