KT-10974 - code review changes
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.core.formatter
|
||||
|
||||
import com.intellij.openapi.application.ApplicationBundle
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
|
||||
class KotlinPackageEntry(
|
||||
@@ -15,14 +16,15 @@ class KotlinPackageEntry(
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val ALL_OTHER_IMPORTS_ENTRY = KotlinPackageEntry("<all other imports>", withSubpackages = true)
|
||||
val ALL_OTHER_IMPORTS_ENTRY =
|
||||
KotlinPackageEntry(ApplicationBundle.message("listbox.import.all.other.imports"), withSubpackages = true)
|
||||
|
||||
@JvmField
|
||||
val ALL_OTHER_ALIAS_IMPORTS_ENTRY = KotlinPackageEntry("<all other alias imports>", withSubpackages = true)
|
||||
}
|
||||
|
||||
fun matchesPackageName(otherPackageName: String): Boolean {
|
||||
if (this == ALL_OTHER_IMPORTS_ENTRY || this == ALL_OTHER_ALIAS_IMPORTS_ENTRY) return true
|
||||
if (isSpecial) return true
|
||||
|
||||
if (otherPackageName.startsWith(packageName)) {
|
||||
if (otherPackageName.length == packageName.length) return true
|
||||
@@ -47,10 +49,7 @@ class KotlinPackageEntry(
|
||||
return entry.packageName.count { it == '.' } < packageName.count { it == '.' }
|
||||
}
|
||||
|
||||
val isSpecial: Boolean
|
||||
get() {
|
||||
return (this == ALL_OTHER_IMPORTS_ENTRY || this == ALL_OTHER_ALIAS_IMPORTS_ENTRY)
|
||||
}
|
||||
val isSpecial: Boolean get() = this == ALL_OTHER_IMPORTS_ENTRY || this == ALL_OTHER_ALIAS_IMPORTS_ENTRY
|
||||
|
||||
override fun toString(): String {
|
||||
return packageName
|
||||
|
||||
+4
-25
@@ -9,15 +9,10 @@ import com.intellij.openapi.util.InvalidDataException
|
||||
import com.intellij.openapi.util.JDOMExternalizable
|
||||
import org.jdom.Element
|
||||
|
||||
class KotlinPackageEntryTable: JDOMExternalizable, Cloneable {
|
||||
class KotlinPackageEntryTable : JDOMExternalizable, Cloneable {
|
||||
private val entries = mutableListOf<KotlinPackageEntry>()
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is KotlinPackageEntryTable) return false
|
||||
if (other.entries.size != entries.size) return false
|
||||
|
||||
return entries.zip(other.entries).any { (entry, otherEntry) -> entry != otherEntry }
|
||||
}
|
||||
val entryCount: Int get() = entries.size
|
||||
|
||||
public override fun clone(): KotlinPackageEntryTable {
|
||||
val clone = KotlinPackageEntryTable()
|
||||
@@ -25,10 +20,6 @@ class KotlinPackageEntryTable: JDOMExternalizable, Cloneable {
|
||||
return clone
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return entries.firstOrNull()?.hashCode() ?: 0
|
||||
}
|
||||
|
||||
fun copyFrom(packageTable: KotlinPackageEntryTable) {
|
||||
entries.clear()
|
||||
entries.addAll(packageTable.entries)
|
||||
@@ -50,24 +41,12 @@ class KotlinPackageEntryTable: JDOMExternalizable, Cloneable {
|
||||
return entries[index]
|
||||
}
|
||||
|
||||
fun getEntryCount(): Int {
|
||||
return entries.size
|
||||
}
|
||||
|
||||
fun setEntryAt(entry: KotlinPackageEntry, index: Int) {
|
||||
entries[index] = entry
|
||||
}
|
||||
|
||||
operator fun contains(packageName: String): Boolean {
|
||||
for (entry in entries) {
|
||||
if (packageName.startsWith(entry.packageName)) {
|
||||
if (packageName.length == entry.packageName.length) return true
|
||||
if (entry.withSubpackages) {
|
||||
if (packageName[entry.packageName.length] == '.') return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return entries.any { !it.isSpecial && it.matchesPackageName(packageName) }
|
||||
}
|
||||
|
||||
fun removeEmptyPackages() {
|
||||
@@ -102,7 +81,7 @@ class KotlinPackageEntryTable: JDOMExternalizable, Cloneable {
|
||||
for (entry in entries) {
|
||||
val element = Element("package")
|
||||
parentNode.addContent(element)
|
||||
val name = if (entry == KotlinPackageEntry.ALL_OTHER_IMPORTS_ENTRY || entry == KotlinPackageEntry.ALL_OTHER_ALIAS_IMPORTS_ENTRY) "" else entry.packageName
|
||||
val name = if (entry.isSpecial) "" else entry.packageName
|
||||
val alias = (entry == KotlinPackageEntry.ALL_OTHER_ALIAS_IMPORTS_ENTRY)
|
||||
|
||||
element.setAttribute("name", name)
|
||||
|
||||
Reference in New Issue
Block a user