Skip to content

Commit

Permalink
FE: slowly refactor extractQualifiersFromAnnotations JetBrains#1
Browse files Browse the repository at this point in the history
That code is convoluted, better take it slow to avoid accidentally
breaking (or fixing) anything.
  • Loading branch information
pyos committed Aug 11, 2021
1 parent ae16e38 commit cf8e66d
Showing 1 changed file with 22 additions and 18 deletions.
Expand Up @@ -274,6 +274,20 @@ private class SignatureParts(
composeAnnotations(typeContainer.annotations, typeOrBound.annotations)
} else typeOrBound.annotations

val annotationsMutability = annotationTypeQualifierResolver.extractMutability(composedAnnotation)
val annotationsNullability = annotationTypeQualifierResolver.extractNullability(composedAnnotation) {
(this is LazyJavaAnnotationDescriptor && (isFreshlySupportedTypeUseAnnotation || typeParameterBounds) && !areImprovementsInStrictMode) ||
(this is PossiblyExternalAnnotationDescriptor && isIdeExternalAnnotation)
}.takeUnless { type == null }

if (annotationsNullability != null) {
return JavaTypeQualifiers(
annotationsNullability.qualifier, annotationsMutability,
annotationsNullability.qualifier == NullabilityQualifier.NOT_NULL && typeOrBound.isTypeParameter(),
annotationsNullability.isForWarningOnly
)
}

val defaultTypeQualifier = (
if (isHeadTypeConstructor)
containerContext.defaultTypeQualifiers?.get(containerApplicabilityType)
Expand All @@ -288,28 +302,18 @@ private class SignatureParts(

val (nullabilityFromBoundsForTypeBasedOnTypeParameter, isTypeParameterWithNotNullableBounds) =
typeOrBound.nullabilityInfoBoundsForTypeParameterUsage()

val annotationsNullability = annotationTypeQualifierResolver.extractNullability(composedAnnotation) {
(this is LazyJavaAnnotationDescriptor && (isFreshlySupportedTypeUseAnnotation || typeParameterBounds) && !areImprovementsInStrictMode) ||
(this is PossiblyExternalAnnotationDescriptor && isIdeExternalAnnotation)
}.takeUnless { type == null }
val nullabilityInfo =
annotationsNullability
?: computeNullabilityInfoInTheAbsenceOfExplicitAnnotation(
nullabilityFromBoundsForTypeBasedOnTypeParameter,
defaultTypeQualifier,
typeParameterForArgument,
type == null
)
val nullabilityInfo = computeNullabilityInfoInTheAbsenceOfExplicitAnnotation(
nullabilityFromBoundsForTypeBasedOnTypeParameter,
defaultTypeQualifier,
typeParameterForArgument,
type == null
)

val isNotNullTypeParameter =
if (annotationsNullability != null)
annotationsNullability.qualifier == NullabilityQualifier.NOT_NULL
else
isTypeParameterWithNotNullableBounds || defaultTypeQualifier?.makesTypeParameterNotNull == true
isTypeParameterWithNotNullableBounds || defaultTypeQualifier?.makesTypeParameterNotNull == true

return JavaTypeQualifiers(
nullabilityInfo?.qualifier, annotationTypeQualifierResolver.extractMutability(composedAnnotation),
nullabilityInfo?.qualifier, annotationsMutability,
isNotNullTypeParameter = isNotNullTypeParameter && typeOrBound.isTypeParameter(),
isNullabilityQualifierForWarning = nullabilityInfo?.isForWarningOnly == true
)
Expand Down

0 comments on commit cf8e66d

Please sign in to comment.