Cleanup: fix some compiler warnings (mostly deprecations, javaClass)
This commit is contained in:
@@ -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())
|
||||
|
||||
+2
-3
@@ -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
|
||||
|
||||
+1
-3
@@ -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)
|
||||
|
||||
+1
-2
@@ -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")
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user