@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
36
36
import org.jetbrains.kotlin.psi.*
37
37
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
38
38
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
39
+ import org.jetbrains.kotlin.psi.psiUtil.hasSuspendModifier
39
40
import org.jetbrains.kotlin.resolve.BindingContext
40
41
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
41
42
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
@@ -83,10 +84,10 @@ abstract class KtLightAbstractAnnotation(parent: PsiElement, computeDelegate: ()
83
84
}
84
85
85
86
class KtLightAnnotationForSourceEntry (
86
- private val qualifiedName : String ,
87
- override val kotlinOrigin : KtCallElement ,
88
- parent : PsiElement ,
89
- computeDelegate : () -> PsiAnnotation
87
+ private val qualifiedName : String ,
88
+ override val kotlinOrigin : KtCallElement ,
89
+ parent : PsiElement ,
90
+ computeDelegate : () -> PsiAnnotation
90
91
) : KtLightAbstractAnnotation(parent, computeDelegate) {
91
92
92
93
override fun getQualifiedName () = qualifiedName
@@ -237,9 +238,9 @@ class KtLightEmptyAnnotationParameterList(parent: PsiElement) : KtLightElementBa
237
238
238
239
open class KtLightNullabilityAnnotation <D : KtLightElement <* , PsiModifierListOwner >>(val member : D , parent : PsiElement ) :
239
240
KtLightAbstractAnnotation (parent, {
240
- // searching for last because nullability annotations are generated after backend generates source annotations
241
+ // searching for last because nullability annotations are generated after backend generates source annotations
241
242
getClsNullabilityAnnotation(member) ? : KtLightNonExistentAnnotation (member)
242
- }) {
243
+ }) {
243
244
override fun fqNameMatches (fqName : String ): Boolean {
244
245
if (! isNullabilityAnnotation(fqName)) return false
245
246
@@ -253,8 +254,8 @@ open class KtLightNullabilityAnnotation<D : KtLightElement<*, PsiModifierListOwn
253
254
254
255
override fun getQualifiedName (): String? {
255
256
val annotatedElement = member.takeIf (::isFromSources)?.kotlinOrigin
256
- ? : // it is out of our hands
257
- return getClsNullabilityAnnotation(member)?.qualifiedName
257
+ ? : // it is out of our hands
258
+ return getClsNullabilityAnnotation(member)?.qualifiedName
258
259
259
260
// all data-class generated members are not-null
260
261
if (annotatedElement is KtClass && annotatedElement.isData()) return NotNull ::class .java.name
@@ -266,7 +267,12 @@ open class KtLightNullabilityAnnotation<D : KtLightElement<*, PsiModifierListOwn
266
267
// don't annotate property setters
267
268
if (annotatedElement is KtValVarKeywordOwner && member is KtLightMethod && member.returnType == PsiType .VOID ) return null
268
269
270
+ if (annotatedElement is KtNamedFunction && annotatedElement.modifierList?.hasSuspendModifier() == true ) {
271
+ return Nullable ::class .java.name
272
+ }
273
+
269
274
val kotlinType = getTargetType(annotatedElement) ? : return null
275
+
270
276
if (KotlinBuiltIns .isPrimitiveType(kotlinType) && (annotatedElement as ? KtParameter )?.isVarArg != true ) {
271
277
// no need to annotate them explicitly except the case when overriding reference-type makes it non-primitive for Jvm
272
278
if (! (annotatedElement is KtCallableDeclaration && annotatedElement.hasModifier(KtTokens .OVERRIDE_KEYWORD ))) return null
0 commit comments