Cleanup modules descriptors.jvm, descriptors.runtime

Fix warnings and inspections
This commit is contained in:
Alexander Udalov
2019-03-15 15:38:30 +01:00
parent b89d7029b2
commit 29d32b213e
39 changed files with 93 additions and 105 deletions
@@ -170,8 +170,8 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap {
val readOnlyFqName = readOnlyClassId.asSingleFqName() val readOnlyFqName = readOnlyClassId.asSingleFqName()
val mutableFqName = mutableClassId.asSingleFqName() val mutableFqName = mutableClassId.asSingleFqName()
mutableToReadOnly.put(mutableClassId.asSingleFqName().toUnsafe(), readOnlyFqName) mutableToReadOnly[mutableClassId.asSingleFqName().toUnsafe()] = readOnlyFqName
readOnlyToMutable.put(readOnlyFqName.toUnsafe(), mutableFqName) readOnlyToMutable[readOnlyFqName.toUnsafe()] = mutableFqName
} }
private fun add(javaClassId: ClassId, kotlinClassId: ClassId) { private fun add(javaClassId: ClassId, kotlinClassId: ClassId) {
@@ -188,11 +188,11 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap {
} }
private fun addJavaToKotlin(javaClassId: ClassId, kotlinClassId: ClassId) { 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) { private fun addKotlinToJava(kotlinFqNameUnsafe: FqName, javaClassId: ClassId) {
kotlinToJava.put(kotlinFqNameUnsafe.toUnsafe(), javaClassId) kotlinToJava[kotlinFqNameUnsafe.toUnsafe()] = javaClassId
} }
fun isJavaPlatformClass(fqName: FqName): Boolean = mapJavaToKotlin(fqName) != null fun isJavaPlatformClass(fqName: FqName): Boolean = mapJavaToKotlin(fqName) != null
@@ -210,7 +210,7 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap {
return if (className.isSafe) return if (className.isSafe)
mapPlatformClass(className.toSafe(), classDescriptor.builtIns) mapPlatformClass(className.toSafe(), classDescriptor.builtIns)
else else
emptySet<ClassDescriptor>() emptySet()
} }
fun mutableToReadOnly(fqNameUnsafe: FqNameUnsafe?): FqName? = mutableToReadOnly[fqNameUnsafe] fun mutableToReadOnly(fqNameUnsafe: FqNameUnsafe?): FqName? = mutableToReadOnly[fqNameUnsafe]
@@ -244,7 +244,7 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap {
} }
private fun classId(clazz: Class<*>): ClassId { 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 val outer = clazz.declaringClass
return if (outer == null) return if (outer == null)
ClassId.topLevel(FqName(clazz.canonicalName)) ClassId.topLevel(FqName(clazz.canonicalName))
@@ -24,7 +24,7 @@ object FakePureImplementationsProvider {
private val pureImplementations = hashMapOf<FqName, FqName>() private val pureImplementations = hashMapOf<FqName, FqName>()
private infix fun FqName.implementedWith(implementations: List<FqName>) { private infix fun FqName.implementedWith(implementations: List<FqName>) {
implementations.associateTo(pureImplementations) { it to this } implementations.associateWithTo(pureImplementations) { this }
} }
init { init {
@@ -40,4 +40,3 @@ object FakePureImplementationsProvider {
private fun fqNameListOf(vararg names: String): List<FqName> = names.map(::FqName) private fun fqNameListOf(vararg names: String): List<FqName> = names.map(::FqName)
} }
@@ -95,7 +95,7 @@ class JavaIncompatibilityRulesOverridabilityCondition : ExternalOverridabilityCo
// void get(Object x) {} // 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. // 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. // 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 // Note that it doesn't work if special builtIn was renamed, because we do not consider renamed built-ins
@@ -26,7 +26,6 @@ public final class JvmAbi {
* This is false for KAPT3 mode. * This is false for KAPT3 mode.
*/ */
public static final String DEFAULT_IMPLS_SUFFIX = "$" + DEFAULT_IMPLS_CLASS_NAME; 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"; public static final String DEFAULT_PARAMS_IMPL_SUFFIX = "$default";
@@ -20,7 +20,10 @@ import kotlin.Unit;
import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; 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.load.java.structure.*;
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.name.Name;
@@ -119,18 +122,18 @@ public final class DescriptorResolverUtils {
return member.getContainingClass().isInterface() && member instanceof JavaMethod && isObjectMethod((JavaMethod) member); 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(); String name = method.getName().asString();
if (name.equals("toString") || name.equals("hashCode")) { if (name.equals("toString") || name.equals("hashCode")) {
return method.getValueParameters().isEmpty(); return method.getValueParameters().isEmpty();
} }
else if (name.equals("equals")) { else if (name.equals("equals")) {
return isMethodWithOneParameterWithFqName(method, "java.lang.Object"); return isMethodWithOneObjectParameter(method);
} }
return false; return false;
} }
private static boolean isMethodWithOneParameterWithFqName(@NotNull JavaMethod method, @NotNull String fqName) { private static boolean isMethodWithOneObjectParameter(@NotNull JavaMethod method) {
List<JavaValueParameter> parameters = method.getValueParameters(); List<JavaValueParameter> parameters = method.getValueParameters();
if (parameters.size() == 1) { if (parameters.size() == 1) {
JavaType type = parameters.get(0).getType(); JavaType type = parameters.get(0).getType();
@@ -138,7 +141,7 @@ public final class DescriptorResolverUtils {
JavaClassifier classifier = ((JavaClassifierType) type).getClassifier(); JavaClassifier classifier = ((JavaClassifierType) type).getClassifier();
if (classifier instanceof JavaClass) { if (classifier instanceof JavaClass) {
FqName classFqName = ((JavaClass) classifier).getFqName(); FqName classFqName = ((JavaClass) classifier).getFqName();
return classFqName != null && classFqName.asString().equals(fqName); return classFqName != null && classFqName.asString().equals("java.lang.Object");
} }
} }
} }
@@ -73,9 +73,9 @@ object JavaAnnotationMapper {
return JavaDeprecatedAnnotationDescriptor(javaAnnotation, c) return JavaDeprecatedAnnotationDescriptor(javaAnnotation, c)
} }
} }
return kotlinToJavaNameMap[kotlinName]?.let { return kotlinToJavaNameMap[kotlinName]?.let { javaName ->
annotationOwner.findAnnotation(it)?.let { annotationOwner.findAnnotation(javaName)?.let { annotation ->
mapOrResolveJavaAnnotation(it, c) mapOrResolveJavaAnnotation(annotation, c)
} }
} }
} }
@@ -24,6 +24,6 @@ interface JavaPropertyInitializerEvaluator {
fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>? fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>?
object DoNothing : JavaPropertyInitializerEvaluator { object DoNothing : JavaPropertyInitializerEvaluator {
override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor) = null override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>? = null
} }
} }
@@ -64,11 +64,7 @@ fun copyValueParameters(
fun ClassDescriptor.getParentJavaStaticClassScope(): LazyJavaStaticClassScope? { fun ClassDescriptor.getParentJavaStaticClassScope(): LazyJavaStaticClassScope? {
val superClassDescriptor = getSuperClassNotAny() ?: return null val superClassDescriptor = getSuperClassNotAny() ?: return null
val staticScope = superClassDescriptor.staticScope return superClassDescriptor.staticScope as? LazyJavaStaticClassScope ?: superClassDescriptor.getParentJavaStaticClassScope()
if (staticScope !is LazyJavaStaticClassScope) return superClassDescriptor.getParentJavaStaticClassScope()
return staticScope
} }
fun DeserializedMemberDescriptor.getImplClassNameForDeserialized(): JvmClassName? = fun DeserializedMemberDescriptor.getImplClassNameForDeserialized(): JvmClassName? =
@@ -25,7 +25,7 @@ interface ModuleClassResolver {
fun resolveClass(javaClass: JavaClass): ClassDescriptor? fun resolveClass(javaClass: JavaClass): ClassDescriptor?
} }
class SingleModuleClassResolver() : ModuleClassResolver { class SingleModuleClassResolver : ModuleClassResolver {
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? = resolver.resolveClass(javaClass) override fun resolveClass(javaClass: JavaClass): ClassDescriptor? = resolver.resolveClass(javaClass)
// component dependency cycle // component dependency cycle
@@ -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.JavaConstructor
import org.jetbrains.kotlin.load.java.structure.JavaMethod import org.jetbrains.kotlin.load.java.structure.JavaMethod
import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorFactory import org.jetbrains.kotlin.resolve.DescriptorFactory
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -68,7 +69,7 @@ class LazyJavaClassMemberScope(
private val jClass: JavaClass private val jClass: JavaClass
) : LazyJavaScope(c) { ) : LazyJavaScope(c) {
override fun computeMemberIndex() = ClassDeclaredMemberIndex(jClass, { !it.isStatic }) override fun computeMemberIndex() = ClassDeclaredMemberIndex(jClass) { !it.isStatic }
override fun computeFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?) = override fun computeFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?) =
ownerDescriptor.typeConstructor.supertypes.flatMapTo(hashSetOf()) { ownerDescriptor.typeConstructor.supertypes.flatMapTo(hashSetOf()) {
@@ -170,7 +171,7 @@ class LazyJavaClassMemberScope(
private fun SimpleFunctionDescriptor.createSuspendView(): SimpleFunctionDescriptor? { private fun SimpleFunctionDescriptor.createSuspendView(): SimpleFunctionDescriptor? {
val continuationParameter = valueParameters.lastOrNull()?.takeIf { val continuationParameter = valueParameters.lastOrNull()?.takeIf {
isContinuation( isContinuation(
it.type.constructor.declarationDescriptor?.fqNameUnsafe?.takeIf { it.isSafe }?.toSafe(), it.type.constructor.declarationDescriptor?.fqNameUnsafe?.takeIf(FqNameUnsafe::isSafe)?.toSafe(),
c.components.settings.isReleaseCoroutines c.components.settings.isReleaseCoroutines
) )
} ?: return null } ?: return null
@@ -551,11 +552,11 @@ class LazyJavaClassMemberScope(
override fun resolveMethodSignature( override fun resolveMethodSignature(
method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: KotlinType, method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: KotlinType,
valueParameters: List<ValueParameterDescriptor> valueParameters: List<ValueParameterDescriptor>
): LazyJavaScope.MethodSignatureData { ): MethodSignatureData {
val propagated = c.components.signaturePropagator.resolvePropagatedSignature( val propagated = c.components.signaturePropagator.resolvePropagatedSignature(
method, ownerDescriptor, returnType, null, valueParameters, methodTypeParameters method, ownerDescriptor, returnType, null, valueParameters, methodTypeParameters
) )
return LazyJavaScope.MethodSignatureData( return MethodSignatureData(
propagated.returnType, propagated.receiverType, propagated.valueParameters, propagated.typeParameters, propagated.returnType, propagated.receiverType, propagated.valueParameters, propagated.typeParameters,
propagated.hasStableParameterNames(), propagated.errors propagated.hasStableParameterNames(), propagated.errors
) )
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation 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.JavaClassFinder
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.structure.JavaClass 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 // 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 if (classId != null && (classId.isNestedClass || classId.isLocal)) return@classByRequest null
val kotlinResult = resolveKotlinBinaryClass(kotlinBinaryClass) when (val kotlinResult = resolveKotlinBinaryClass(kotlinBinaryClass)) {
when (kotlinResult) {
is KotlinClassLookupResult.Found -> kotlinResult.descriptor is KotlinClassLookupResult.Found -> kotlinResult.descriptor
is KotlinClassLookupResult.SyntheticClass -> null is KotlinClassLookupResult.SyntheticClass -> null
is KotlinClassLookupResult.NotFound -> { is KotlinClassLookupResult.NotFound -> {
@@ -176,7 +173,5 @@ class LazyJavaPackageScope(
override fun getContributedDescriptors( override fun getContributedDescriptors(
kindFilter: DescriptorKindFilter, kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean nameFilter: (Name) -> Boolean
): Collection<DeclarationDescriptor> { ): Collection<DeclarationDescriptor> = computeDescriptors(kindFilter, nameFilter)
return computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
}
} }
@@ -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 // 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 // but is placed in the base class to not duplicate code
private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue<Collection<DeclarationDescriptor>>( private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue<Collection<DeclarationDescriptor>>(
{ 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: // This is to avoid the following recursive case:
// when computing getAllPackageNames() we ask the JavaPsiFacade for all subpackages of foo // 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 // 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() c.components.signatureEnhancement.enhanceSignatures(c, result).toList()
} }
open protected fun JavaMethodDescriptor.isVisibleAsFunction() = true protected open fun JavaMethodDescriptor.isVisibleAsFunction() = true
protected data class MethodSignatureData( protected data class MethodSignatureData(
val returnType: KotlinType, val returnType: KotlinType,
@@ -321,9 +321,9 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
protected fun computeDescriptors( protected fun computeDescriptors(
kindFilter: DescriptorKindFilter, kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean, nameFilter: (Name) -> Boolean
location: LookupLocation
): List<DeclarationDescriptor> { ): List<DeclarationDescriptor> {
val location = NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS
val result = LinkedHashSet<DeclarationDescriptor>() val result = LinkedHashSet<DeclarationDescriptor>()
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) { if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.load.java.lazy.descriptors package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
@@ -25,13 +26,13 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) { abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) {
override fun getDispatchReceiverParameter() = null override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = null
override fun resolveMethodSignature( override fun resolveMethodSignature(
method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: KotlinType, method: JavaMethod, methodTypeParameters: List<TypeParameterDescriptor>, returnType: KotlinType,
valueParameters: List<ValueParameterDescriptor> valueParameters: List<ValueParameterDescriptor>
): MethodSignatureData = ): MethodSignatureData =
LazyJavaScope.MethodSignatureData(returnType, null, valueParameters, methodTypeParameters, false, emptyList()) MethodSignatureData(returnType, null, valueParameters, methodTypeParameters, false, emptyList())
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) { override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
//no undeclared properties //no undeclared properties
@@ -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 // 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 is JavaWildcardType -> javaType.bound?.let { transformJavaType(it, attr) } ?: c.module.builtIns.defaultBound
null -> 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, // 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 // 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 // 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 val typeParameters = constructor.parameters
if (eraseTypeParameters) { if (eraseTypeParameters) {
@@ -279,7 +279,7 @@ class JavaTypeResolver(
private fun JavaTypeAttributes.isNullable(): Boolean { private fun JavaTypeAttributes.isNullable(): Boolean {
if (flexibility == FLEXIBLE_LOWER_BOUND) return false 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 return !isForAnnotationParameter && howThisTypeIsUsed != SUPERTYPE
} }
} }
@@ -16,9 +16,8 @@
package org.jetbrains.kotlin.load.java 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.load.java.BuiltinSpecialProperties.getPropertyNameCandidatesBySpecialGetterName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmartForCompiler import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmartForCompiler
fun propertyNameByGetMethodName(methodName: Name): Name? = 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) propertyNameFromAccessorMethodName(methodName, "set", addPrefix = if (withIsPrefix) "is" else null)
fun propertyNamesBySetMethodName(methodName: Name) = fun propertyNamesBySetMethodName(methodName: Name) =
listOf(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)).filterNotNull() listOfNotNull(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true))
private fun propertyNameFromAccessorMethodName( private fun propertyNameFromAccessorMethodName(
methodName: Name, methodName: Name,
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters
import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecialPropertyGetterName 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.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents import org.jetbrains.kotlin.load.kotlin.SignatureBuildingComponents
import org.jetbrains.kotlin.load.kotlin.computeJvmSignature 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 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 if (defaultValue == TypeSafeBarrierDescription.NULL)
// return type is some generic type as 'Map.get' // return type is some generic type as 'Map.get'
@@ -37,6 +37,7 @@ private val NOT_PLATFORM = JavaTypeQualifiers(NullabilityQualifier.NOT_NULL, nul
/** Type is always non-nullable: `T & Any` */ /** Type is always non-nullable: `T & Any` */
private val NOT_NULLABLE = JavaTypeQualifiers(NullabilityQualifier.NOT_NULL, null, isNotNullTypeParameter = true) private val NOT_NULLABLE = JavaTypeQualifiers(NullabilityQualifier.NOT_NULL, null, isNotNullTypeParameter = true)
@Suppress("LocalVariableName")
val PREDEFINED_FUNCTION_ENHANCEMENT_INFO_BY_SIGNATURE = signatures { val PREDEFINED_FUNCTION_ENHANCEMENT_INFO_BY_SIGNATURE = signatures {
val JLObject = javaLang("Object") val JLObject = javaLang("Object")
val JFPredicate = javaFunction("Predicate") val JFPredicate = javaFunction("Predicate")
@@ -250,5 +251,3 @@ private class SignatureEnhancementBuilder {
fun build(): Map<String, PredefinedFunctionEnhancementInfo> = signatures fun build(): Map<String, PredefinedFunctionEnhancementInfo> = signatures
} }
@@ -122,11 +122,11 @@ private fun SimpleType.enhanceInflexible(
val subtreeSize = globalArgIndex - index val subtreeSize = globalArgIndex - index
if (!wereChanges) return SimpleResult(this, subtreeSize, wereChanges = false) if (!wereChanges) return SimpleResult(this, subtreeSize, wereChanges = false)
val newAnnotations = listOf( val newAnnotations = listOfNotNull(
annotations, annotations,
enhancedMutabilityAnnotations, enhancedMutabilityAnnotations,
enhancedNullabilityAnnotations enhancedNullabilityAnnotations
).filterNotNull().compositeAnnotationsOrSingle() ).compositeAnnotationsOrSingle()
val enhancedType = KotlinTypeFactory.simpleType( val enhancedType = KotlinTypeFactory.simpleType(
newAnnotations, newAnnotations,
@@ -327,7 +327,7 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any>(
val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(signature, index) val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(signature, index)
var result = memberAnnotations[paramSignature] var result = memberAnnotations[paramSignature]
if (result == null) { if (result == null) {
result = ArrayList<A>() result = ArrayList()
memberAnnotations[paramSignature] = result memberAnnotations[paramSignature] = result
} }
return loadAnnotationIfNotSpecial(classId, source, result) return loadAnnotationIfNotSpecial(classId, source, result)
@@ -380,16 +380,16 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any>(
kind: AnnotatedCallableKind, kind: AnnotatedCallableKind,
requireHasFieldFlagForField: Boolean = false requireHasFieldFlagForField: Boolean = false
): MemberSignature? { ): MemberSignature? {
return when { return when (proto) {
proto is ProtoBuf.Constructor -> { is ProtoBuf.Constructor -> {
MemberSignature.fromJvmMemberSignature( MemberSignature.fromJvmMemberSignature(
JvmProtoBufUtil.getJvmConstructorSignature(proto, nameResolver, typeTable) ?: return null JvmProtoBufUtil.getJvmConstructorSignature(proto, nameResolver, typeTable) ?: return null
) )
} }
proto is ProtoBuf.Function -> { is ProtoBuf.Function -> {
MemberSignature.fromJvmMemberSignature(JvmProtoBufUtil.getJvmMethodSignature(proto, nameResolver, typeTable) ?: return null) MemberSignature.fromJvmMemberSignature(JvmProtoBufUtil.getJvmMethodSignature(proto, nameResolver, typeTable) ?: return null)
} }
proto is ProtoBuf.Property -> { is ProtoBuf.Property -> {
val signature = proto.getExtensionOrNull(propertySignature) ?: return null val signature = proto.getExtensionOrNull(propertySignature) ?: return null
when (kind) { when (kind) {
AnnotatedCallableKind.PROPERTY_GETTER -> AnnotatedCallableKind.PROPERTY_GETTER ->
@@ -96,7 +96,7 @@ class BinaryClassAnnotationAndConstantLoaderImpl(
} }
override fun visitArray(name: Name): AnnotationArrayArgumentVisitor? { override fun visitArray(name: Name): AnnotationArrayArgumentVisitor? {
return object : KotlinJvmBinaryClass.AnnotationArrayArgumentVisitor { return object : AnnotationArrayArgumentVisitor {
private val elements = ArrayList<ConstantValue<*>>() private val elements = ArrayList<ConstantValue<*>>()
override fun visit(value: Any?) { override fun visit(value: Any?) {
@@ -94,15 +94,15 @@ class DeserializedDescriptorResolver {
get() = !components.configuration.skipMetadataVersionCheck && get() = !components.configuration.skipMetadataVersionCheck &&
classHeader.isPreRelease && classHeader.metadataVersion == KOTLIN_1_3_M1_METADATA_VERSION classHeader.isPreRelease && classHeader.metadataVersion == KOTLIN_1_3_M1_METADATA_VERSION
internal fun readData(kotlinClass: KotlinJvmBinaryClass, expectedKinds: Set<KotlinClassHeader.Kind>): Array<String>? { private fun readData(kotlinClass: KotlinJvmBinaryClass, expectedKinds: Set<KotlinClassHeader.Kind>): Array<String>? {
val header = kotlinClass.classHeader val header = kotlinClass.classHeader
return (header.data ?: header.incompatibleData)?.takeIf { header.kind in expectedKinds } return (header.data ?: header.incompatibleData)?.takeIf { header.kind in expectedKinds }
} }
private inline fun <T : Any> parseProto(klass: KotlinJvmBinaryClass, block: () -> T): T? { private inline fun <T : Any> parseProto(klass: KotlinJvmBinaryClass, block: () -> T): T? =
try { try {
try { try {
return block() block()
} catch (e: InvalidProtocolBufferException) { } catch (e: InvalidProtocolBufferException) {
throw IllegalStateException("Could not read data from ${klass.location}", e) throw IllegalStateException("Could not read data from ${klass.location}", e)
} }
@@ -112,9 +112,8 @@ class DeserializedDescriptorResolver {
} }
// TODO: log.warn // TODO: log.warn
return null null
} }
}
companion object { companion object {
internal val KOTLIN_CLASS = setOf(KotlinClassHeader.Kind.CLASS) internal val KOTLIN_CLASS = setOf(KotlinClassHeader.Kind.CLASS)
@@ -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 // 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 // into a map indexed by these signatures
@Suppress("DataClassPrivateConstructor")
data class MemberSignature private constructor(internal val signature: String) { data class MemberSignature private constructor(internal val signature: String) {
companion object { companion object {
@JvmStatic @JvmStatic
@@ -36,7 +37,7 @@ data class MemberSignature private constructor(internal val signature: String) {
@JvmStatic @JvmStatic
fun fromFieldNameAndDesc(name: String, desc: String): MemberSignature { fun fromFieldNameAndDesc(name: String, desc: String): MemberSignature {
return MemberSignature(name + "#" + desc) return MemberSignature("$name#$desc")
} }
@JvmStatic @JvmStatic
@@ -47,7 +48,7 @@ data class MemberSignature private constructor(internal val signature: String) {
@JvmStatic @JvmStatic
fun fromMethodSignatureAndParameterIndex(signature: MemberSignature, index: Int): MemberSignature { fun fromMethodSignatureAndParameterIndex(signature: MemberSignature, index: Int): MemberSignature {
return MemberSignature(signature.signature + "@" + index) return MemberSignature("${signature.signature}@$index")
} }
} }
} }
@@ -23,13 +23,13 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmBytecodeBinaryVersio
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
class KotlinClassHeader( class KotlinClassHeader(
val kind: KotlinClassHeader.Kind, val kind: Kind,
val metadataVersion: JvmMetadataVersion, val metadataVersion: JvmMetadataVersion,
val bytecodeVersion: JvmBytecodeBinaryVersion, val bytecodeVersion: JvmBytecodeBinaryVersion,
val data: Array<String>?, val data: Array<String>?,
val incompatibleData: Array<String>?, val incompatibleData: Array<String>?,
val strings: Array<String>?, val strings: Array<String>?,
val extraString: String?, private val extraString: String?,
val extraInt: Int, val extraInt: Int,
val packageName: String? val packageName: String?
) { ) {
@@ -62,6 +62,7 @@ class KotlinClassHeader(
get() = data.takeIf { kind == Kind.MULTIFILE_CLASS }?.asList().orEmpty() get() = data.takeIf { kind == Kind.MULTIFILE_CLASS }?.asList().orEmpty()
// TODO: use in incremental compilation // TODO: use in incremental compilation
@Suppress("unused")
val multifileClassKind: MultifileClassKind? val multifileClassKind: MultifileClassKind?
get() = if (kind == Kind.MULTIFILE_CLASS || kind == Kind.MULTIFILE_CLASS_PART) { get() = if (kind == Kind.MULTIFILE_CLASS || kind == Kind.MULTIFILE_CLASS_PART) {
if ((extraInt and JvmAnnotationNames.METADATA_MULTIFILE_PARTS_INHERIT_FLAG) != 0) if ((extraInt and JvmAnnotationNames.METADATA_MULTIFILE_PARTS_INHERIT_FLAG) != 0)
@@ -318,7 +318,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
@Override @Override
public void visitEnd() { public void visitEnd() {
//noinspection SSBasedInspection //noinspection SSBasedInspection
visitEnd(strings.toArray(new String[strings.size()])); visitEnd(strings.toArray(new String[0]));
} }
protected abstract void visitEnd(@NotNull String[] data); protected abstract void visitEnd(@NotNull String[] data);
@@ -32,14 +32,11 @@ object SignatureBuildingComponents {
fun inJavaLang(name: String, vararg signatures: String) = inClass(javaLang(name), *signatures) fun inJavaLang(name: String, vararg signatures: String) = inClass(javaLang(name), *signatures)
fun inJavaUtil(name: String, vararg signatures: String) = inClass(javaUtil(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(classDescriptor: ClassDescriptor, jvmDescriptor: String) = signature(classDescriptor.internalName, jvmDescriptor)
fun signature(classId: ClassId, jvmDescriptor: String) = signature(classId.internalName, jvmDescriptor) fun signature(classId: ClassId, jvmDescriptor: String) = signature(classId.internalName, jvmDescriptor)
fun signature(internalName: String, jvmDescriptor: String) = 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 jvmDescriptor(name: String, parameters: List<String>, ret: String = "V") = fun jvmDescriptor(name: String, parameters: List<String>, ret: String = "V") =
"$name(${parameters.joinToString("") { escapeClassName(it) }})${escapeClassName(internalName = ret)}" "$name(${parameters.joinToString("") { escapeClassName(it) }})${escapeClassName(internalName = ret)}"
@@ -119,7 +119,7 @@ private object JvmTypeFactoryImpl : JvmTypeFactory<JvmType> {
} }
override fun createFromString(representation: String): JvmType { 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] val firstChar = representation[0]
JvmPrimitiveType.values().firstOrNull { it.desc[0] == firstChar }?.let { JvmPrimitiveType.values().firstOrNull { it.desc[0] == firstChar }?.let {
@@ -158,7 +158,7 @@ internal object TypeMappingConfigurationImpl : TypeMappingConfiguration<JvmType>
throw AssertionError("There should be no intersection type in existing descriptors, but found: " + types.joinToString()) 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 getPredefinedInternalNameForClass(classDescriptor: ClassDescriptor): String? = null
override fun processErrorType(kotlinType: KotlinType, descriptor: ClassDescriptor) { override fun processErrorType(kotlinType: KotlinType, descriptor: ClassDescriptor) {
@@ -280,7 +280,7 @@ internal fun computeExpandedTypeInner(kotlinType: KotlinType, visitedClassifiers
} }
classifier is ClassDescriptor && classifier.isInline -> { classifier is ClassDescriptor && classifier.isInline -> {
val inlineClassBoxType = kotlinType // kotlinType is the boxed inline class type
val underlyingType = kotlinType.substitutedUnderlyingType() ?: return null val underlyingType = kotlinType.substitutedUnderlyingType() ?: return null
val expandedUnderlyingType = computeExpandedTypeInner(underlyingType, visitedClassifiers) ?: 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. // Here inline class type is nullable. Apply nullability to the expandedUnderlyingType.
// Nullable types become inline class boxes // Nullable types become inline class boxes
expandedUnderlyingType.isNullable() -> inlineClassBoxType expandedUnderlyingType.isNullable() -> kotlinType
// Primitives become inline class boxes // Primitives become inline class boxes
KotlinBuiltIns.isPrimitiveType(expandedUnderlyingType) -> inlineClassBoxType KotlinBuiltIns.isPrimitiveType(expandedUnderlyingType) -> kotlinType
// Non-null reference types become nullable reference types // Non-null reference types become nullable reference types
else -> expandedUnderlyingType.makeNullable() else -> expandedUnderlyingType.makeNullable()
@@ -19,7 +19,6 @@ package kotlin.reflect.jvm.internal.components
import org.jetbrains.kotlin.load.java.JavaClassFinder import org.jetbrains.kotlin.load.java.JavaClassFinder
import org.jetbrains.kotlin.load.java.structure.JavaClass import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaPackage import org.jetbrains.kotlin.load.java.structure.JavaPackage
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import kotlin.reflect.jvm.internal.structure.ReflectJavaClass import kotlin.reflect.jvm.internal.structure.ReflectJavaClass
import kotlin.reflect.jvm.internal.structure.ReflectJavaPackage import kotlin.reflect.jvm.internal.structure.ReflectJavaPackage
@@ -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.KotlinClassHeader
import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor import org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue import org.jetbrains.kotlin.resolve.constants.ClassLiteralValue
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
@@ -234,17 +233,17 @@ private object ReflectClassStructure {
clazz.isArray -> { clazz.isArray -> {
val v = visitor.visitArray(name) ?: return val v = visitor.visitArray(name) ?: return
val componentType = clazz.componentType val componentType = clazz.componentType
if (componentType.isEnum) { when {
val enumClassId = componentType.classId componentType.isEnum -> {
for (element in value as Array<*>) { val enumClassId = componentType.classId
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name)) for (element in value as Array<*>) {
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
}
} }
} else if (componentType == Class::class.java) { componentType == Class::class.java -> for (element in value as Array<*>) {
for (element in value as Array<*>) {
v.visitClassLiteral((element as Class<*>).classLiteralValue()) v.visitClassLiteral((element as Class<*>).classLiteralValue())
} }
} else { else -> for (element in value as Array<*>) {
for (element in value as Array<*>) {
v.visit(element) v.visit(element)
} }
} }
@@ -45,7 +45,7 @@ class ReflectJavaArrayAnnotationArgument(
name: Name?, name: Name?,
private val values: Array<*> private val values: Array<*>
) : ReflectJavaAnnotationArgument(name), JavaArrayAnnotationArgument { ) : ReflectJavaAnnotationArgument(name), JavaArrayAnnotationArgument {
override fun getElements() = values.map { ReflectJavaAnnotationArgument.create(it!!, null) } override fun getElements() = values.map { create(it!!, null) }
} }
class ReflectJavaEnumValueAnnotationArgument( class ReflectJavaEnumValueAnnotationArgument(
@@ -23,8 +23,8 @@ import java.lang.reflect.Type
class ReflectJavaArrayType(override val reflectType: Type) : ReflectJavaType(), JavaArrayType { class ReflectJavaArrayType(override val reflectType: Type) : ReflectJavaType(), JavaArrayType {
override val componentType: ReflectJavaType = with(reflectType) { override val componentType: ReflectJavaType = with(reflectType) {
when { when {
this is GenericArrayType -> ReflectJavaType.create(genericComponentType) this is GenericArrayType -> create(genericComponentType)
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType()) this is Class<*> && isArray() -> create(getComponentType())
else -> throw IllegalArgumentException("Not an array type (${reflectType::class.java}): $reflectType") else -> throw IllegalArgumentException("Not an array type (${reflectType::class.java}): $reflectType")
} }
} }
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind import org.jetbrains.kotlin.load.java.structure.LightClassOriginKind
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import java.lang.reflect.Member
import java.lang.reflect.Method import java.lang.reflect.Method
import java.util.* import java.util.*
@@ -84,14 +85,14 @@ class ReflectJavaClass(
override val fields: List<ReflectJavaField> override val fields: List<ReflectJavaField>
get() = klass.declaredFields get() = klass.declaredFields
.asSequence() .asSequence()
.filter { field -> !field.isSynthetic } .filterNot(Member::isSynthetic)
.map(::ReflectJavaField) .map(::ReflectJavaField)
.toList() .toList()
override val constructors: List<ReflectJavaConstructor> override val constructors: List<ReflectJavaConstructor>
get() = klass.declaredConstructors get() = klass.declaredConstructors
.asSequence() .asSequence()
.filter { constructor -> !constructor.isSynthetic } .filterNot(Member::isSynthetic)
.map(::ReflectJavaConstructor) .map(::ReflectJavaConstructor)
.toList() .toList()
@@ -47,7 +47,7 @@ class ReflectJavaClassifierType(public override val reflectType: Type) : Reflect
get() = with(reflectType) { this is Class<*> && getTypeParameters().isNotEmpty() } get() = with(reflectType) { this is Class<*> && getTypeParameters().isNotEmpty() }
override val typeArguments: List<JavaType> override val typeArguments: List<JavaType>
get() = reflectType.parameterizedTypeArguments.map(ReflectJavaType.Factory::create) get() = reflectType.parameterizedTypeArguments.map(Factory::create)
override val annotations: Collection<JavaAnnotation> override val annotations: Collection<JavaAnnotation>
get() { get() {
@@ -26,6 +26,6 @@ class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaFi
override val type: ReflectJavaType override val type: ReflectJavaType
get() = ReflectJavaType.create(member.genericType) get() = ReflectJavaType.create(member.genericType)
override val initializerValue get() = null override val initializerValue: Any? get() = null
override val hasConstantNotNullInitializer get() = false override val hasConstantNotNullInitializer get() = false
} }
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaModifierListOwner
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
interface ReflectJavaModifierListOwner : JavaModifierListOwner { interface ReflectJavaModifierListOwner : JavaModifierListOwner {
/* protected // KT-3029 */ val modifiers: Int val modifiers: Int
override val isAbstract: Boolean override val isAbstract: Boolean
get() = Modifier.isAbstract(modifiers) get() = Modifier.isAbstract(modifiers)
@@ -37,7 +37,7 @@ class ReflectJavaPackage(override val fqName: FqName) : ReflectJavaElement(), Ja
// TODO: support it if possible // TODO: support it if possible
override val annotations get() = emptyList<JavaAnnotation>() override val annotations get() = emptyList<JavaAnnotation>()
override fun findAnnotation(fqName: FqName) = null override fun findAnnotation(fqName: FqName): JavaAnnotation? = null
override val isDeprecatedInJavaDoc: Boolean override val isDeprecatedInJavaDoc: Boolean
get() = false get() = false
@@ -28,8 +28,8 @@ class ReflectJavaWildcardType(override val reflectType: WildcardType) : ReflectJ
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $reflectType") throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $reflectType")
} }
return when { return when {
lowerBounds.size == 1 -> ReflectJavaType.create(lowerBounds.single()) lowerBounds.size == 1 -> create(lowerBounds.single())
upperBounds.size == 1 -> upperBounds.single().let { ub -> if (ub != Any::class.java) ReflectJavaType.create(ub) else null } upperBounds.size == 1 -> upperBounds.single().let { ub -> if (ub != Any::class.java) create(ub) else null }
else -> null else -> null
} }
} }
@@ -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.AbstractJvm8RuntimeDescriptorLoaderTest
import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest import org.jetbrains.kotlin.jvm.runtime.AbstractJvmRuntimeDescriptorLoaderTest
fun main(args: Array<String>) { fun main() {
System.setProperty("java.awt.headless", "true") System.setProperty("java.awt.headless", "true")
testGroup("core/descriptors.runtime/tests", "compiler/testData") { testGroup("core/descriptors.runtime/tests", "compiler/testData") {
@@ -127,7 +127,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
myTestRootDisposable, ConfigurationKind.ALL, jdkKind myTestRootDisposable, ConfigurationKind.ALL, jdkKind
) )
for (root in environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS)) { 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) val ktFile = KotlinTestUtils.createFile(file.path, text, environment.project)
GenerationUtils.compileFileTo(ktFile, environment, tmpdir) GenerationUtils.compileFileTo(ktFile, environment, tmpdir)
@@ -176,7 +176,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
private fun adaptJavaSource(text: String): String { private fun adaptJavaSource(text: String): String {
val typeAnnotations = arrayOf("NotNull", "Nullable", "ReadOnly", "Mutable") 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) { if ("@Retention" !in adaptedSource) {
return adaptedSource.replace( return adaptedSource.replace(
"@interface", "@interface",
@@ -213,7 +213,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R =
visitor.visitPackageViewDescriptor(this, data) visitor.visitPackageViewDescriptor(this, data)
override fun getContainingDeclaration() = null override fun getContainingDeclaration(): PackageViewDescriptor? = null
override fun getOriginal() = throw UnsupportedOperationException() override fun getOriginal() = throw UnsupportedOperationException()
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = throw UnsupportedOperationException() override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = throw UnsupportedOperationException()
override fun getName() = throw UnsupportedOperationException() override fun getName() = throw UnsupportedOperationException()