Cleanup: fix some compiler warnings (mostly deprecations, javaClass)

This commit is contained in:
Mikhail Glukhikh
2017-02-21 17:38:43 +03:00
parent d0cc1635db
commit b121bf8802
445 changed files with 773 additions and 949 deletions
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.load.java.lazy.types.RawTypeImpl
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition.Result
import org.jetbrains.kotlin.resolve.OverridingUtil
import org.jetbrains.kotlin.utils.singletonOrEmptyList
class ErasedOverridabilityCondition : ExternalOverridabilityCondition {
override fun isOverridable(superDescriptor: CallableDescriptor, subDescriptor: CallableDescriptor, subClassDescriptor: ClassDescriptor?): Result {
@@ -36,7 +35,7 @@ class ErasedOverridabilityCondition : ExternalOverridabilityCondition {
val signatureTypes = subDescriptor.valueParameters.asSequence().map { it.type } +
subDescriptor.returnType!! +
subDescriptor.extensionReceiverParameter?.type.singletonOrEmptyList()
listOfNotNull(subDescriptor.extensionReceiverParameter?.type)
if (signatureTypes.any { it.arguments.isNotEmpty() && it.unwrap() !is RawTypeImpl }) return Result.UNKNOWN
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.MemoizedFunctionToNullable
import org.jetbrains.kotlin.utils.emptyOrSingletonList
class LazyJavaPackageFragmentProvider(
components: JavaResolverComponents
@@ -41,7 +40,7 @@ class LazyJavaPackageFragmentProvider(
private fun getPackageFragment(fqName: FqName) = packageFragments(fqName)
override fun getPackageFragments(fqName: FqName) = emptyOrSingletonList(getPackageFragment(fqName))
override fun getPackageFragments(fqName: FqName) = listOfNotNull(getPackageFragment(fqName))
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean) =
getPackageFragment(fqName)?.getSubPackageFqNames().orEmpty()
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.util.collectionUtils.getFirstClassifierDiscriminateHeaders
import org.jetbrains.kotlin.util.collectionUtils.getFromAllScopes
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
class JvmPackageScope(
private val c: LazyJavaResolverContext,
@@ -43,7 +42,7 @@ class JvmPackageScope(
private val kotlinScopes by c.storageManager.createLazyValue {
packageFragment.binaryClasses.values.mapNotNull { partClass ->
c.components.deserializedDescriptorResolver.createKotlinPackagePartScope(packageFragment, partClass)
}.toReadOnlyList()
}.toList()
}
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
@@ -78,7 +77,7 @@ class JvmPackageScope(
}
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.println(this::class.java.simpleName, " {")
p.pushIndent()
p.println("containingDeclaration: $packageFragment")
@@ -48,8 +48,6 @@ import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
class LazyJavaClassDescriptor(
@@ -184,11 +182,11 @@ class LazyJavaClassDescriptor(
})
}
return if (result.isNotEmpty()) result.toReadOnlyList() else listOf(c.module.builtIns.anyType)
return if (result.isNotEmpty()) result.toList() else listOf(c.module.builtIns.anyType)
}
private fun getPurelyImplementedSupertype(): KotlinType? {
val annotatedPurelyImplementedFqName = getPurelyImplementsFqNameFromAnnotation()?.check {
val annotatedPurelyImplementedFqName = getPurelyImplementsFqNameFromAnnotation()?.takeIf {
!it.isRoot && it.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)
}
@@ -57,7 +57,6 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.utils.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
import java.util.*
@@ -87,8 +86,8 @@ class LazyJavaClassMemberScope(
}
enhanceSignatures(
result.ifEmpty { emptyOrSingletonList(createDefaultConstructor()) }
).toReadOnlyList()
result.ifEmpty { listOfNotNull(createDefaultConstructor()) }
).toList()
}
override fun JavaMethodDescriptor.isVisibleAsFunction(): Boolean {
@@ -192,8 +191,7 @@ class LazyJavaClassMemberScope(
val overriddenBuiltinProperty = getter?.getOverriddenBuiltinWithDifferentJvmName()
val specialGetterName = overriddenBuiltinProperty?.getBuiltinSpecialPropertyGetterName()
if (specialGetterName != null
&& !this@LazyJavaClassMemberScope.ownerDescriptor.hasRealKotlinSuperClassWithOverrideOf(
overriddenBuiltinProperty!!)
&& !this@LazyJavaClassMemberScope.ownerDescriptor.hasRealKotlinSuperClassWithOverrideOf(overriddenBuiltinProperty)
) {
return findGetterByName(specialGetterName, functions)
}
@@ -209,7 +207,7 @@ class LazyJavaClassMemberScope(
descriptor ->
if (descriptor.valueParameters.size != 0) return@factory null
descriptor.check { KotlinTypeChecker.DEFAULT.isSubtypeOf(descriptor.returnType ?: return@check false, type) }
descriptor.takeIf { KotlinTypeChecker.DEFAULT.isSubtypeOf(descriptor.returnType ?: return@takeIf false, type) }
}
}
@@ -221,7 +219,7 @@ class LazyJavaClassMemberScope(
if (descriptor.valueParameters.size != 1) return@factory null
if (!KotlinBuiltIns.isUnit(descriptor.returnType ?: return@factory null)) return@factory null
descriptor.check { KotlinTypeChecker.DEFAULT.equalTypes(descriptor.valueParameters.single().type, type) }
descriptor.takeIf { KotlinTypeChecker.DEFAULT.equalTypes(descriptor.valueParameters.single().type, type) }
}
}
@@ -46,7 +46,6 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberScopeImpl() {
@@ -89,7 +88,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
computeNonDeclaredFunctions(result, name)
enhanceSignatures(result).toReadOnlyList()
enhanceSignatures(result).toList()
}
open protected fun JavaMethodDescriptor.isVisibleAsFunction() = true
@@ -245,9 +244,9 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
computeNonDeclaredProperties(name, properties)
if (DescriptorUtils.isAnnotationClass(ownerDescriptor))
properties.toReadOnlyList()
properties.toList()
else
enhanceSignatures(properties).toReadOnlyList()
enhanceSignatures(properties).toList()
}
private fun resolveProperty(field: JavaField): PropertyDescriptor {
@@ -337,7 +336,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
}
}
return result.toReadOnlyList()
return result.toList()
}
protected abstract fun computeClassNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?): Set<Name>
@@ -345,7 +344,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
override fun toString() = "Lazy scope for $ownerDescriptor"
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.println(this::class.java.simpleName, " {")
p.pushIndent()
p.println("containingDeclaration: $ownerDescriptor")
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.types.Variance.*
import org.jetbrains.kotlin.types.typeUtil.createProjection
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
import org.jetbrains.kotlin.utils.sure
import org.jetbrains.kotlin.utils.toReadOnlyList
private val JAVA_LANG_CLASS_FQ_NAME: FqName = FqName("java.lang.Class")
@@ -225,12 +224,12 @@ class JavaTypeResolver(
}
RawSubstitution.computeProjection(parameter, attr, erasedUpperBound)
}.toReadOnlyList()
}.toList()
}
if (typeParameters.size != javaType.typeArguments.size) {
// Most of the time this means there is an error in the Java code
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toReadOnlyList()
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }.toList()
}
val howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
return javaType.typeArguments.withIndex().map {
@@ -243,7 +242,7 @@ class JavaTypeResolver(
val parameter = typeParameters[i]
transformToTypeProjection(javaTypeArgument, howTheProjectionIsUsed.toAttributes(), parameter)
}.toReadOnlyList()
}.toList()
}
private fun transformToTypeProjection(
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.load.java
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart
import org.jetbrains.kotlin.utils.singletonOrEmptyList
import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getPropertyNameCandidatesBySpecialGetterName
@@ -53,7 +52,7 @@ fun getPropertyNamesCandidatesByAccessorName(name: Name): List<Name> {
val nameAsString = name.asString()
if (JvmAbi.isGetterName(nameAsString)) {
return propertyNameByGetMethodName(name).singletonOrEmptyList()
return listOfNotNull(propertyNameByGetMethodName(name))
}
if (JvmAbi.isSetterName(nameAsString)) {
@@ -33,8 +33,6 @@ import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.createProjection
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.toReadOnlyList
// The index in the lambda is the position of the type component:
// Example: for `A<B, C<D, E>>`, indices go as follows: `0 - A<...>, 1 - B, 2 - C<D, E>, 3 - D, 4 - E`,
@@ -52,7 +50,7 @@ private enum class TypeComponentPosition {
}
private open class Result(open val type: KotlinType, val subtreeSize: Int, val wereChanges: Boolean) {
val typeIfChanged: KotlinType? get() = type.check { wereChanges }
val typeIfChanged: KotlinType? get() = type.takeIf { wereChanges }
}
private class SimpleResult(override val type: SimpleType, subtreeSize: Int, wereChanges: Boolean): Result(type, subtreeSize, wereChanges)
@@ -143,7 +141,7 @@ private fun SimpleType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
private fun List<Annotations>.compositeAnnotationsOrSingle() = when (size) {
0 -> error("At least one Annotations object expected")
1 -> single()
else -> CompositeAnnotations(this.toReadOnlyList())
else -> CompositeAnnotations(this.toList())
}
private fun TypeComponentPosition.shouldEnhance() = this != TypeComponentPosition.INFLEXIBLE
@@ -167,7 +167,7 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
container.isInner -> 1
else -> 0
}
else -> throw UnsupportedOperationException("Unsupported message: ${message.javaClass}")
else -> throw UnsupportedOperationException("Unsupported message: ${message::class.java}")
}
}
@@ -47,7 +47,6 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.LazyWrappedType
import org.jetbrains.kotlin.utils.DFS
import org.jetbrains.kotlin.utils.SmartSet
import org.jetbrains.kotlin.utils.addToStdlib.check
import java.io.Serializable
import java.util.*
@@ -263,7 +262,7 @@ open class JvmBuiltInsSettings(
// No additional members should be added to Any
if (isAny) return null
val fqName = fqNameUnsafe.check { it.isSafe }?.toSafe() ?: return null
val fqName = fqNameUnsafe.takeIf { it.isSafe }?.toSafe() ?: return null
val javaAnalogueFqName = j2kClassMap.mapKotlinToJava(fqName.toUnsafe())?.asSingleFqName() ?: return null
return ownerModuleDescriptor.resolveClassByFqName(javaAnalogueFqName, NoLookupLocation.FROM_BUILTINS) as? LazyJavaClassDescriptor
@@ -32,7 +32,7 @@ internal class UnsafeVarianceTypeSubstitution(kotlinBuiltIns: KotlinBuiltIns) :
val unsafeVariancePaths = mutableListOf<List<Int>>()
IndexedTypeHolder(topLevelType).checkTypePosition(
position,
{ typeParameter, indexedTypeHolder, errorPosition ->
{ _, indexedTypeHolder, _ ->
unsafeVariancePaths.add(indexedTypeHolder.argumentIndices)
},
customVariance = { null })
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.serialization.ClassData
import org.jetbrains.kotlin.serialization.PackageData
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.utils.singletonOrEmptyList
import java.io.ByteArrayInputStream
object JvmProtoBufUtil {
@@ -65,7 +64,7 @@ object JvmProtoBufUtil {
nameResolver.getString(signature.desc)
}
else {
val parameterTypes = proto.receiverType(typeTable).singletonOrEmptyList() + proto.valueParameterList.map { it.type(typeTable) }
val parameterTypes = listOfNotNull(proto.receiverType(typeTable)) + proto.valueParameterList.map { it.type(typeTable) }
val parametersDesc = parameterTypes.map { mapTypeDefault(it, nameResolver) ?: return null }
val returnTypeDesc = mapTypeDefault(proto.returnType(typeTable), nameResolver) ?: return null
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaElement
object RuntimeSourceElementFactory : JavaSourceElementFactory {
class RuntimeSourceElement(override val javaElement: ReflectJavaElement) : JavaSourceElement {
override fun toString() = javaClass.name + ": " + javaElement.toString()
override fun toString() = this::class.java.name + ": " + javaElement.toString()
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
}
@@ -36,5 +36,5 @@ class ReflectJavaAnnotation(val annotation: Annotation) : ReflectJavaElement(),
override fun hashCode() = annotation.hashCode()
override fun toString() = javaClass.name + ": " + annotation
override fun toString() = this::class.java.name + ": " + annotation
}
@@ -25,7 +25,7 @@ abstract class ReflectJavaAnnotationArgument(
companion object Factory {
fun create(value: Any, name: Name?): ReflectJavaAnnotationArgument {
return when {
value.javaClass.isEnumClassOrSpecializedEnumEntryClass() -> ReflectJavaEnumValueAnnotationArgument(name, value as Enum<*>)
value::class.java.isEnumClassOrSpecializedEnumEntryClass() -> ReflectJavaEnumValueAnnotationArgument(name, value as Enum<*>)
value is Annotation -> ReflectJavaAnnotationAsAnnotationArgument(name, value)
value is Array<*> -> ReflectJavaArrayAnnotationArgument(name, value)
value is Class<*> -> ReflectJavaClassObjectAnnotationArgument(name, value)
@@ -52,7 +52,7 @@ class ReflectJavaEnumValueAnnotationArgument(
private val value: Enum<*>
) : ReflectJavaAnnotationArgument(name), JavaEnumValueAnnotationArgument {
override fun resolve(): ReflectJavaField {
val clazz = value.javaClass
val clazz = value::class.java
val enumClass = if (clazz.isEnum) clazz else clazz.enclosingClass
return ReflectJavaField(enumClass.getDeclaredField(value.name))
}
@@ -25,7 +25,7 @@ class ReflectJavaArrayType(override val reflectType: Type) : ReflectJavaType(),
when {
this is GenericArrayType -> ReflectJavaType.create(genericComponentType)
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType())
else -> throw IllegalArgumentException("Not an array type (${reflectType.javaClass}): $reflectType")
else -> throw IllegalArgumentException("Not an array type (${reflectType::class.java}): $reflectType")
}
}
}
@@ -110,5 +110,5 @@ class ReflectJavaClass(
override fun hashCode() = klass.hashCode()
override fun toString() = javaClass.name + ": " + klass
override fun toString() = this::class.java.name + ": " + klass
}
@@ -32,7 +32,7 @@ class ReflectJavaClassifierType(public override val reflectType: Type) : Reflect
is Class<*> -> ReflectJavaClass(type)
is TypeVariable<*> -> ReflectJavaTypeParameter(type)
is ParameterizedType -> ReflectJavaClass(type.rawType as Class<*>)
else -> throw IllegalStateException("Not a classifier type (${type.javaClass}): $type")
else -> throw IllegalStateException("Not a classifier type (${type::class.java}): $type")
}
classifier
}
@@ -59,7 +59,7 @@ abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOw
override fun hashCode() = member.hashCode()
override fun toString() = javaClass.name + ": " + member
override fun toString() = this::class.java.name + ": " + member
}
private object Java8ParameterNamesLoader {
@@ -69,7 +69,7 @@ private object Java8ParameterNamesLoader {
fun buildCache(member: Member): Cache {
// This should be either j.l.reflect.Method or j.l.reflect.Constructor
val methodOrConstructorClass = member.javaClass
val methodOrConstructorClass = member::class.java
val getParameters = try {
methodOrConstructorClass.getMethod("getParameters")
@@ -37,5 +37,5 @@ class ReflectJavaPackage(override val fqName: FqName) : ReflectJavaElement(), Ja
override fun hashCode() = fqName.hashCode()
override fun toString() = javaClass.name + ": " + fqName
override fun toString() = this::class.java.name + ": " + fqName
}
@@ -39,5 +39,5 @@ abstract class ReflectJavaType : JavaType {
override fun hashCode() = reflectType.hashCode()
override fun toString() = javaClass.name + ": " + reflectType
override fun toString() = this::class.java.name + ": " + reflectType
}
@@ -42,5 +42,5 @@ class ReflectJavaTypeParameter(
override fun hashCode() = typeVariable.hashCode()
override fun toString() = javaClass.name + ": " + typeVariable
override fun toString() = this::class.java.name + ": " + typeVariable
}
@@ -38,5 +38,5 @@ class ReflectJavaValueParameter(
override val name: Name?
get() = reflectName?.let(Name::guessByFirstCharacter)
override fun toString() = javaClass.name + ": " + (if (isVararg) "vararg " else "") + name + ": " + type
override fun toString() = this::class.java.name + ": " + (if (isVararg) "vararg " else "") + name + ": " + type
}
@@ -75,7 +75,7 @@ val Class<*>.desc: String
}
fun Class<*>.createArrayType(): Class<*> =
Array.newInstance(this, 0).javaClass
Array.newInstance(this, 0)::class.java
/**
* @return all arguments of a parameterized type, including those of outer classes in case this type represents an inner generic.
@@ -72,7 +72,7 @@ class ReflectKotlinClass private constructor(
override fun hashCode() = klass.hashCode()
override fun toString() = javaClass.name + ": " + klass
override fun toString() = this::class.java.name + ": " + klass
}
private object ReflectClassStructure {
@@ -175,7 +175,7 @@ private object ReflectClassStructure {
}
private fun processAnnotationArgumentValue(visitor: KotlinJvmBinaryClass.AnnotationArgumentVisitor, name: Name, value: Any) {
val clazz = value.javaClass
val clazz = value::class.java
when {
clazz in TYPES_ELIGIBLE_FOR_SIMPLE_VISIT -> {
visitor.visit(name, value)
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
import org.jetbrains.kotlin.utils.DFS
import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.addToStdlib.check
import java.util.*
private fun KotlinType.isTypeOrSubtypeOf(predicate: (KotlinType) -> Boolean): Boolean =
@@ -150,7 +149,7 @@ fun KotlinType.extractParameterNameFromFunctionTypeArgument(): Name? {
val annotation = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.parameterName) ?: return null
val name = (annotation.allValueArguments.values.singleOrNull() as? StringValue)
?.value
?.check { Name.isValidIdentifier(it) }
?.takeIf { Name.isValidIdentifier(it) }
?: return null
return Name.identifier(name)
}
@@ -167,7 +166,7 @@ fun getFunctionTypeArgumentProjections(
arguments.addIfNotNull(receiverType?.asTypeProjection())
parameterTypes.mapIndexedTo(arguments) { index, type ->
val name = parameterNames?.get(index)?.check { !it.isSpecial }
val name = parameterNames?.get(index)?.takeIf { !it.isSpecial }
val typeToUse = if (name != null) {
val annotationClass = builtIns.getBuiltInClassByName(KotlinBuiltIns.FQ_NAMES.parameterName.shortName())
val nameValue = ConstantValueFactory(builtIns).createStringValue(name.asString())
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
/**
@@ -81,7 +80,7 @@ class FunctionClassDescriptor(
typeParameter(Variance.OUT_VARIANCE, "R")
parameters = result.toReadOnlyList()
parameters = result.toList()
}
override fun getContainingDeclaration() = containingDeclaration
@@ -146,7 +145,7 @@ class FunctionClassDescriptor(
add(kotlinPackageFragment, Kind.Function.numberedClassName(arity))
}
return result.toReadOnlyList()
return result.toList()
}
override fun getParameters() = this@FunctionClassDescriptor.parameters
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.descriptors
import org.jetbrains.kotlin.utils.singletonOrEmptyList
interface VariableDescriptorWithAccessors : VariableDescriptor {
val getter: VariableAccessorDescriptor?
@@ -35,4 +33,4 @@ interface VariableDescriptorWithAccessors : VariableDescriptor {
}
val VariableDescriptorWithAccessors.accessors: List<VariableAccessorDescriptor>
get() = getter.singletonOrEmptyList() + setter.singletonOrEmptyList()
get() = listOfNotNull(getter) + listOfNotNull(setter)
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.name.FqName
import java.util.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.toReadOnlyList
class CompositePackageFragmentProvider(// can be modified from outside
private val providers: List<PackageFragmentProvider>) : PackageFragmentProvider {
@@ -31,7 +30,7 @@ class CompositePackageFragmentProvider(// can be modified from outside
for (provider in providers) {
result.addAll(provider.getPackageFragments(fqName))
}
return result.toReadOnlyList()
return result.toList()
}
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> {
@@ -58,7 +58,7 @@ open class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, priv
}
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.println(this::class.java.simpleName, " {")
p.pushIndent()
p.popIndent()
@@ -282,7 +282,7 @@ internal class DescriptorRendererImpl(
return when (cd) {
is TypeParameterDescriptor, is ClassDescriptor, is TypeAliasDescriptor -> renderClassifierName(cd)
null -> typeConstructor.toString()
else -> error("Unexpected classifier: " + cd.javaClass)
else -> error("Unexpected classifier: " + cd::class.java)
}
}
@@ -38,7 +38,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
val copy = DescriptorRendererOptionsImpl()
//TODO: use Kotlin reflection
for (field in this.javaClass.declaredFields) {
for (field in this::class.java.declaredFields) {
if (field.modifiers.and(Modifier.STATIC) != 0) continue
field.isAccessible = true
val property = field.get(this) as? ObservableProperty<*> ?: continue
@@ -54,7 +54,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
}
private fun <T> property(initialValue: T): ReadWriteProperty<DescriptorRendererOptionsImpl, T> {
return Delegates.vetoable(initialValue) { property, oldValue, newValue ->
return Delegates.vetoable(initialValue) { _, _, _ ->
if (isLocked) {
throw IllegalStateException("Cannot modify readonly DescriptorRendererOptions")
}
@@ -47,7 +47,7 @@ object DescriptorEquivalenceForOverrides {
private fun areTypeParametersEquivalent(
a: TypeParameterDescriptor,
b: TypeParameterDescriptor,
equivalentCallables: (DeclarationDescriptor?, DeclarationDescriptor?) -> Boolean = {x, y -> false}
equivalentCallables: (DeclarationDescriptor?, DeclarationDescriptor?) -> Boolean = { _, _ -> false}
): Boolean {
if (a == b) return true
if (a.containingDeclaration == b.containingDeclaration) return false
@@ -69,7 +69,7 @@ object DescriptorEquivalenceForOverrides {
// Distinct locals are not equivalent
if (DescriptorUtils.isLocal(a) || DescriptorUtils.isLocal(b)) return false
if (!ownersEquivalent(a, b, {x, y -> false})) return false
if (!ownersEquivalent(a, b, { _, _ -> false})) return false
val overridingUtil = OverridingUtil.createWithEqualityAxioms eq@ {
c1, c2 ->
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.DFS
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addToStdlib.check
fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = companionObjectDescriptor ?: this
@@ -228,7 +227,7 @@ val DeclarationDescriptor.parents: Sequence<DeclarationDescriptor>
val CallableMemberDescriptor.propertyIfAccessor: CallableMemberDescriptor
get() = if (this is PropertyAccessorDescriptor) correspondingProperty else this
fun CallableDescriptor.fqNameOrNull(): FqName? = fqNameUnsafe.check { it.isSafe }?.toSafe()
fun CallableDescriptor.fqNameOrNull(): FqName? = fqNameUnsafe.takeIf { it.isSafe }?.toSafe()
fun CallableMemberDescriptor.firstOverridden(
useOriginal: Boolean = false,
@@ -61,7 +61,7 @@ class ArrayValue(
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
if (other == null || other::class.java != this::class.java) return false
return value == (other as ArrayValue).value
}
@@ -149,7 +149,7 @@ class EnumValue(
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
if (other == null || other::class.java != this::class.java) return false
return value == (other as EnumValue).value
}
@@ -201,7 +201,7 @@ class IntValue(
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
if (other == null || other::class.java != this::class.java) return false
val intValue = other as IntValue
@@ -266,7 +266,7 @@ class StringValue(
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false
if (other == null || other::class.java != this::class.java) return false
return value != (other as StringValue).value
}
@@ -57,7 +57,7 @@ abstract class AbstractScopeAdapter : MemberScope {
override fun getVariableNames() = workerScope.getVariableNames()
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.println(this::class.java.simpleName, " {")
p.pushIndent()
p.print("worker =")
@@ -47,7 +47,7 @@ class ChainedMemberScope(
override fun toString() = debugName
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, ": ", debugName, " {")
p.println(this::class.java.simpleName, ": ", debugName, " {")
p.pushIndent()
for (scope in scopes) {
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.lang.reflect.Modifier
interface MemberScope : ResolutionScope {
@@ -157,7 +156,7 @@ class DescriptorKindFilter(
val filter = field.get(null) as? DescriptorKindFilter
if (filter != null) MaskToName(filter.kindMask, field.name) else null
}
.toReadOnlyList()
.toList()
private val DEBUG_MASK_BIT_NAMES = staticFields<DescriptorKindFilter>()
.filter { it.type == Integer.TYPE }
@@ -166,7 +165,7 @@ class DescriptorKindFilter(
val isOneBitMask = mask == (mask and (-mask))
if (isOneBitMask) MaskToName(mask, field.name) else null
}
.toReadOnlyList()
.toList()
private inline fun <reified T : Any> staticFields() = T::class.java.fields.filter { Modifier.isStatic(it.modifiers) }
}
@@ -181,7 +180,7 @@ abstract class DescriptorKindExclude {
*/
abstract val fullyExcludedDescriptorKinds: Int
override fun toString() = this.javaClass.simpleName
override fun toString() = this::class.java.simpleName
object Extensions : DescriptorKindExclude() {
override fun excludes(descriptor: DeclarationDescriptor)
@@ -79,7 +79,7 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
override fun getVariableNames() = workerScope.getVariableNames()
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.println(this::class.java.simpleName, " {")
p.pushIndent()
p.println("substitutor = ")
@@ -34,9 +34,9 @@ fun captureFromArguments(
val arguments = type.arguments
if (arguments.all { it.projectionKind == Variance.INVARIANT }) return type
val newArguments = arguments.mapIndexed {
index, projection ->
if (projection.projectionKind == Variance.INVARIANT) return@mapIndexed projection
val newArguments = arguments.map {
projection ->
if (projection.projectionKind == Variance.INVARIANT) return@map projection
val lowerType = if (!projection.isStarProjection && projection.projectionKind == Variance.IN_VARIANCE) {
projection.type.unwrap()
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.types.checker.TypeCheckerContext.SupertypesPolicy
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addToStdlib.check
object StrictEqualityTypeChecker {
/**
@@ -106,7 +105,7 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
when (constructor) {
// Type itself can be just SimpleTypeImpl, not CapturedType. see KT-16147
is CapturedTypeConstructor -> {
val lowerType = constructor.typeProjection.check { it.projectionKind == Variance.IN_VARIANCE }?.type?.unwrap()
val lowerType = constructor.typeProjection.takeIf { it.projectionKind == Variance.IN_VARIANCE }?.type?.unwrap()
// it is incorrect calculate this type directly because of recursive star projections
if (constructor.newTypeConstructor == null) {
@@ -191,9 +190,9 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
else -> { // at least 2 supertypes with same constructors. Such case is rare
if (supertypesWithSameConstructor.any { isSubtypeForSameConstructor(it.arguments, superType) }) return true
val newArguments = superConstructor.parameters.mapIndexed { index, parameterDescriptor ->
val newArguments = superConstructor.parameters.mapIndexed { index, _ ->
val allProjections = supertypesWithSameConstructor.map {
it.arguments.getOrNull(index)?.check { it.projectionKind == Variance.INVARIANT }?.type?.unwrap()
it.arguments.getOrNull(index)?.takeIf { it.projectionKind == Variance.INVARIANT }?.type?.unwrap()
?: error("Incorrect type: $it, subType: $subType, superType: $superType")
}
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.SmartSet
import org.jetbrains.kotlin.utils.addToStdlib.check
import java.util.*
open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean) {
@@ -85,7 +84,7 @@ open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean) {
return true
}
val policy = supertypesPolicy(current).check { it != SupertypesPolicy.None } ?: continue
val policy = supertypesPolicy(current).takeIf { it != SupertypesPolicy.None } ?: continue
for (supertype in current.constructor.supertypes) deque.add(policy.transformType(supertype))
}
@@ -90,12 +90,12 @@ private fun TypeConstructor.debugInfo() = buildString {
+ "type: ${this@debugInfo}"
+ "hashCode: ${this@debugInfo.hashCode()}"
+ "javaClass: ${this@debugInfo.javaClass.canonicalName}"
+ "javaClass: ${this@debugInfo::class.java.canonicalName}"
var declarationDescriptor: DeclarationDescriptor? = declarationDescriptor
while (declarationDescriptor != null) {
+ "fqName: ${DescriptorRenderer.FQ_NAMES_IN_TYPES.render(declarationDescriptor)}"
+ "javaClass: ${declarationDescriptor.javaClass.canonicalName}"
+ "javaClass: ${declarationDescriptor::class.java.canonicalName}"
declarationDescriptor = declarationDescriptor.containingDeclaration
}
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.utils.singletonOrEmptyList
abstract class AbstractDeserializedPackageFragmentProvider(
protected val storageManager: StorageManager,
@@ -39,7 +38,7 @@ abstract class AbstractDeserializedPackageFragmentProvider(
protected abstract fun findPackage(fqName: FqName): DeserializedPackageFragment?
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> = fragments(fqName).singletonOrEmptyList()
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> = listOfNotNull(fragments(fqName))
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> = emptySet()
}
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
import org.jetbrains.kotlin.utils.toReadOnlyList
class MemberDeserializer(private val c: DeserializationContext) {
private val annotationDeserializer = AnnotationDeserializer(c.components.moduleDescriptor, c.components.notFoundClasses)
@@ -267,7 +266,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
proto.varargElementType(c.typeTable)?.let { c.typeDeserializer.type(it) },
SourceElement.NO_SOURCE
)
}.toReadOnlyList()
}.toList()
}
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) {
@@ -53,5 +53,5 @@ sealed class ProtoContainer(
abstract fun debugFqName(): FqName
override fun toString() = "${javaClass.simpleName}: ${debugFqName()}"
override fun toString() = "${this::class.java.simpleName}: ${debugFqName()}"
}
@@ -29,8 +29,6 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.addToStdlib.check
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
class TypeDeserializer(
@@ -60,7 +58,7 @@ class TypeDeserializer(
}
val ownTypeParameters: List<TypeParameterDescriptor>
get() = typeParameterDescriptors.values.toReadOnlyList()
get() = typeParameterDescriptors.values.toList()
// TODO: don't load identical types from TypeTable more than once
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
@@ -99,7 +97,7 @@ class TypeDeserializer(
val arguments = proto.collectAllArguments().mapIndexed { index, proto ->
typeArgument(constructor.parameters.getOrNull(index), proto)
}.toReadOnlyList()
}.toList()
val simpleType = if (Flags.SUSPEND_TYPE.get(proto.flags)) {
createSuspendFunctionType(annotations, constructor, arguments, proto.nullable)
@@ -148,7 +146,7 @@ class TypeDeserializer(
val result = when (functionTypeConstructor.parameters.size - arguments.size) {
0 -> {
val functionType = KotlinTypeFactory.simpleType(annotations, functionTypeConstructor, arguments, nullable)
functionType.check { it.isFunctionType }?.let(::transformRuntimeFunctionTypeToSuspendFunction)
functionType.takeIf { it.isFunctionType }?.let(::transformRuntimeFunctionTypeToSuspendFunction)
}
// This case for types written by eap compiler 1.1
1 -> {
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.utils.toReadOnlyList
class DeserializedAnnotations(
storageManager: StorageManager,
@@ -36,7 +35,7 @@ open class DeserializedAnnotationsWithPossibleTargets(
storageManager: StorageManager,
compute: () -> List<AnnotationWithTarget>
) : Annotations {
private val annotations = storageManager.createLazyValue { compute().toReadOnlyList() }
private val annotations = storageManager.createLazyValue { compute().toList() }
override fun isEmpty(): Boolean = annotations().isEmpty()
@@ -38,8 +38,6 @@ import org.jetbrains.kotlin.serialization.deserialization.*
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.utils.singletonOrEmptyList
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
class DeserializedClassDescriptor(
@@ -127,7 +125,7 @@ class DeserializedClassDescriptor(
override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = primaryConstructor()
private fun computeConstructors(): Collection<ClassConstructorDescriptor> =
computeSecondaryConstructors() + unsubstitutedPrimaryConstructor.singletonOrEmptyList() +
computeSecondaryConstructors() + listOfNotNull(unsubstitutedPrimaryConstructor) +
c.components.additionalClassPartsProvider.getConstructors(this)
private fun computeSecondaryConstructors(): List<ClassConstructorDescriptor> =
@@ -192,7 +190,7 @@ class DeserializedClassDescriptor(
)
}
return result.toReadOnlyList()
return result.toList()
}
override fun getParameters() = parameters()
@@ -227,7 +227,7 @@ abstract class DeserializedMemberScope protected constructor(
protected abstract fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.println(this::class.java.simpleName, " {")
p.pushIndent()
p.println("containingDeclaration = " + c.containingDeclaration)
@@ -97,7 +97,7 @@ class SinceKotlinInfo(
is ProtoBuf.Function -> if (proto.hasSinceKotlinInfo()) proto.sinceKotlinInfo else return null
is ProtoBuf.Property -> if (proto.hasSinceKotlinInfo()) proto.sinceKotlinInfo else return null
is ProtoBuf.TypeAlias -> if (proto.hasSinceKotlinInfo()) proto.sinceKotlinInfo else return null
else -> throw IllegalStateException("Unexpected declaration: ${proto.javaClass}")
else -> throw IllegalStateException("Unexpected declaration: ${proto::class.java}")
}
val info = table[id] ?: return null
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.load.java.structure.reflect.safeClassLoader
import org.jetbrains.kotlin.load.kotlin.reflect.RuntimeModuleData
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.lang.reflect.Constructor
import java.lang.reflect.Method
import java.util.*
@@ -65,7 +64,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
belonginess.accept(descriptor))
descriptor.accept(visitor, Unit)
else null
}.toReadOnlyList()
}.toList()
}
protected enum class MemberBelonginess {
@@ -52,7 +52,8 @@ abstract class BinaryVersion(vararg val numbers: Int) {
}
override fun equals(other: Any?) =
this.javaClass == other?.javaClass &&
other != null &&
this::class.java == other::class.java &&
major == (other as BinaryVersion).major && minor == other.minor && patch == other.patch && rest == other.rest
override fun hashCode(): Int{
@@ -92,7 +92,7 @@ fun <T : Any> constant(calculator: () -> T): T {
if (cached != null) return cached as T
// safety check
val fields = calculator.javaClass.declaredFields.filter { it.modifiers.and(Modifier.STATIC) == 0 }
val fields = calculator::class.java.declaredFields.filter { it.modifiers.and(Modifier.STATIC) == 0 }
assert(fields.isEmpty()) {
"No fields in the passed lambda expected but ${fields.joinToString()} found"
}
@@ -31,7 +31,7 @@ private val ALWAYS_NULL: (Any?) -> Any? = { null }
fun <T, R: Any> alwaysNull(): (T) -> R? = ALWAYS_NULL as (T) -> R?
val DO_NOTHING: (Any?) -> Unit = { }
val DO_NOTHING_2: (Any?, Any?) -> Unit = { x, y -> }
val DO_NOTHING_3: (Any?, Any?, Any?) -> Unit = { x, y, z -> }
val DO_NOTHING_2: (Any?, Any?) -> Unit = { _, _ -> }
val DO_NOTHING_3: (Any?, Any?, Any?) -> Unit = { _, _, _ -> }
fun <T> doNothing(): (T) -> Unit = DO_NOTHING