From 29d32b213e3c11adedfb1a714c7ba731fc41437d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 15 Mar 2019 15:38:30 +0100 Subject: [PATCH] Cleanup modules descriptors.jvm, descriptors.runtime Fix warnings and inspections --- .../kotlin/builtins/jvm/JavaToKotlinClassMap.kt | 12 ++++++------ .../java/FakePureImplementationsProvider.kt | 3 +-- ...compatibilityRulesOverridabilityCondition.kt | 2 +- .../org/jetbrains/kotlin/load/java/JvmAbi.java | 1 - .../components/DescriptorResolverUtils.java | 13 ++++++++----- .../java/components/JavaAnnotationMapper.kt | 6 +++--- .../JavaPropertyInitializerEvaluator.kt | 2 +- .../kotlin/load/java/descriptors/util.kt | 6 +----- .../load/java/lazy/ModuleClassResolver.kt | 2 +- .../descriptors/LazyJavaClassMemberScope.kt | 9 +++++---- .../lazy/descriptors/LazyJavaPackageScope.kt | 9 ++------- .../load/java/lazy/descriptors/LazyJavaScope.kt | 8 ++++---- .../lazy/descriptors/LazyJavaStaticScope.kt | 5 +++-- .../load/java/lazy/types/JavaTypeResolver.kt | 6 +++--- .../load/java/propertiesConventionUtil.kt | 5 ++--- .../kotlin/load/java/specialBuiltinMembers.kt | 3 +-- .../predefinedEnhancementInfo.kt | 3 +-- .../java/typeEnhancement/typeEnhancement.kt | 4 ++-- ...actBinaryClassAnnotationAndConstantLoader.kt | 10 +++++----- ...inaryClassAnnotationAndConstantLoaderImpl.kt | 2 +- .../kotlin/DeserializedDescriptorResolver.kt | 9 ++++----- .../kotlin/load/kotlin/MemberSignature.kt | 5 +++-- .../load/kotlin/header/KotlinClassHeader.kt | 5 +++-- .../ReadKotlinClassHeaderAnnotationVisitor.java | 2 +- .../load/kotlin/methodSignatureBuilding.kt | 7 ++----- .../load/kotlin/methodSignatureMapping.kt | 4 ++-- .../kotlin/load/kotlin/typeSignatureMapping.kt | 6 +++--- .../components/ReflectJavaClassFinder.kt | 1 - .../internal/components/ReflectKotlinClass.kt | 17 ++++++++--------- .../structure/ReflectJavaAnnotationArguments.kt | 2 +- .../internal/structure/ReflectJavaArrayType.kt | 4 ++-- .../jvm/internal/structure/ReflectJavaClass.kt | 5 +++-- .../structure/ReflectJavaClassifierType.kt | 2 +- .../jvm/internal/structure/ReflectJavaField.kt | 2 +- .../structure/ReflectJavaModifierListOwner.kt | 2 +- .../internal/structure/ReflectJavaPackage.kt | 2 +- .../structure/ReflectJavaWildcardType.kt | 4 ++-- .../tests/GenerateRuntimeDescriptorTests.kt | 2 +- .../AbstractJvmRuntimeDescriptorLoaderTest.kt | 6 +++--- 39 files changed, 93 insertions(+), 105 deletions(-) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt index c61c599bce8..37425ddea2c 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt @@ -170,8 +170,8 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap { val readOnlyFqName = readOnlyClassId.asSingleFqName() val mutableFqName = mutableClassId.asSingleFqName() - mutableToReadOnly.put(mutableClassId.asSingleFqName().toUnsafe(), readOnlyFqName) - readOnlyToMutable.put(readOnlyFqName.toUnsafe(), mutableFqName) + mutableToReadOnly[mutableClassId.asSingleFqName().toUnsafe()] = readOnlyFqName + readOnlyToMutable[readOnlyFqName.toUnsafe()] = mutableFqName } private fun add(javaClassId: ClassId, kotlinClassId: ClassId) { @@ -188,11 +188,11 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap { } private fun addJavaToKotlin(javaClassId: ClassId, kotlinClassId: ClassId) { - javaToKotlin.put(javaClassId.asSingleFqName().toUnsafe(), kotlinClassId) + javaToKotlin[javaClassId.asSingleFqName().toUnsafe()] = kotlinClassId } private fun addKotlinToJava(kotlinFqNameUnsafe: FqName, javaClassId: ClassId) { - kotlinToJava.put(kotlinFqNameUnsafe.toUnsafe(), javaClassId) + kotlinToJava[kotlinFqNameUnsafe.toUnsafe()] = javaClassId } fun isJavaPlatformClass(fqName: FqName): Boolean = mapJavaToKotlin(fqName) != null @@ -210,7 +210,7 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap { return if (className.isSafe) mapPlatformClass(className.toSafe(), classDescriptor.builtIns) else - emptySet() + emptySet() } fun mutableToReadOnly(fqNameUnsafe: FqNameUnsafe?): FqName? = mutableToReadOnly[fqNameUnsafe] @@ -244,7 +244,7 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap { } private fun classId(clazz: Class<*>): ClassId { - assert(!clazz.isPrimitive && !clazz.isArray) { "Invalid class: " + clazz } + assert(!clazz.isPrimitive && !clazz.isArray) { "Invalid class: $clazz" } val outer = clazz.declaringClass return if (outer == null) ClassId.topLevel(FqName(clazz.canonicalName)) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/FakePureImplementationsProvider.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/FakePureImplementationsProvider.kt index 654b62e49a9..269d2668165 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/FakePureImplementationsProvider.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/FakePureImplementationsProvider.kt @@ -24,7 +24,7 @@ object FakePureImplementationsProvider { private val pureImplementations = hashMapOf() private infix fun FqName.implementedWith(implementations: List) { - implementations.associateTo(pureImplementations) { it to this } + implementations.associateWithTo(pureImplementations) { this } } init { @@ -40,4 +40,3 @@ object FakePureImplementationsProvider { private fun fqNameListOf(vararg names: String): List = names.map(::FqName) } - diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JavaIncompatibilityRulesOverridabilityCondition.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JavaIncompatibilityRulesOverridabilityCondition.kt index 7f169d1cd57..527e1d0b474 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JavaIncompatibilityRulesOverridabilityCondition.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JavaIncompatibilityRulesOverridabilityCondition.kt @@ -95,7 +95,7 @@ class JavaIncompatibilityRulesOverridabilityCondition : ExternalOverridabilityCo // void get(Object x) {} // } // - // The problem is that when checking overridabilty of `A.get` and `HashMap.get` we fall through to here, because + // The problem is that when checking overridability of `A.get` and `HashMap.get` we fall through to here, because // we do not recreate a magic copy of it, because it has the same signature. // But it obviously that if subDescriptor and superDescriptor has the same JVM descriptor, they're one-way overridable. // Note that it doesn't work if special builtIn was renamed, because we do not consider renamed built-ins diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JvmAbi.java b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JvmAbi.java index 7eee17089a0..9800f414a34 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JvmAbi.java +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/JvmAbi.java @@ -26,7 +26,6 @@ public final class JvmAbi { * This is false for KAPT3 mode. */ public static final String DEFAULT_IMPLS_SUFFIX = "$" + DEFAULT_IMPLS_CLASS_NAME; - public static final String DEFAULT_IMPLS_DELEGATE_SUFFIX = "$defaultImpl"; public static final String DEFAULT_PARAMS_IMPL_SUFFIX = "$default"; diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/DescriptorResolverUtils.java b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/DescriptorResolverUtils.java index 317093e2715..735a2bf3bef 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/DescriptorResolverUtils.java +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/DescriptorResolverUtils.java @@ -20,7 +20,10 @@ import kotlin.Unit; import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.descriptors.*; +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor; +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor; +import org.jetbrains.kotlin.descriptors.ClassDescriptor; +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor; import org.jetbrains.kotlin.load.java.structure.*; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.Name; @@ -119,18 +122,18 @@ public final class DescriptorResolverUtils { return member.getContainingClass().isInterface() && member instanceof JavaMethod && isObjectMethod((JavaMethod) member); } - public static boolean isObjectMethod(@NotNull JavaMethod method) { + private static boolean isObjectMethod(@NotNull JavaMethod method) { String name = method.getName().asString(); if (name.equals("toString") || name.equals("hashCode")) { return method.getValueParameters().isEmpty(); } else if (name.equals("equals")) { - return isMethodWithOneParameterWithFqName(method, "java.lang.Object"); + return isMethodWithOneObjectParameter(method); } return false; } - private static boolean isMethodWithOneParameterWithFqName(@NotNull JavaMethod method, @NotNull String fqName) { + private static boolean isMethodWithOneObjectParameter(@NotNull JavaMethod method) { List parameters = method.getValueParameters(); if (parameters.size() == 1) { JavaType type = parameters.get(0).getType(); @@ -138,7 +141,7 @@ public final class DescriptorResolverUtils { JavaClassifier classifier = ((JavaClassifierType) type).getClassifier(); if (classifier instanceof JavaClass) { FqName classFqName = ((JavaClass) classifier).getFqName(); - return classFqName != null && classFqName.asString().equals(fqName); + return classFqName != null && classFqName.asString().equals("java.lang.Object"); } } } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt index 92b34422e71..261e5fcf8a9 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaAnnotationMapper.kt @@ -73,9 +73,9 @@ object JavaAnnotationMapper { return JavaDeprecatedAnnotationDescriptor(javaAnnotation, c) } } - return kotlinToJavaNameMap[kotlinName]?.let { - annotationOwner.findAnnotation(it)?.let { - mapOrResolveJavaAnnotation(it, c) + return kotlinToJavaNameMap[kotlinName]?.let { javaName -> + annotationOwner.findAnnotation(javaName)?.let { annotation -> + mapOrResolveJavaAnnotation(annotation, c) } } } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluator.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluator.kt index 7659487c781..9889a7cc5f8 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluator.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/components/JavaPropertyInitializerEvaluator.kt @@ -24,6 +24,6 @@ interface JavaPropertyInitializerEvaluator { fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>? object DoNothing : JavaPropertyInitializerEvaluator { - override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor) = null + override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>? = null } } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/util.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/util.kt index a9cca3c68f1..c4005feee85 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/util.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/descriptors/util.kt @@ -64,11 +64,7 @@ fun copyValueParameters( fun ClassDescriptor.getParentJavaStaticClassScope(): LazyJavaStaticClassScope? { val superClassDescriptor = getSuperClassNotAny() ?: return null - val staticScope = superClassDescriptor.staticScope - - if (staticScope !is LazyJavaStaticClassScope) return superClassDescriptor.getParentJavaStaticClassScope() - - return staticScope + return superClassDescriptor.staticScope as? LazyJavaStaticClassScope ?: superClassDescriptor.getParentJavaStaticClassScope() } fun DeserializedMemberDescriptor.getImplClassNameForDeserialized(): JvmClassName? = diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/ModuleClassResolver.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/ModuleClassResolver.kt index 944ccd01960..aa806cee196 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/ModuleClassResolver.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/ModuleClassResolver.kt @@ -25,7 +25,7 @@ interface ModuleClassResolver { fun resolveClass(javaClass: JavaClass): ClassDescriptor? } -class SingleModuleClassResolver() : ModuleClassResolver { +class SingleModuleClassResolver : ModuleClassResolver { override fun resolveClass(javaClass: JavaClass): ClassDescriptor? = resolver.resolveClass(javaClass) // component dependency cycle diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt index 5fddd7db3c2..82f60dd204a 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaClassMemberScope.kt @@ -44,6 +44,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.load.java.structure.JavaConstructor import org.jetbrains.kotlin.load.java.structure.JavaMethod import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor +import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorFactory import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -68,7 +69,7 @@ class LazyJavaClassMemberScope( private val jClass: JavaClass ) : LazyJavaScope(c) { - override fun computeMemberIndex() = ClassDeclaredMemberIndex(jClass, { !it.isStatic }) + override fun computeMemberIndex() = ClassDeclaredMemberIndex(jClass) { !it.isStatic } override fun computeFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?) = ownerDescriptor.typeConstructor.supertypes.flatMapTo(hashSetOf()) { @@ -170,7 +171,7 @@ class LazyJavaClassMemberScope( private fun SimpleFunctionDescriptor.createSuspendView(): SimpleFunctionDescriptor? { val continuationParameter = valueParameters.lastOrNull()?.takeIf { isContinuation( - it.type.constructor.declarationDescriptor?.fqNameUnsafe?.takeIf { it.isSafe }?.toSafe(), + it.type.constructor.declarationDescriptor?.fqNameUnsafe?.takeIf(FqNameUnsafe::isSafe)?.toSafe(), c.components.settings.isReleaseCoroutines ) } ?: return null @@ -551,11 +552,11 @@ class LazyJavaClassMemberScope( override fun resolveMethodSignature( method: JavaMethod, methodTypeParameters: List, returnType: KotlinType, valueParameters: List - ): LazyJavaScope.MethodSignatureData { + ): MethodSignatureData { val propagated = c.components.signaturePropagator.resolvePropagatedSignature( method, ownerDescriptor, returnType, null, valueParameters, methodTypeParameters ) - return LazyJavaScope.MethodSignatureData( + return MethodSignatureData( propagated.returnType, propagated.receiverType, propagated.valueParameters, propagated.typeParameters, propagated.hasStableParameterNames(), propagated.errors ) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt index 0e4c5b27e23..2b2439a73be 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaPackageScope.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.incremental.components.LookupLocation -import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.load.java.JavaClassFinder import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext import org.jetbrains.kotlin.load.java.structure.JavaClass @@ -69,9 +68,7 @@ class LazyJavaPackageScope( // It happens because KotlinClassFinder searches through a file-based index that does not differ classes containing $-sign and nested ones if (classId != null && (classId.isNestedClass || classId.isLocal)) return@classByRequest null - val kotlinResult = resolveKotlinBinaryClass(kotlinBinaryClass) - - when (kotlinResult) { + when (val kotlinResult = resolveKotlinBinaryClass(kotlinBinaryClass)) { is KotlinClassLookupResult.Found -> kotlinResult.descriptor is KotlinClassLookupResult.SyntheticClass -> null is KotlinClassLookupResult.NotFound -> { @@ -176,7 +173,5 @@ class LazyJavaPackageScope( override fun getContributedDescriptors( kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean - ): Collection { - return computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) - } + ): Collection = computeDescriptors(kindFilter, nameFilter) } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt index 5cac43a3822..f304249366d 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaScope.kt @@ -60,7 +60,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS // this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there // but is placed in the base class to not duplicate code private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue>( - { computeDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) }, + { computeDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER) }, // This is to avoid the following recursive case: // when computing getAllPackageNames() we ask the JavaPsiFacade for all subpackages of foo // it, in turn, asks JavaElementFinder for subpackages of Kotlin package foo, which calls getAllPackageNames() recursively @@ -97,7 +97,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS c.components.signatureEnhancement.enhanceSignatures(c, result).toList() } - open protected fun JavaMethodDescriptor.isVisibleAsFunction() = true + protected open fun JavaMethodDescriptor.isVisibleAsFunction() = true protected data class MethodSignatureData( val returnType: KotlinType, @@ -321,9 +321,9 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS protected fun computeDescriptors( kindFilter: DescriptorKindFilter, - nameFilter: (Name) -> Boolean, - location: LookupLocation + nameFilter: (Name) -> Boolean ): List { + val location = NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS val result = LinkedHashSet() if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) { diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt index 9682e35e81b..1b43120aeea 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/descriptors/LazyJavaStaticScope.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext @@ -25,13 +26,13 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.KotlinType abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) { - override fun getDispatchReceiverParameter() = null + override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = null override fun resolveMethodSignature( method: JavaMethod, methodTypeParameters: List, returnType: KotlinType, valueParameters: List ): MethodSignatureData = - LazyJavaScope.MethodSignatureData(returnType, null, valueParameters, methodTypeParameters, false, emptyList()) + MethodSignatureData(returnType, null, valueParameters, methodTypeParameters, false, emptyList()) override fun computeNonDeclaredProperties(name: Name, result: MutableCollection) { //no undeclared properties diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt index 020117dac5d..2996c2500b3 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt @@ -54,7 +54,7 @@ class JavaTypeResolver( // Top level type can be a wildcard only in case of broken Java code, but we should not fail with exceptions in such cases is JavaWildcardType -> javaType.bound?.let { transformJavaType(it, attr) } ?: c.module.builtIns.defaultBound null -> c.module.builtIns.defaultBound - else -> throw UnsupportedOperationException("Unsupported type: " + javaType) + else -> throw UnsupportedOperationException("Unsupported type: $javaType") } } @@ -199,7 +199,7 @@ class JavaTypeResolver( // This option is needed because sometimes we get weird versions of JDK classes in the class path, // such as collections with no generics, so the Java types are not raw, formally, but they don't match with // their Kotlin analogs, so we treat them as raw to avoid exceptions - (javaType.typeArguments.isEmpty() && !constructor.parameters.isEmpty()) + (javaType.typeArguments.isEmpty() && constructor.parameters.isNotEmpty()) val typeParameters = constructor.parameters if (eraseTypeParameters) { @@ -279,7 +279,7 @@ class JavaTypeResolver( private fun JavaTypeAttributes.isNullable(): Boolean { if (flexibility == FLEXIBLE_LOWER_BOUND) return false - // even if flexibility is FLEXIBLE_UPPER_BOUND it's still can be not nullable for supetypes and annotation parameters + // even if flexibility is FLEXIBLE_UPPER_BOUND it's still can be not nullable for supertypes and annotation parameters return !isForAnnotationParameter && howThisTypeIsUsed != SUPERTYPE } } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt index 572b1e5a577..c5035f5839b 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/propertiesConventionUtil.kt @@ -16,9 +16,8 @@ package org.jetbrains.kotlin.load.java -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getPropertyNameCandidatesBySpecialGetterName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmartForCompiler fun propertyNameByGetMethodName(methodName: Name): Name? = @@ -28,7 +27,7 @@ fun propertyNameBySetMethodName(methodName: Name, withIsPrefix: Boolean): Name? propertyNameFromAccessorMethodName(methodName, "set", addPrefix = if (withIsPrefix) "is" else null) fun propertyNamesBySetMethodName(methodName: Name) = - listOf(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)).filterNotNull() + listOfNotNull(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)) private fun propertyNameFromAccessorMethodName( methodName: Name, diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt index 3c9d0b95370..18fb995c307 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/specialBuiltinMembers.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecialPropertyGetterName -import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents import org.jetbrains.kotlin.load.kotlin.computeJvmSignature @@ -201,7 +200,7 @@ object BuiltinMethodsWithSpecialGenericSignature { if (builtinSignature in ERASED_COLLECTION_PARAMETER_SIGNATURES) return SpecialSignatureInfo.ONE_COLLECTION_PARAMETER - val defaultValue = SIGNATURE_TO_DEFAULT_VALUES_MAP[builtinSignature]!! + val defaultValue = SIGNATURE_TO_DEFAULT_VALUES_MAP.getValue(builtinSignature) return if (defaultValue == TypeSafeBarrierDescription.NULL) // return type is some generic type as 'Map.get' diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/predefinedEnhancementInfo.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/predefinedEnhancementInfo.kt index bf658025d3f..b31e4a663e1 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/predefinedEnhancementInfo.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/predefinedEnhancementInfo.kt @@ -37,6 +37,7 @@ private val NOT_PLATFORM = JavaTypeQualifiers(NullabilityQualifier.NOT_NULL, nul /** Type is always non-nullable: `T & Any` */ private val NOT_NULLABLE = JavaTypeQualifiers(NullabilityQualifier.NOT_NULL, null, isNotNullTypeParameter = true) +@Suppress("LocalVariableName") val PREDEFINED_FUNCTION_ENHANCEMENT_INFO_BY_SIGNATURE = signatures { val JLObject = javaLang("Object") val JFPredicate = javaFunction("Predicate") @@ -250,5 +251,3 @@ private class SignatureEnhancementBuilder { fun build(): Map = signatures } - - diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt index 38cd88dded6..197f2461af3 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/typeEnhancement.kt @@ -122,11 +122,11 @@ private fun SimpleType.enhanceInflexible( val subtreeSize = globalArgIndex - index if (!wereChanges) return SimpleResult(this, subtreeSize, wereChanges = false) - val newAnnotations = listOf( + val newAnnotations = listOfNotNull( annotations, enhancedMutabilityAnnotations, enhancedNullabilityAnnotations - ).filterNotNull().compositeAnnotationsOrSingle() + ).compositeAnnotationsOrSingle() val enhancedType = KotlinTypeFactory.simpleType( newAnnotations, diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt index 9c81b26084a..42f8997bc56 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt @@ -327,7 +327,7 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader( val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(signature, index) var result = memberAnnotations[paramSignature] if (result == null) { - result = ArrayList() + result = ArrayList() memberAnnotations[paramSignature] = result } return loadAnnotationIfNotSpecial(classId, source, result) @@ -380,16 +380,16 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader( kind: AnnotatedCallableKind, requireHasFieldFlagForField: Boolean = false ): MemberSignature? { - return when { - proto is ProtoBuf.Constructor -> { + return when (proto) { + is ProtoBuf.Constructor -> { MemberSignature.fromJvmMemberSignature( JvmProtoBufUtil.getJvmConstructorSignature(proto, nameResolver, typeTable) ?: return null ) } - proto is ProtoBuf.Function -> { + is ProtoBuf.Function -> { MemberSignature.fromJvmMemberSignature(JvmProtoBufUtil.getJvmMethodSignature(proto, nameResolver, typeTable) ?: return null) } - proto is ProtoBuf.Property -> { + is ProtoBuf.Property -> { val signature = proto.getExtensionOrNull(propertySignature) ?: return null when (kind) { AnnotatedCallableKind.PROPERTY_GETTER -> diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt index 7a45b1097cd..a160db964bb 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt @@ -96,7 +96,7 @@ class BinaryClassAnnotationAndConstantLoaderImpl( } override fun visitArray(name: Name): AnnotationArrayArgumentVisitor? { - return object : KotlinJvmBinaryClass.AnnotationArrayArgumentVisitor { + return object : AnnotationArrayArgumentVisitor { private val elements = ArrayList>() override fun visit(value: Any?) { diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.kt index 894b8ad225b..eb3a5ba5377 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/DeserializedDescriptorResolver.kt @@ -94,15 +94,15 @@ class DeserializedDescriptorResolver { get() = !components.configuration.skipMetadataVersionCheck && classHeader.isPreRelease && classHeader.metadataVersion == KOTLIN_1_3_M1_METADATA_VERSION - internal fun readData(kotlinClass: KotlinJvmBinaryClass, expectedKinds: Set): Array? { + private fun readData(kotlinClass: KotlinJvmBinaryClass, expectedKinds: Set): Array? { val header = kotlinClass.classHeader return (header.data ?: header.incompatibleData)?.takeIf { header.kind in expectedKinds } } - private inline fun parseProto(klass: KotlinJvmBinaryClass, block: () -> T): T? { + private inline fun parseProto(klass: KotlinJvmBinaryClass, block: () -> T): T? = try { try { - return block() + block() } catch (e: InvalidProtocolBufferException) { throw IllegalStateException("Could not read data from ${klass.location}", e) } @@ -112,9 +112,8 @@ class DeserializedDescriptorResolver { } // TODO: log.warn - return null + null } - } companion object { internal val KOTLIN_CLASS = setOf(KotlinClassHeader.Kind.CLASS) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt index 8817bfef43f..055be90383f 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMemberSignature // The purpose of this class is to hold a unique signature of either a method or a field, so that annotations on a member can be put // into a map indexed by these signatures +@Suppress("DataClassPrivateConstructor") data class MemberSignature private constructor(internal val signature: String) { companion object { @JvmStatic @@ -36,7 +37,7 @@ data class MemberSignature private constructor(internal val signature: String) { @JvmStatic fun fromFieldNameAndDesc(name: String, desc: String): MemberSignature { - return MemberSignature(name + "#" + desc) + return MemberSignature("$name#$desc") } @JvmStatic @@ -47,7 +48,7 @@ data class MemberSignature private constructor(internal val signature: String) { @JvmStatic fun fromMethodSignatureAndParameterIndex(signature: MemberSignature, index: Int): MemberSignature { - return MemberSignature(signature.signature + "@" + index) + return MemberSignature("${signature.signature}@$index") } } } diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt index fcd664af7c9..90d138276ce 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt @@ -23,13 +23,13 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmBytecodeBinaryVersio import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion class KotlinClassHeader( - val kind: KotlinClassHeader.Kind, + val kind: Kind, val metadataVersion: JvmMetadataVersion, val bytecodeVersion: JvmBytecodeBinaryVersion, val data: Array?, val incompatibleData: Array?, val strings: Array?, - val extraString: String?, + private val extraString: String?, val extraInt: Int, val packageName: String? ) { @@ -62,6 +62,7 @@ class KotlinClassHeader( get() = data.takeIf { kind == Kind.MULTIFILE_CLASS }?.asList().orEmpty() // TODO: use in incremental compilation + @Suppress("unused") val multifileClassKind: MultifileClassKind? get() = if (kind == Kind.MULTIFILE_CLASS || kind == Kind.MULTIFILE_CLASS_PART) { if ((extraInt and JvmAnnotationNames.METADATA_MULTIFILE_PARTS_INHERIT_FLAG) != 0) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java index 96167db0d8d..3cb3c74b6db 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java @@ -318,7 +318,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor @Override public void visitEnd() { //noinspection SSBasedInspection - visitEnd(strings.toArray(new String[strings.size()])); + visitEnd(strings.toArray(new String[0])); } protected abstract void visitEnd(@NotNull String[] data); diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureBuilding.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureBuilding.kt index 1b2d0cbd364..8e865688c74 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureBuilding.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureBuilding.kt @@ -32,14 +32,11 @@ object SignatureBuildingComponents { fun inJavaLang(name: String, vararg signatures: String) = inClass(javaLang(name), *signatures) fun inJavaUtil(name: String, vararg signatures: String) = inClass(javaUtil(name), *signatures) - fun inClass(internalName: String, vararg signatures: String) = signatures.mapTo(LinkedHashSet()) { internalName + "." + it } + fun inClass(internalName: String, vararg signatures: String) = signatures.mapTo(LinkedHashSet()) { "$internalName.$it" } fun signature(classDescriptor: ClassDescriptor, jvmDescriptor: String) = signature(classDescriptor.internalName, jvmDescriptor) fun signature(classId: ClassId, jvmDescriptor: String) = signature(classId.internalName, jvmDescriptor) - fun signature(internalName: String, jvmDescriptor: String) = internalName + "." + jvmDescriptor - - fun jvmDescriptor(name: String, vararg parameters: String, ret: String = "V") = - jvmDescriptor(name, parameters.asList(), ret) + fun signature(internalName: String, jvmDescriptor: String) = "$internalName.$jvmDescriptor" fun jvmDescriptor(name: String, parameters: List, ret: String = "V") = "$name(${parameters.joinToString("") { escapeClassName(it) }})${escapeClassName(internalName = ret)}" diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureMapping.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureMapping.kt index 224c0ae34fb..cbe780bc1bf 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureMapping.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/methodSignatureMapping.kt @@ -119,7 +119,7 @@ private object JvmTypeFactoryImpl : JvmTypeFactory { } override fun createFromString(representation: String): JvmType { - assert(representation.length > 0) { "empty string as JvmType" } + assert(representation.isNotEmpty()) { "empty string as JvmType" } val firstChar = representation[0] JvmPrimitiveType.values().firstOrNull { it.desc[0] == firstChar }?.let { @@ -158,7 +158,7 @@ internal object TypeMappingConfigurationImpl : TypeMappingConfiguration throw AssertionError("There should be no intersection type in existing descriptors, but found: " + types.joinToString()) } - override fun getPredefinedTypeForClass(classDescriptor: ClassDescriptor) = null + override fun getPredefinedTypeForClass(classDescriptor: ClassDescriptor): JvmType? = null override fun getPredefinedInternalNameForClass(classDescriptor: ClassDescriptor): String? = null override fun processErrorType(kotlinType: KotlinType, descriptor: ClassDescriptor) { diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt index 24eaa058094..de0674630b8 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/typeSignatureMapping.kt @@ -280,7 +280,7 @@ internal fun computeExpandedTypeInner(kotlinType: KotlinType, visitedClassifiers } classifier is ClassDescriptor && classifier.isInline -> { - val inlineClassBoxType = kotlinType + // kotlinType is the boxed inline class type val underlyingType = kotlinType.substitutedUnderlyingType() ?: return null val expandedUnderlyingType = computeExpandedTypeInner(underlyingType, visitedClassifiers) ?: return null @@ -290,10 +290,10 @@ internal fun computeExpandedTypeInner(kotlinType: KotlinType, visitedClassifiers // Here inline class type is nullable. Apply nullability to the expandedUnderlyingType. // Nullable types become inline class boxes - expandedUnderlyingType.isNullable() -> inlineClassBoxType + expandedUnderlyingType.isNullable() -> kotlinType // Primitives become inline class boxes - KotlinBuiltIns.isPrimitiveType(expandedUnderlyingType) -> inlineClassBoxType + KotlinBuiltIns.isPrimitiveType(expandedUnderlyingType) -> kotlinType // Non-null reference types become nullable reference types else -> expandedUnderlyingType.makeNullable() diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectJavaClassFinder.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectJavaClassFinder.kt index 6857f5fcb44..28a5ab6ac33 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectJavaClassFinder.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectJavaClassFinder.kt @@ -19,7 +19,6 @@ package kotlin.reflect.jvm.internal.components import org.jetbrains.kotlin.load.java.JavaClassFinder import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.load.java.structure.JavaPackage -import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import kotlin.reflect.jvm.internal.structure.ReflectJavaClass import kotlin.reflect.jvm.internal.structure.ReflectJavaPackage diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectKotlinClass.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectKotlinClass.kt index 8deebf9a05d..201543115d0 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectKotlinClass.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/components/ReflectKotlinClass.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor import org.jetbrains.kotlin.name.ClassId -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType @@ -234,17 +233,17 @@ private object ReflectClassStructure { clazz.isArray -> { val v = visitor.visitArray(name) ?: return val componentType = clazz.componentType - if (componentType.isEnum) { - val enumClassId = componentType.classId - for (element in value as Array<*>) { - v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name)) + when { + componentType.isEnum -> { + val enumClassId = componentType.classId + for (element in value as Array<*>) { + v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name)) + } } - } else if (componentType == Class::class.java) { - for (element in value as Array<*>) { + componentType == Class::class.java -> for (element in value as Array<*>) { v.visitClassLiteral((element as Class<*>).classLiteralValue()) } - } else { - for (element in value as Array<*>) { + else -> for (element in value as Array<*>) { v.visit(element) } } diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaAnnotationArguments.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaAnnotationArguments.kt index 579594a24ba..579e6fb635b 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaAnnotationArguments.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaAnnotationArguments.kt @@ -45,7 +45,7 @@ class ReflectJavaArrayAnnotationArgument( name: Name?, private val values: Array<*> ) : ReflectJavaAnnotationArgument(name), JavaArrayAnnotationArgument { - override fun getElements() = values.map { ReflectJavaAnnotationArgument.create(it!!, null) } + override fun getElements() = values.map { create(it!!, null) } } class ReflectJavaEnumValueAnnotationArgument( diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaArrayType.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaArrayType.kt index 45f747226ed..19f8c5dffe1 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaArrayType.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaArrayType.kt @@ -23,8 +23,8 @@ import java.lang.reflect.Type class ReflectJavaArrayType(override val reflectType: Type) : ReflectJavaType(), JavaArrayType { override val componentType: ReflectJavaType = with(reflectType) { when { - this is GenericArrayType -> ReflectJavaType.create(genericComponentType) - this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType()) + this is GenericArrayType -> create(genericComponentType) + this is Class<*> && isArray() -> create(getComponentType()) else -> throw IllegalArgumentException("Not an array type (${reflectType::class.java}): $reflectType") } } diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClass.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClass.kt index 11cf16e7b44..c06cfe0b178 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClass.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClass.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaClassifierType import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import java.lang.reflect.Member import java.lang.reflect.Method import java.util.* @@ -84,14 +85,14 @@ class ReflectJavaClass( override val fields: List get() = klass.declaredFields .asSequence() - .filter { field -> !field.isSynthetic } + .filterNot(Member::isSynthetic) .map(::ReflectJavaField) .toList() override val constructors: List get() = klass.declaredConstructors .asSequence() - .filter { constructor -> !constructor.isSynthetic } + .filterNot(Member::isSynthetic) .map(::ReflectJavaConstructor) .toList() diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClassifierType.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClassifierType.kt index 1e86c9cacf6..142a23baf17 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClassifierType.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaClassifierType.kt @@ -47,7 +47,7 @@ class ReflectJavaClassifierType(public override val reflectType: Type) : Reflect get() = with(reflectType) { this is Class<*> && getTypeParameters().isNotEmpty() } override val typeArguments: List - get() = reflectType.parameterizedTypeArguments.map(ReflectJavaType.Factory::create) + get() = reflectType.parameterizedTypeArguments.map(Factory::create) override val annotations: Collection get() { diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaField.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaField.kt index 2f9dfbba37d..0f98496a685 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaField.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaField.kt @@ -26,6 +26,6 @@ class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaFi override val type: ReflectJavaType get() = ReflectJavaType.create(member.genericType) - override val initializerValue get() = null + override val initializerValue: Any? get() = null override val hasConstantNotNullInitializer get() = false } diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaModifierListOwner.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaModifierListOwner.kt index 094f045780d..09cb689463f 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaModifierListOwner.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaModifierListOwner.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaModifierListOwner import java.lang.reflect.Modifier interface ReflectJavaModifierListOwner : JavaModifierListOwner { - /* protected // KT-3029 */ val modifiers: Int + val modifiers: Int override val isAbstract: Boolean get() = Modifier.isAbstract(modifiers) diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaPackage.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaPackage.kt index d79d890cbec..59aa32e8287 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaPackage.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaPackage.kt @@ -37,7 +37,7 @@ class ReflectJavaPackage(override val fqName: FqName) : ReflectJavaElement(), Ja // TODO: support it if possible override val annotations get() = emptyList() - override fun findAnnotation(fqName: FqName) = null + override fun findAnnotation(fqName: FqName): JavaAnnotation? = null override val isDeprecatedInJavaDoc: Boolean get() = false diff --git a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaWildcardType.kt b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaWildcardType.kt index 0be3ff6ed8e..f97f21ecd47 100644 --- a/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaWildcardType.kt +++ b/core/descriptors.runtime/src/kotlin/reflect/jvm/internal/structure/ReflectJavaWildcardType.kt @@ -28,8 +28,8 @@ class ReflectJavaWildcardType(override val reflectType: WildcardType) : ReflectJ throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $reflectType") } return when { - lowerBounds.size == 1 -> ReflectJavaType.create(lowerBounds.single()) - upperBounds.size == 1 -> upperBounds.single().let { ub -> if (ub != Any::class.java) ReflectJavaType.create(ub) else null } + lowerBounds.size == 1 -> create(lowerBounds.single()) + upperBounds.size == 1 -> upperBounds.single().let { ub -> if (ub != Any::class.java) create(ub) else null } else -> null } } diff --git a/core/descriptors.runtime/tests/org/jetbrains/kotlin/generators/tests/GenerateRuntimeDescriptorTests.kt b/core/descriptors.runtime/tests/org/jetbrains/kotlin/generators/tests/GenerateRuntimeDescriptorTests.kt index 4036fc3da31..e8324406994 100644 --- a/core/descriptors.runtime/tests/org/jetbrains/kotlin/generators/tests/GenerateRuntimeDescriptorTests.kt +++ b/core/descriptors.runtime/tests/org/jetbrains/kotlin/generators/tests/GenerateRuntimeDescriptorTests.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.generators.tests.generator.testGroup import org.jetbrains.kotlin.jvm.runtime.AbstractJvm8RuntimeDescriptorLoaderTest import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest -fun main(args: Array) { +fun main() { System.setProperty("java.awt.headless", "true") testGroup("core/descriptors.runtime/tests", "compiler/testData") { diff --git a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt index d65d774ecc8..1881b01f003 100644 --- a/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt +++ b/core/descriptors.runtime/tests/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt @@ -127,7 +127,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { myTestRootDisposable, ConfigurationKind.ALL, jdkKind ) for (root in environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS)) { - LOG.info("root: " + root.toString()) + LOG.info("root: $root") } val ktFile = KotlinTestUtils.createFile(file.path, text, environment.project) GenerationUtils.compileFileTo(ktFile, environment, tmpdir) @@ -176,7 +176,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { private fun adaptJavaSource(text: String): String { val typeAnnotations = arrayOf("NotNull", "Nullable", "ReadOnly", "Mutable") - val adaptedSource = typeAnnotations.fold(text) { text, annotation -> text.replace("@$annotation", "") } + val adaptedSource = typeAnnotations.fold(text) { result, annotation -> result.replace("@$annotation", "") } if ("@Retention" !in adaptedSource) { return adaptedSource.replace( "@interface", @@ -213,7 +213,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R = visitor.visitPackageViewDescriptor(this, data) - override fun getContainingDeclaration() = null + override fun getContainingDeclaration(): PackageViewDescriptor? = null override fun getOriginal() = throw UnsupportedOperationException() override fun acceptVoid(visitor: DeclarationDescriptorVisitor?) = throw UnsupportedOperationException() override fun getName() = throw UnsupportedOperationException()