Remove compiler support for kotlin-annotations-android
#KT-44815
This commit is contained in:
@@ -19,19 +19,14 @@ package org.jetbrains.kotlin.load.java.descriptors
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaStaticClassScope
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.firstArgument
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class ValueParameterData(val type: KotlinType, val hasDefaultValue: Boolean)
|
||||
|
||||
@@ -72,25 +67,3 @@ fun DescriptorWithContainerSource.getImplClassNameForDeserialized(): JvmClassNam
|
||||
|
||||
fun DescriptorWithContainerSource.isFromJvmPackagePart(): Boolean =
|
||||
containerSource is JvmPackagePartSource
|
||||
|
||||
fun ValueParameterDescriptor.getParameterNameAnnotation(): AnnotationDescriptor? {
|
||||
val annotation = annotations.findAnnotation(JvmAnnotationNames.PARAMETER_NAME_FQ_NAME) ?: return null
|
||||
if (annotation.firstArgument()?.safeAs<StringValue>()?.value?.isEmpty() != false) {
|
||||
return null
|
||||
}
|
||||
|
||||
return annotation
|
||||
}
|
||||
|
||||
fun ValueParameterDescriptor.getDefaultValueFromAnnotation(): AnnotationDefaultValue? {
|
||||
annotations.findAnnotation(JvmAnnotationNames.DEFAULT_VALUE_FQ_NAME)
|
||||
?.firstArgument()
|
||||
?.safeAs<StringValue>()?.value
|
||||
?.let { return StringDefaultValue(it) }
|
||||
|
||||
if (annotations.hasAnnotation(JvmAnnotationNames.DEFAULT_NULL_FQ_NAME)) {
|
||||
return NullDefaultValue
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
-12
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
@@ -39,8 +38,6 @@ import org.jetbrains.kotlin.load.java.toDescriptorVisibility
|
||||
import org.jetbrains.kotlin.load.kotlin.computeJvmDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.firstArgument
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude.NonExtensions
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -53,7 +50,6 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.*
|
||||
|
||||
abstract class LazyJavaScope(
|
||||
@@ -212,15 +208,9 @@ abstract class LazyJavaScope(
|
||||
jValueParameters: List<JavaValueParameter>
|
||||
): ResolvedValueParameters {
|
||||
var synthesizedNames = false
|
||||
val usedNames = mutableSetOf<String>()
|
||||
|
||||
val descriptors = jValueParameters.withIndex().map { (index, javaParameter) ->
|
||||
val annotations = c.resolveAnnotations(javaParameter)
|
||||
val typeUsage = TypeUsage.COMMON.toAttributes()
|
||||
val parameterName = annotations
|
||||
.findAnnotation(JvmAnnotationNames.PARAMETER_NAME_FQ_NAME)
|
||||
?.firstArgument()
|
||||
?.safeAs<StringValue>()?.value
|
||||
|
||||
val (outType, varargElementType) =
|
||||
if (javaParameter.isVararg) {
|
||||
@@ -241,8 +231,6 @@ abstract class LazyJavaScope(
|
||||
// "other" in Any)
|
||||
// TODO: fix Java parameter name loading logic somehow (don't always load "p0", "p1", etc.)
|
||||
Name.identifier("other")
|
||||
} else if (parameterName != null && parameterName.isNotEmpty() && usedNames.add(parameterName)) {
|
||||
Name.identifier(parameterName)
|
||||
} else {
|
||||
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
||||
val javaName = javaParameter.name
|
||||
|
||||
+2
-22
@@ -195,14 +195,8 @@ class SignatureEnhancement(
|
||||
}
|
||||
|
||||
val valueParameterEnhancements = annotationOwnerForMember.valueParameters.map { p ->
|
||||
val enhancementResult = partsForValueParameter(p, memberContext) { it.valueParameters[p.index].type }
|
||||
partsForValueParameter(p, memberContext) { it.valueParameters[p.index].type }
|
||||
.enhance(predefinedEnhancementInfo?.parametersInfo?.getOrNull(p.index))
|
||||
|
||||
val actualType = if (enhancementResult.wereChanges) enhancementResult.type else p.type
|
||||
val hasDefaultValue = p.hasDefaultValueInAnnotation(actualType)
|
||||
val wereChanges = enhancementResult.wereChanges || (hasDefaultValue != p.declaresDefaultValue())
|
||||
|
||||
ValueParameterEnhancementResult(enhancementResult.type, hasDefaultValue, wereChanges, enhancementResult.containsFunctionN)
|
||||
}
|
||||
|
||||
val returnTypeEnhancement =
|
||||
@@ -231,7 +225,7 @@ class SignatureEnhancement(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return this.enhance(
|
||||
receiverTypeEnhancement?.type,
|
||||
valueParameterEnhancements.map { ValueParameterData(it.type, it.hasDefaultValue) },
|
||||
valueParameterEnhancements.map { ValueParameterData(it.type, false) },
|
||||
returnTypeEnhancement.type,
|
||||
additionalUserData
|
||||
) as D
|
||||
@@ -263,13 +257,6 @@ class SignatureEnhancement(
|
||||
fun enhanceSuperType(type: KotlinType, context: LazyJavaResolverContext) =
|
||||
SignatureParts(null, type, emptyList(), false, context, AnnotationQualifierApplicabilityType.TYPE_USE).enhance().type
|
||||
|
||||
private fun ValueParameterDescriptor.hasDefaultValueInAnnotation(type: KotlinType) =
|
||||
when (val defaultValue = getDefaultValueFromAnnotation()) {
|
||||
is StringDefaultValue -> type.lexicalCastFrom(defaultValue.value) != null
|
||||
NullDefaultValue -> TypeUtils.acceptsNullable(type)
|
||||
null -> declaresDefaultValue()
|
||||
} && overriddenDescriptors.isEmpty()
|
||||
|
||||
private inner class SignatureParts(
|
||||
private val typeContainer: Annotated?,
|
||||
private val fromOverride: KotlinType,
|
||||
@@ -592,13 +579,6 @@ class SignatureEnhancement(
|
||||
val containsFunctionN: Boolean
|
||||
)
|
||||
|
||||
private class ValueParameterEnhancementResult(
|
||||
type: KotlinType,
|
||||
val hasDefaultValue: Boolean,
|
||||
wereChanges: Boolean,
|
||||
containsFunctionN: Boolean
|
||||
) : PartEnhancementResult(type, wereChanges, containsFunctionN)
|
||||
|
||||
private fun CallableMemberDescriptor.partsForValueParameter(
|
||||
// TODO: investigate if it's really can be a null (check properties' with extension overrides in Java)
|
||||
parameterDescriptor: ValueParameterDescriptor?,
|
||||
|
||||
@@ -16,53 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.resolve.deprecation.Deprecation
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.utils.extractRadix
|
||||
|
||||
sealed class JavaDefaultValue
|
||||
class EnumEntry(val descriptor: ClassDescriptor) : JavaDefaultValue()
|
||||
class Constant(val value: Any) : JavaDefaultValue()
|
||||
|
||||
fun KotlinType.lexicalCastFrom(value: String): JavaDefaultValue? {
|
||||
val typeDescriptor = constructor.declarationDescriptor
|
||||
if (typeDescriptor is ClassDescriptor && typeDescriptor.kind == ClassKind.ENUM_CLASS) {
|
||||
val descriptor = typeDescriptor.unsubstitutedInnerClassesScope.getContributedClassifier(
|
||||
Name.identifier(value),
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
)
|
||||
|
||||
return if (descriptor is ClassDescriptor && descriptor.kind == ClassKind.ENUM_ENTRY) EnumEntry(descriptor) else null
|
||||
}
|
||||
|
||||
val type = this.makeNotNullable()
|
||||
val (number, radix) = extractRadix(value)
|
||||
val result: Any? = try {
|
||||
when {
|
||||
KotlinBuiltIns.isBoolean(type) -> value.toBoolean()
|
||||
KotlinBuiltIns.isChar(type) -> value.singleOrNull()
|
||||
KotlinBuiltIns.isByte(type) -> number.toByteOrNull(radix)
|
||||
KotlinBuiltIns.isShort(type) -> number.toShortOrNull(radix)
|
||||
KotlinBuiltIns.isInt(type) -> number.toIntOrNull(radix)
|
||||
KotlinBuiltIns.isLong(type) -> number.toLongOrNull(radix)
|
||||
KotlinBuiltIns.isFloat(type) -> value.toFloatOrNull()
|
||||
KotlinBuiltIns.isDouble(type) -> value.toDoubleOrNull()
|
||||
KotlinBuiltIns.isString(type) -> value
|
||||
else -> null
|
||||
}
|
||||
} catch (e: IllegalArgumentException) {
|
||||
null
|
||||
}
|
||||
|
||||
return if (result != null) Constant(result) else null
|
||||
}
|
||||
|
||||
class DeprecationCausedByFunctionN(override val target: DeclarationDescriptor) : Deprecation {
|
||||
override val deprecationLevel: DeprecationLevelValue
|
||||
|
||||
Reference in New Issue
Block a user