Refactoring: abandon custom MajorVersion class, use KotlinVersion
This commit is contained in:
+16
-32
@@ -75,14 +75,14 @@ fun notifyOutdatedBundledCompilerIfNecessary(project: Project) {
|
|||||||
private var alreadyNotified = ConcurrentHashMap<String, String>()
|
private var alreadyNotified = ConcurrentHashMap<String, String>()
|
||||||
|
|
||||||
fun createOutdatedBundledCompilerMessage(project: Project, bundledCompilerVersion: String = KotlinCompilerVersion.VERSION): String? {
|
fun createOutdatedBundledCompilerMessage(project: Project, bundledCompilerVersion: String = KotlinCompilerVersion.VERSION): String? {
|
||||||
val bundledCompilerMajorVersion = MajorVersion.create(bundledCompilerVersion) ?: return null
|
val bundledCompilerMajorVersion = createKotlinVersion(bundledCompilerVersion) ?: return null
|
||||||
|
|
||||||
var maxCompilerInfo: ModuleCompilerInfo? = null
|
var maxCompilerInfo: ModuleCompilerInfo? = null
|
||||||
val newerModuleCompilerInfos = ArrayList<ModuleCompilerInfo>()
|
val newerModuleCompilerInfos = ArrayList<ModuleCompilerInfo>()
|
||||||
for (module in ModuleManager.getInstance(project).modules) {
|
for (module in ModuleManager.getInstance(project).modules) {
|
||||||
val externalCompilerVersion = module.externalCompilerVersion ?: continue
|
val externalCompilerVersion = module.externalCompilerVersion ?: continue
|
||||||
val externalCompilerMajorVersion = MajorVersion.create(externalCompilerVersion) ?: continue
|
val externalCompilerMajorVersion = createKotlinVersion(externalCompilerVersion) ?: continue
|
||||||
val languageMajorVersion = MajorVersion.create(module.languageVersionSettings.languageVersion)
|
val languageMajorVersion = createKotlinVersion(module.languageVersionSettings.languageVersion)
|
||||||
|
|
||||||
if (externalCompilerMajorVersion > bundledCompilerMajorVersion && languageMajorVersion > bundledCompilerMajorVersion) {
|
if (externalCompilerMajorVersion > bundledCompilerMajorVersion && languageMajorVersion > bundledCompilerMajorVersion) {
|
||||||
val moduleCompilerInfo = ModuleCompilerInfo(module, externalCompilerVersion, externalCompilerMajorVersion, languageMajorVersion)
|
val moduleCompilerInfo = ModuleCompilerInfo(module, externalCompilerVersion, externalCompilerMajorVersion, languageMajorVersion)
|
||||||
@@ -171,43 +171,27 @@ private fun selectedModulesForPopup(
|
|||||||
private class ModuleCompilerInfo(
|
private class ModuleCompilerInfo(
|
||||||
val module: Module,
|
val module: Module,
|
||||||
val externalCompilerVersion: String,
|
val externalCompilerVersion: String,
|
||||||
val externalCompilerMajorVersion: MajorVersion,
|
val externalCompilerMajorVersion: KotlinVersion,
|
||||||
val languageMajorVersion: MajorVersion
|
val languageMajorVersion: KotlinVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
private data class MajorVersion(val major: Int, val minor: Int) : Comparable<MajorVersion> {
|
private fun createKotlinVersion(languageVersion: LanguageVersion): KotlinVersion {
|
||||||
override fun compareTo(other: MajorVersion): Int {
|
return KotlinVersion(languageVersion.major, languageVersion.minor, 0)
|
||||||
if (major > other.major) return 1
|
}
|
||||||
if (major < other.major) return -1
|
|
||||||
|
|
||||||
if (minor > other.minor) return 1
|
private fun createKotlinVersion(versionStr: String): KotlinVersion? {
|
||||||
if (minor < other.minor) return -1
|
if (versionStr == "@snapshot@") {
|
||||||
|
return KotlinVersion(Int.MAX_VALUE, Int.MAX_VALUE, 0)
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String = "$major.$minor"
|
val regex = """(\d+)\.(\d+).*""".toRegex()
|
||||||
|
|
||||||
companion object {
|
val matchResult = regex.matchEntire(versionStr) ?: return null
|
||||||
fun create(languageVersion: LanguageVersion): MajorVersion {
|
|
||||||
return MajorVersion(languageVersion.major, languageVersion.minor)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun create(versionStr: String): MajorVersion? {
|
val major: Int = matchResult.groupValues[1].toInt()
|
||||||
if (versionStr == "@snapshot@") {
|
val minor: Int = matchResult.groupValues[2].toInt()
|
||||||
return MajorVersion(Int.MAX_VALUE, Int.MAX_VALUE)
|
|
||||||
}
|
|
||||||
|
|
||||||
val regex = "(\\d+)\\.(\\d+).*".toRegex()
|
return KotlinVersion(major, minor, 0)
|
||||||
|
|
||||||
val matchResult = regex.matchEntire(versionStr) ?: return null
|
|
||||||
|
|
||||||
val major: Int = matchResult.groupValues[1].toInt()
|
|
||||||
val minor: Int = matchResult.groupValues[2].toInt()
|
|
||||||
|
|
||||||
return MajorVersion(major, minor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val NUMBER_OF_MODULES_TO_SHOW = 2
|
private const val NUMBER_OF_MODULES_TO_SHOW = 2
|
||||||
|
|||||||
Reference in New Issue
Block a user