Change map key type in AnnotationDescriptor.getAllValueArguments
Turns out, only the parameter's name is needed at all usages of this method. Such a map is both easier to use (no need to call ValueParameterDescriptor.getName) and easier to construct (no need to resolve annotation class, its constructor, its parameters). In this commit, only usages have changed but the implementations are still using the old logic, this is going to be refactored in subsequent commits
This commit is contained in:
+1
-1
@@ -92,7 +92,7 @@ class AnnotationTypeQualifierResolverImpl(storageManager: StorageManager) : Anno
|
||||
.annotations.findAnnotation(TYPE_QUALIFIER_DEFAULT_FQNAME)!!
|
||||
.allValueArguments
|
||||
.flatMap { (parameter, argument) ->
|
||||
if (parameter.name == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME)
|
||||
if (parameter == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME)
|
||||
argument.mapConstantToQualifierApplicabilityTypes()
|
||||
else
|
||||
emptyList()
|
||||
|
||||
+4
-4
@@ -109,14 +109,14 @@ open class JavaAnnotationDescriptor(
|
||||
|
||||
protected val firstArgument: JavaAnnotationArgument? = annotation?.arguments?.firstOrNull()
|
||||
|
||||
override val allValueArguments: Map<ValueParameterDescriptor, ConstantValue<*>> get() = emptyMap()
|
||||
override val valueArgumentsByParameterDescriptor: Map<ValueParameterDescriptor, ConstantValue<*>> get() = emptyMap()
|
||||
}
|
||||
|
||||
class JavaDeprecatedAnnotationDescriptor(
|
||||
annotation: JavaAnnotation?,
|
||||
c: LazyJavaResolverContext
|
||||
): JavaAnnotationDescriptor(c, annotation, c.module.builtIns.deprecatedAnnotation) {
|
||||
override val allValueArguments: Map<ValueParameterDescriptor, ConstantValue<*>> by c.storageManager.createLazyValue {
|
||||
override val valueArgumentsByParameterDescriptor: Map<ValueParameterDescriptor, ConstantValue<*>> by c.storageManager.createLazyValue {
|
||||
val parameterDescriptor = valueParameters.firstOrNull {
|
||||
it.name == JavaAnnotationMapper.DEPRECATED_ANNOTATION_MESSAGE
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class JavaTargetAnnotationDescriptor(
|
||||
annotation: JavaAnnotation,
|
||||
c: LazyJavaResolverContext
|
||||
): JavaAnnotationDescriptor(c, annotation, c.module.builtIns.targetAnnotation) {
|
||||
override val allValueArguments by c.storageManager.createLazyValue {
|
||||
override val valueArgumentsByParameterDescriptor by c.storageManager.createLazyValue {
|
||||
val targetArgument = when (firstArgument) {
|
||||
is JavaArrayAnnotationArgument -> JavaAnnotationTargetMapper.mapJavaTargetArguments(firstArgument.getElements(), c.module.builtIns)
|
||||
is JavaEnumValueAnnotationArgument -> JavaAnnotationTargetMapper.mapJavaTargetArguments(listOf(firstArgument), c.module.builtIns)
|
||||
@@ -144,7 +144,7 @@ class JavaRetentionAnnotationDescriptor(
|
||||
annotation: JavaAnnotation,
|
||||
c: LazyJavaResolverContext
|
||||
): JavaAnnotationDescriptor(c, annotation, c.module.builtIns.retentionAnnotation) {
|
||||
override val allValueArguments by c.storageManager.createLazyValue {
|
||||
override val valueArgumentsByParameterDescriptor by c.storageManager.createLazyValue {
|
||||
val retentionArgument = JavaAnnotationTargetMapper.mapJavaRetentionArgument(firstArgument, c.module.builtIns)
|
||||
retentionArgument?.let { mapOf(valueParameters.single() to it) }.orEmpty()
|
||||
}
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
|
||||
private val factory = ConstantValueFactory(c.module.builtIns)
|
||||
|
||||
override val allValueArguments by c.storageManager.createLazyValue {
|
||||
override val valueArgumentsByParameterDescriptor by c.storageManager.createLazyValue {
|
||||
val constructors = annotationClass!!.constructors
|
||||
if (constructors.isEmpty()) return@createLazyValue emptyMap<ValueParameterDescriptor, ConstantValue<*>>()
|
||||
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ private class EnhancedTypeAnnotations(private val fqNameToMatch: FqName) : Annot
|
||||
private object EnhancedTypeAnnotationDescriptor : AnnotationDescriptor {
|
||||
private fun throwError(): Nothing = error("No methods should be called on this descriptor. Only its presence matters")
|
||||
override val type: KotlinType get() = throwError()
|
||||
override val allValueArguments: Map<ValueParameterDescriptor, ConstantValue<*>> get() = throwError()
|
||||
override val valueArgumentsByParameterDescriptor: Map<ValueParameterDescriptor, ConstantValue<*>> get() = throwError()
|
||||
override val source: SourceElement get() = throwError()
|
||||
override fun toString() = "[EnhancedType]"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user