No need to insert imports of Kotlin standard classes if java.util.* is imported
This commit is contained in:
committed by
Valentin Kipyatkov
parent
ccdcbf702a
commit
51a5125987
@@ -41,7 +41,6 @@ class Converter private(private val elementToConvert: PsiElement,
|
||||
|
||||
// state which is shared between all converter's based on this one
|
||||
private class CommonState(val usageProcessingsCollector: (UsageProcessing) -> Unit) {
|
||||
val importsToAdd = LinkedHashSet<String>()
|
||||
val deferredElements = ArrayList<DeferredElement<*>>()
|
||||
val postUnfoldActions = ArrayList<() -> Unit>()
|
||||
}
|
||||
@@ -54,10 +53,6 @@ class Converter private(private val elementToConvert: PsiElement,
|
||||
public val annotationConverter: AnnotationConverter = AnnotationConverter(this)
|
||||
|
||||
public val specialContext: PsiElement? = personalState.specialContext
|
||||
public val importsToAdd: MutableCollection<String> = commonState.importsToAdd
|
||||
|
||||
private val importList = (elementToConvert as? PsiJavaFile)?.getImportList()?.let { convertImportList(it) }
|
||||
public val importNames: Set<String> = importList?.imports?.mapTo(HashSet<String>()) { it.name } ?: setOf()
|
||||
|
||||
class object {
|
||||
public fun create(elementToConvert: PsiElement, settings: ConverterSettings, conversionScope: ConversionScope,
|
||||
@@ -127,23 +122,7 @@ class Converter private(private val elementToConvert: PsiElement,
|
||||
}
|
||||
|
||||
private fun convertFile(javaFile: PsiJavaFile): File {
|
||||
var convertedChildren = javaFile.getChildren().map {
|
||||
if (it is PsiImportList) {
|
||||
assert(it == javaFile.getImportList())
|
||||
importList
|
||||
}
|
||||
else {
|
||||
convertTopElement(it)
|
||||
}
|
||||
}.filterNotNull()
|
||||
|
||||
addPostUnfoldDeferredElementsAction {
|
||||
assert(importList != null)
|
||||
if (importsToAdd.isNotEmpty()) {
|
||||
importList!!.imports = importList.imports + importsToAdd.map { Import(it).assignNoPrototype() }
|
||||
}
|
||||
}
|
||||
|
||||
var convertedChildren = javaFile.getChildren().map { convertTopElement(it) }.filterNotNull()
|
||||
return File(convertedChildren, createMainFunction(javaFile)).assignPrototype(javaFile)
|
||||
}
|
||||
|
||||
|
||||
@@ -65,11 +65,7 @@ class TypeVisitor(private val converter: Converter,
|
||||
val kotlinClassName = (if (mutability.isMutable(converter.settings)) toKotlinMutableTypesMap[javaClassName] else null)
|
||||
?: toKotlinTypesMap[javaClassName]
|
||||
if (kotlinClassName != null) {
|
||||
val kotlinShortName = getShortName(kotlinClassName)
|
||||
if (kotlinShortName == getShortName(javaClassName!!) && converter.importNames.contains(getPackageName(javaClassName) + ".*")) {
|
||||
converter.importsToAdd.add(kotlinClassName)
|
||||
}
|
||||
return ReferenceElement(Identifier(kotlinShortName).assignNoPrototype(), typeArgs).assignNoPrototype()
|
||||
return ReferenceElement(Identifier(getShortName(kotlinClassName)).assignNoPrototype(), typeArgs).assignNoPrototype()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import java.util.*
|
||||
import kotlin.List
|
||||
|
||||
class A {
|
||||
private val field1 = ArrayList<String>()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import java.util.*
|
||||
import kotlin.List
|
||||
|
||||
class A {
|
||||
var list: List<String> = ArrayList()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import java.util.*
|
||||
import kotlin.Map
|
||||
|
||||
class A {
|
||||
fun foo(): Map<String, String> {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// ERROR: Type mismatch: inferred type is T? but T was expected
|
||||
import java.util.*
|
||||
import kotlin.Collection
|
||||
|
||||
class A<T> {
|
||||
fun foo(nonMutableCollection: Collection<String>, mutableCollection: MutableCollection<String>, mutableSet: MutableSet<T>, mutableMap: MutableMap<String, T>) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import java.util.*
|
||||
import kotlin.Collection
|
||||
|
||||
class A {
|
||||
fun createCollection(): MutableCollection<String> {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import java.util.*
|
||||
import kotlin.Collection
|
||||
|
||||
class A {
|
||||
private val collection: MutableCollection<String>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// !specifyFieldTypeByDefault: true
|
||||
import java.util.*
|
||||
import kotlin.List
|
||||
|
||||
class A {
|
||||
private val field1: List<String> = ArrayList()
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import java.util.*
|
||||
import kotlin.Iterator
|
||||
import kotlin.List
|
||||
|
||||
trait I<T : List<Iterator<String>>>
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package demo
|
||||
|
||||
import java.util.*
|
||||
import kotlin.Iterator
|
||||
|
||||
class Test : Iterable<String> {
|
||||
override fun iterator(): Iterator<String> {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// ERROR: Type inference failed. Expected type mismatch: found: java.util.HashMap<kotlin.Any!, kotlin.Any!> required: kotlin.Map<kotlin.String, kotlin.String>
|
||||
import java.util.*
|
||||
import kotlin.Map
|
||||
|
||||
class A {
|
||||
class object {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import java.util.*
|
||||
import javaApi.T
|
||||
import kotlin.Set
|
||||
|
||||
class A {
|
||||
public fun foo(t: T): Any {
|
||||
|
||||
Reference in New Issue
Block a user