K2: implement "create function from usage" for members (part of KTIJ-28926 K2: Create Function From Usage Fix)

- support "fir" version for dependency files in test data for AbstractQuickFixMultiFileTest
- support generation of @Nullable/@NotNull in java method signatures
- support nullability in generated java types (ExpectedTypeWithNullability)
- support implicit receivers in generation (see computeImplicitReceiverType)
- suggest creating new function in case of too many/too few arguments (K2CreateFromUsageQuickFixesRegistrar)

GitOrigin-RevId: d1adac9e7a4f5caeb2300e80c953e95a0c339dcf
This commit is contained in:
Alexey Kudravtsev
2024-03-18 15:36:51 +01:00
committed by intellij-monorepo-bot
parent 33442630e6
commit f294fccb79
48 changed files with 532 additions and 236 deletions

View File

@@ -0,0 +1,40 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.jvm.actions
import com.intellij.codeInsight.Nullability
import com.intellij.lang.jvm.types.JvmType
import com.intellij.psi.PsiType
import com.intellij.psi.PsiTypeVisitor
import com.intellij.psi.PsiTypes
import com.intellij.psi.search.GlobalSearchScope
class ExpectedTypeWithNullability(val type: JvmType, val nullability: Nullability) : ExpectedType {
override fun getTheType(): JvmType = type
override fun getTheKind(): ExpectedType.Kind = ExpectedType.Kind.EXACT
companion object {
fun createExpectedKotlinType(type: JvmType, nullability: Nullability): ExpectedTypeWithNullability = ExpectedTypeWithNullability(type, nullability)
/**
* A placeholder to denote "This type is invalid". Only thing this type does is returning `false` for `isValid()` function.
*/
val INVALID_TYPE: ExpectedTypeWithNullability = createExpectedKotlinType(object : PsiType(emptyArray()) {
override fun <A : Any?> accept(visitor: PsiTypeVisitor<A>): A {
return visitor.visitType(PsiTypes.nullType())
}
override fun getPresentableText(): String = ""
override fun getCanonicalText(): String = ""
override fun isValid(): Boolean = false
override fun equalsToText(text: String): Boolean = false
override fun getResolveScope(): GlobalSearchScope? = null
override fun getSuperTypes(): Array<PsiType> = emptyArray()
}, Nullability.UNKNOWN)
}
}