Move static constants with builtin names to :core:descriptors.common module

This commit is contained in:
Dmitriy Novozhilov
2020-08-16 22:57:12 +03:00
parent 2e92fe9be9
commit 7a7fe77b8e
180 changed files with 1085 additions and 1025 deletions
@@ -5,17 +5,15 @@
package org.jetbrains.kotlin.nj2k.inference.mutability
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames.FqNames
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.nj2k.inference.common.BoundType
import org.jetbrains.kotlin.nj2k.inference.common.BoundTypeCalculatorImpl
import org.jetbrains.kotlin.nj2k.inference.common.BoundTypeEnhancer
import org.jetbrains.kotlin.nj2k.inference.common.InferenceContext
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtQualifiedExpression
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class MutabilityBoundTypeCalculator(
private val resolutionFacade: ResolutionFacade,
@@ -38,10 +36,10 @@ class MutabilityBoundTypeCalculator(
companion object {
private val PRESERVING_MUTABILITY_FQ_NAMES = setOf(
FQ_NAMES.collection.child(Name.identifier("iterator")),
FQ_NAMES.list.child(Name.identifier("listIterator")),
FQ_NAMES.map.child(Name.identifier("entries")),
FQ_NAMES.map.child(Name.identifier("values"))
FqNames.collection.child(Name.identifier("iterator")),
FqNames.list.child(Name.identifier("listIterator")),
FqNames.map.child(Name.identifier("entries")),
FqNames.map.child(Name.identifier("values"))
)
}
}
}
@@ -5,10 +5,8 @@
package org.jetbrains.kotlin.nj2k.inference.mutability
import com.intellij.psi.CommonClassNames
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames.FqNames
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.nj2k.inference.common.*
import org.jetbrains.kotlin.nj2k.inference.common.collectors.ConstraintsCollector
@@ -38,35 +36,35 @@ class MutabilityConstraintsCollector : ConstraintsCollector() {
companion object {
private val MUTATOR_CALL_FQ_NAMES = setOf(
FQ_NAMES.mutableCollection.child(Name.identifier("add")),
FQ_NAMES.mutableCollection.child(Name.identifier("addAll")),
FQ_NAMES.mutableCollection.child(Name.identifier("remove")),
FQ_NAMES.mutableCollection.child(Name.identifier("removeAll")),
FQ_NAMES.mutableCollection.child(Name.identifier("retainAll")),
FQ_NAMES.mutableCollection.child(Name.identifier("clear")),
FQ_NAMES.mutableCollection.child(Name.identifier("removeIf")),
FqNames.mutableCollection.child(Name.identifier("add")),
FqNames.mutableCollection.child(Name.identifier("addAll")),
FqNames.mutableCollection.child(Name.identifier("remove")),
FqNames.mutableCollection.child(Name.identifier("removeAll")),
FqNames.mutableCollection.child(Name.identifier("retainAll")),
FqNames.mutableCollection.child(Name.identifier("clear")),
FqNames.mutableCollection.child(Name.identifier("removeIf")),
FQ_NAMES.mutableList.child(Name.identifier("addAll")),
FQ_NAMES.mutableList.child(Name.identifier("set")),
FqNames.mutableList.child(Name.identifier("addAll")),
FqNames.mutableList.child(Name.identifier("set")),
FQ_NAMES.mutableMap.child(Name.identifier("put")),
FQ_NAMES.mutableMap.child(Name.identifier("remove")),
FQ_NAMES.mutableMap.child(Name.identifier("putAll")),
FQ_NAMES.mutableMap.child(Name.identifier("clear")),
FQ_NAMES.mutableMap.child(Name.identifier("putIfAbsent")),
FQ_NAMES.mutableMap.child(Name.identifier("replace")),
FQ_NAMES.mutableMap.child(Name.identifier("replaceAll")),
FQ_NAMES.mutableMap.child(Name.identifier("computeIfAbsent")),
FQ_NAMES.mutableMap.child(Name.identifier("computeIfPresent")),
FQ_NAMES.mutableMap.child(Name.identifier("compute")),
FQ_NAMES.mutableMap.child(Name.identifier("merge")),
FqNames.mutableMap.child(Name.identifier("put")),
FqNames.mutableMap.child(Name.identifier("remove")),
FqNames.mutableMap.child(Name.identifier("putAll")),
FqNames.mutableMap.child(Name.identifier("clear")),
FqNames.mutableMap.child(Name.identifier("putIfAbsent")),
FqNames.mutableMap.child(Name.identifier("replace")),
FqNames.mutableMap.child(Name.identifier("replaceAll")),
FqNames.mutableMap.child(Name.identifier("computeIfAbsent")),
FqNames.mutableMap.child(Name.identifier("computeIfPresent")),
FqNames.mutableMap.child(Name.identifier("compute")),
FqNames.mutableMap.child(Name.identifier("merge")),
FQ_NAMES.mutableMapEntry.child(Name.identifier("setValue")),
FqNames.mutableMapEntry.child(Name.identifier("setValue")),
FQ_NAMES.mutableIterator.child(Name.identifier("remove")),
FqNames.mutableIterator.child(Name.identifier("remove")),
FQ_NAMES.mutableListIterator.child(Name.identifier("set")),
FQ_NAMES.mutableListIterator.child(Name.identifier("add"))
FqNames.mutableListIterator.child(Name.identifier("set")),
FqNames.mutableListIterator.child(Name.identifier("add"))
)
}
}
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.nj2k.inference.mutability
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.nj2k.inference.common.State
import org.jetbrains.kotlin.nj2k.inference.common.StateUpdater
@@ -54,15 +54,15 @@ class MutabilityStateUpdater : StateUpdater() {
}
val mutableToImmutable = mapOf(
KotlinBuiltIns.FQ_NAMES.mutableIterator to KotlinBuiltIns.FQ_NAMES.iterator,
KotlinBuiltIns.FQ_NAMES.mutableCollection to KotlinBuiltIns.FQ_NAMES.collection,
KotlinBuiltIns.FQ_NAMES.mutableList to KotlinBuiltIns.FQ_NAMES.list,
KotlinBuiltIns.FQ_NAMES.mutableListIterator to KotlinBuiltIns.FQ_NAMES.listIterator,
KotlinBuiltIns.FQ_NAMES.mutableSet to KotlinBuiltIns.FQ_NAMES.set,
KotlinBuiltIns.FQ_NAMES.mutableMap to KotlinBuiltIns.FQ_NAMES.map,
KotlinBuiltIns.FQ_NAMES.mutableMapEntry to KotlinBuiltIns.FQ_NAMES.mapEntry
KotlinBuiltInsNames.FqNames.mutableIterator to KotlinBuiltInsNames.FqNames.iterator,
KotlinBuiltInsNames.FqNames.mutableCollection to KotlinBuiltInsNames.FqNames.collection,
KotlinBuiltInsNames.FqNames.mutableList to KotlinBuiltInsNames.FqNames.list,
KotlinBuiltInsNames.FqNames.mutableListIterator to KotlinBuiltInsNames.FqNames.listIterator,
KotlinBuiltInsNames.FqNames.mutableSet to KotlinBuiltInsNames.FqNames.set,
KotlinBuiltInsNames.FqNames.mutableMap to KotlinBuiltInsNames.FqNames.map,
KotlinBuiltInsNames.FqNames.mutableMapEntry to KotlinBuiltInsNames.FqNames.mapEntry
)
val immutableToMutable = mutableToImmutable.map { (key, value) -> value to key }.toMap()
}
}
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.nj2k.conversions
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames
import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.j2k.ast.Nullability
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
@@ -80,7 +80,7 @@ class ArrayInitializerConversion(context: NewJ2kConverterContext) : RecursiveApp
)
for (i in 0 until dimensions.size - 2) {
resultType = JKClassType(
symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.array.toSafe()),
symbolProvider.provideClassSymbol(KotlinBuiltInsNames.FqNames.array.toSafe()),
listOf(resultType),
Nullability.Default
)
@@ -91,4 +91,4 @@ class ArrayInitializerConversion(context: NewJ2kConverterContext) : RecursiveApp
JKTypeArgumentList(listOf(JKTypeElement(resultType)))
)
}
}
}
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.nj2k.conversions
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames
import org.jetbrains.kotlin.nj2k.*
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedField
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
import org.jetbrains.kotlin.nj2k.tree.*
import org.jetbrains.kotlin.nj2k.types.isArrayType
import org.jetbrains.kotlin.nj2k.types.isStringType
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -500,7 +499,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
},
Method("java.lang.String.format") convertTo CustomExpression { expression ->
JKClassAccessExpression(
symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.string)
symbolProvider.provideClassSymbol(KotlinBuiltInsNames.FqNames.string)
).callOn(
symbolProvider.provideMethodSymbol("kotlin.text.String.format"),
(expression as JKCallExpression).arguments::arguments.detached()
@@ -9,17 +9,12 @@ package org.jetbrains.kotlin.nj2k.symbols
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiReference
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
import org.jetbrains.kotlin.j2k.ast.Nullability
import org.jetbrains.kotlin.nj2k.tree.JKClass
import org.jetbrains.kotlin.nj2k.tree.JKMethod
import org.jetbrains.kotlin.nj2k.types.asType
import org.jetbrains.kotlin.nj2k.types.toJK
import org.jetbrains.kotlin.nj2k.types.JKClassType
import org.jetbrains.kotlin.nj2k.types.JKNoType
import org.jetbrains.kotlin.nj2k.types.JKType
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
import org.jetbrains.kotlin.nj2k.types.*
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -77,7 +72,7 @@ class JKMultiverseFunctionSymbol(
type?.let {
if (parameter.isVarArg) {
JKClassType(
symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.array.toSafe()),
symbolProvider.provideClassSymbol(KotlinBuiltInsNames.FqNames.array.toSafe()),
listOf(it)
)
} else it
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.nj2k.types
import com.intellij.psi.*
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.j2k.ast.Nullability
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
@@ -36,24 +36,24 @@ class JKTypeFactory(val symbolProvider: JKSymbolProvider) {
nullability
)
val boolean = typeByFqName(KotlinBuiltIns.FQ_NAMES._boolean)
val char = typeByFqName(KotlinBuiltIns.FQ_NAMES._char)
val byte = typeByFqName(KotlinBuiltIns.FQ_NAMES._byte)
val short = typeByFqName(KotlinBuiltIns.FQ_NAMES._short)
val int = typeByFqName(KotlinBuiltIns.FQ_NAMES._int)
val float = typeByFqName(KotlinBuiltIns.FQ_NAMES._float)
val long = typeByFqName(KotlinBuiltIns.FQ_NAMES._long)
val double = typeByFqName(KotlinBuiltIns.FQ_NAMES._double)
val boolean = typeByFqName(KotlinBuiltInsNames.FqNames._boolean)
val char = typeByFqName(KotlinBuiltInsNames.FqNames._char)
val byte = typeByFqName(KotlinBuiltInsNames.FqNames._byte)
val short = typeByFqName(KotlinBuiltInsNames.FqNames._short)
val int = typeByFqName(KotlinBuiltInsNames.FqNames._int)
val float = typeByFqName(KotlinBuiltInsNames.FqNames._float)
val long = typeByFqName(KotlinBuiltInsNames.FqNames._long)
val double = typeByFqName(KotlinBuiltInsNames.FqNames._double)
val string = typeByFqName(KotlinBuiltIns.FQ_NAMES.string)
val possiblyNullString = typeByFqName(KotlinBuiltIns.FQ_NAMES.string, nullability = Nullability.Default)
val string = typeByFqName(KotlinBuiltInsNames.FqNames.string)
val possiblyNullString = typeByFqName(KotlinBuiltInsNames.FqNames.string, nullability = Nullability.Default)
val unit = typeByFqName(KotlinBuiltIns.FQ_NAMES.unit)
val nothing = typeByFqName(KotlinBuiltIns.FQ_NAMES.nothing)
val nullableAny = typeByFqName(KotlinBuiltIns.FQ_NAMES.any, nullability = Nullability.Nullable)
val unit = typeByFqName(KotlinBuiltInsNames.FqNames.unit)
val nothing = typeByFqName(KotlinBuiltInsNames.FqNames.nothing)
val nullableAny = typeByFqName(KotlinBuiltInsNames.FqNames.any, nullability = Nullability.Nullable)
val javaKlass = typeByFqName(FqNameUnsafe(CommonClassNames.JAVA_LANG_CLASS))
val kotlinClass = typeByFqName(KotlinBuiltIns.FQ_NAMES.kClass)
val kotlinClass = typeByFqName(KotlinBuiltInsNames.FqNames.kClass)
}
fun fromPrimitiveType(primitiveType: JKJavaPrimitiveType) = when (primitiveType.jvmPrimitiveType) {
@@ -139,4 +139,4 @@ class JKTypeFactory(val symbolProvider: JKSymbolProvider) {
)
}
}
}
}
@@ -9,14 +9,17 @@ import com.intellij.psi.CommonClassNames
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiType
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltInsNames
import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
import org.jetbrains.kotlin.j2k.ast.Nullability
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
import org.jetbrains.kotlin.nj2k.tree.*
import org.jetbrains.kotlin.nj2k.tree.JKAnnotationList
import org.jetbrains.kotlin.nj2k.tree.JKClass
import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression
import org.jetbrains.kotlin.nj2k.tree.JKTypeElement
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.resolve.BindingContext
@@ -116,7 +119,7 @@ fun JKType.isStringType(): Boolean =
fun JKClassSymbol.isStringType(): Boolean =
fqName == CommonClassNames.JAVA_LANG_STRING
|| fqName == KotlinBuiltIns.FQ_NAMES.string.asString()
|| fqName == KotlinBuiltInsNames.FqNames.string.asString()
fun JKJavaPrimitiveType.toLiteralType(): JKLiteralExpression.LiteralType? =
when (this) {
@@ -134,14 +137,14 @@ fun JKJavaPrimitiveType.toLiteralType(): JKLiteralExpression.LiteralType? =
fun JKType.asPrimitiveType(): JKJavaPrimitiveType? =
if (this is JKJavaPrimitiveType) this
else when ((this as? JKClassType)?.classReference?.fqName) {
KotlinBuiltIns.FQ_NAMES._char.asString(), CommonClassNames.JAVA_LANG_CHARACTER -> JKJavaPrimitiveType.CHAR
KotlinBuiltIns.FQ_NAMES._boolean.asString(), CommonClassNames.JAVA_LANG_BOOLEAN -> JKJavaPrimitiveType.BOOLEAN
KotlinBuiltIns.FQ_NAMES._int.asString(), CommonClassNames.JAVA_LANG_INTEGER -> JKJavaPrimitiveType.INT
KotlinBuiltIns.FQ_NAMES._long.asString(), CommonClassNames.JAVA_LANG_LONG -> JKJavaPrimitiveType.LONG
KotlinBuiltIns.FQ_NAMES._float.asString(), CommonClassNames.JAVA_LANG_FLOAT -> JKJavaPrimitiveType.FLOAT
KotlinBuiltIns.FQ_NAMES._double.asString(), CommonClassNames.JAVA_LANG_DOUBLE -> JKJavaPrimitiveType.DOUBLE
KotlinBuiltIns.FQ_NAMES._byte.asString(), CommonClassNames.JAVA_LANG_BYTE -> JKJavaPrimitiveType.BYTE
KotlinBuiltIns.FQ_NAMES._short.asString(), CommonClassNames.JAVA_LANG_SHORT -> JKJavaPrimitiveType.SHORT
KotlinBuiltInsNames.FqNames._char.asString(), CommonClassNames.JAVA_LANG_CHARACTER -> JKJavaPrimitiveType.CHAR
KotlinBuiltInsNames.FqNames._boolean.asString(), CommonClassNames.JAVA_LANG_BOOLEAN -> JKJavaPrimitiveType.BOOLEAN
KotlinBuiltInsNames.FqNames._int.asString(), CommonClassNames.JAVA_LANG_INTEGER -> JKJavaPrimitiveType.INT
KotlinBuiltInsNames.FqNames._long.asString(), CommonClassNames.JAVA_LANG_LONG -> JKJavaPrimitiveType.LONG
KotlinBuiltInsNames.FqNames._float.asString(), CommonClassNames.JAVA_LANG_FLOAT -> JKJavaPrimitiveType.FLOAT
KotlinBuiltInsNames.FqNames._double.asString(), CommonClassNames.JAVA_LANG_DOUBLE -> JKJavaPrimitiveType.DOUBLE
KotlinBuiltInsNames.FqNames._byte.asString(), CommonClassNames.JAVA_LANG_BYTE -> JKJavaPrimitiveType.BYTE
KotlinBuiltInsNames.FqNames._short.asString(), CommonClassNames.JAVA_LANG_SHORT -> JKJavaPrimitiveType.SHORT
else -> null
}
@@ -167,7 +170,7 @@ val primitiveTypes =
fun JKType.arrayFqName(): String =
if (this is JKJavaPrimitiveType)
PrimitiveType.valueOf(jvmPrimitiveType.name).arrayTypeFqName.asString()
else KotlinBuiltIns.FQ_NAMES.array.asString()
else KotlinBuiltInsNames.FqNames.array.asString()
fun JKClassSymbol.isArrayType(): Boolean =
fqName in arrayFqNames
@@ -175,7 +178,7 @@ fun JKClassSymbol.isArrayType(): Boolean =
@OptIn(ExperimentalStdlibApi::class)
private val arrayFqNames = buildList {
JKJavaPrimitiveType.ALL.mapTo(this) { PrimitiveType.valueOf(it.jvmPrimitiveType.name).arrayTypeFqName.asString() }
add(KotlinBuiltIns.FQ_NAMES.array.asString())
add(KotlinBuiltInsNames.FqNames.array.asString())
}
fun JKType.isArrayType() =
@@ -186,19 +189,19 @@ fun JKType.isArrayType() =
}
fun JKType.isUnit() =
safeAs<JKClassType>()?.classReference?.fqName == KotlinBuiltIns.FQ_NAMES.unit.asString()
safeAs<JKClassType>()?.classReference?.fqName == KotlinBuiltInsNames.FqNames.unit.asString()
val JKType.isCollectionType: Boolean
get() = safeAs<JKClassType>()?.classReference?.fqName in collectionFqNames
private val collectionFqNames = setOf(
KotlinBuiltIns.FQ_NAMES.mutableIterator.asString(),
KotlinBuiltIns.FQ_NAMES.mutableList.asString(),
KotlinBuiltIns.FQ_NAMES.mutableCollection.asString(),
KotlinBuiltIns.FQ_NAMES.mutableSet.asString(),
KotlinBuiltIns.FQ_NAMES.mutableMap.asString(),
KotlinBuiltIns.FQ_NAMES.mutableMapEntry.asString(),
KotlinBuiltIns.FQ_NAMES.mutableListIterator.asString()
KotlinBuiltInsNames.FqNames.mutableIterator.asString(),
KotlinBuiltInsNames.FqNames.mutableList.asString(),
KotlinBuiltInsNames.FqNames.mutableCollection.asString(),
KotlinBuiltInsNames.FqNames.mutableSet.asString(),
KotlinBuiltInsNames.FqNames.mutableMap.asString(),
KotlinBuiltInsNames.FqNames.mutableMapEntry.asString(),
KotlinBuiltInsNames.FqNames.mutableListIterator.asString()
)
fun JKType.arrayInnerType(): JKType? =
@@ -228,7 +231,7 @@ fun JKType.replaceJavaClassWithKotlinClassType(symbolProvider: JKSymbolProvider)
applyRecursive { type ->
if (type is JKClassType && type.classReference.fqName == "java.lang.Class") {
JKClassType(
symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.kClass.toSafe()),
symbolProvider.provideClassSymbol(KotlinBuiltInsNames.FqNames.kClass.toSafe()),
type.parameters.map { it.replaceJavaClassWithKotlinClassType(symbolProvider) },
Nullability.NotNull
)