[platform] tunes Java version formatting

This commit is contained in:
Roman Shevchenko
2018-01-17 18:32:43 +01:00
parent 3216566490
commit 134584956a
2 changed files with 22 additions and 9 deletions
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.lang;
import com.intellij.openapi.util.text.StringUtil;
@@ -102,13 +100,15 @@ public final class JavaVersion implements Comparable<JavaVersion> {
StringBuilder sb = new StringBuilder();
if (feature > 8) {
sb.append(feature);
if (minor > 0 || update > 0) sb.append('.').append(minor).append('.').append(update);
if (minor > 0 || update > 0) sb.append('.').append(minor);
if (update > 0) sb.append('.').append(update);
if (ea) sb.append("-ea");
if (build > 0) sb.append('+').append(build);
}
else {
sb.append("1.").append(feature).append('.').append(minor);
if (update > 0 || ea) sb.append('_').append(update);
sb.append("1.").append(feature);
if (minor > 0 || update > 0 || ea || build > 0) sb.append('.').append(minor);
if (update > 0) sb.append('_').append(update);
if (ea) sb.append("-ea");
if (build > 0) sb.append("-b").append(build);
}
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.lang
import org.assertj.core.api.Assertions.assertThat
@@ -69,6 +67,21 @@ class JavaVersionTest {
assertThat(JavaVersion.compose(8, 0, 0, 0, false)).isGreaterThan(JavaVersion.compose(8, 0, 0, 0, true))
}
@Test fun formatting() {
assertThat(JavaVersion.compose(8, 0, 0, 0, false).toString()).isEqualTo("1.8")
assertThat(JavaVersion.compose(8, 1, 0, 0, false).toString()).isEqualTo("1.8.1")
assertThat(JavaVersion.compose(8, 0, 1, 0, false).toString()).isEqualTo("1.8.0_1")
assertThat(JavaVersion.compose(8, 0, 0, 1, false).toString()).isEqualTo("1.8.0-b1")
assertThat(JavaVersion.compose(8, 0, 0, 0, true).toString()).isEqualTo("1.8.0-ea")
assertThat(JavaVersion.compose(8, 1, 2, 3, true).toString()).isEqualTo("1.8.1_2-ea-b3")
assertThat(JavaVersion.compose(9, 0, 0, 0, false).toString()).isEqualTo("9")
assertThat(JavaVersion.compose(9, 1, 0, 0, false).toString()).isEqualTo("9.1")
assertThat(JavaVersion.compose(9, 0, 1, 0, false).toString()).isEqualTo("9.0.1")
assertThat(JavaVersion.compose(9, 0, 0, 1, false).toString()).isEqualTo("9+1")
assertThat(JavaVersion.compose(9, 0, 0, 0, true).toString()).isEqualTo("9-ea")
assertThat(JavaVersion.compose(9, 1, 2, 3, true).toString()).isEqualTo("9.1.2-ea+3")
}
private fun doTest(versionString: String,
feature: Int,
minor: Int = 0,