[ULC] Skip nullability annotation for backing field of lateinit property

This commit is contained in:
Igor Yakovlev
2020-07-22 19:05:21 +03:00
parent cd32cf7828
commit a36d53e086
2 changed files with 14 additions and 11 deletions
@@ -74,9 +74,6 @@ abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, P
return annotationsForEntries + filteredNonSourceAnnotations return annotationsForEntries + filteredNonSourceAnnotations
} }
if ((modifierListOwner is KtLightMember<*> && modifierListOwner !is KtLightFieldImpl.KtLightEnumConstant)
|| modifierListOwner is LightParameter
) {
if (fastCheckIsNullabilityApplied(modifierListOwner)) { if (fastCheckIsNullabilityApplied(modifierListOwner)) {
@@ -87,7 +84,7 @@ abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, P
return annotationsForEntries + listOf(nullabilityAnnotation) return annotationsForEntries + listOf(nullabilityAnnotation)
} }
}
return annotationsForEntries return annotationsForEntries
} }
} }
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.asJava.elements.PsiElementWithOrigin
import org.jetbrains.kotlin.asJava.elements.* import org.jetbrains.kotlin.asJava.elements.*
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
import org.jetbrains.kotlin.load.java.propertyNameBySetMethodName import org.jetbrains.kotlin.load.java.propertyNameBySetMethodName
@@ -228,12 +229,17 @@ fun KtLightMethod.checkIsMangled(): Boolean {
fun fastCheckIsNullabilityApplied(lightElement: KtLightElement<*, PsiModifierListOwner>): Boolean { fun fastCheckIsNullabilityApplied(lightElement: KtLightElement<*, PsiModifierListOwner>): Boolean {
val elementIsApplicable =
(lightElement is KtLightMember<*> && lightElement !is KtLightFieldImpl.KtLightEnumConstant) || lightElement is LightParameter
if (!elementIsApplicable) return false
val annotatedElement = lightElement.kotlinOrigin ?: return true val annotatedElement = lightElement.kotlinOrigin ?: return true
// all data-class generated members are not-null // all data-class generated members are not-null
if (annotatedElement is KtClass && annotatedElement.isData()) return true if (annotatedElement is KtClass && annotatedElement.isData()) return true
if (lightElement is PsiField && lightElement.hasModifierProperty(PsiModifier.PRIVATE)) return false // backing fields for lateinit props are skipped
if (lightElement is KtLightField && annotatedElement is KtProperty && annotatedElement.hasModifier(KtTokens.LATEINIT_KEYWORD)) return false
if (annotatedElement is KtParameter) { if (annotatedElement is KtParameter) {
val containingClassOrObject = annotatedElement.containingClassOrObject val containingClassOrObject = annotatedElement.containingClassOrObject