mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[kotlin] k2 introduce property: specify a functional type explicitly
^KTIJ-6298 fixed GitOrigin-RevId: 6aeae17e0d189e6d349ba70f803db36434183818
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fc97b3c3fb
commit
a23105ad9d
@@ -312,7 +312,7 @@ abstract class AbstractExtractionTest : KotlinLightCodeInsightFixtureTestCase()
|
||||
}
|
||||
|
||||
protected open fun doIntroducePropertyTest(unused: String) {
|
||||
doTest { file ->
|
||||
doTestIfNotDisabledByFileDirective { file ->
|
||||
file as KtFile
|
||||
|
||||
val extractionTarget = propertyTargets.single {
|
||||
|
||||
@@ -3235,6 +3235,11 @@ public abstract class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
runTest("testData/refactoring/introduceProperty/extractWithParams.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionalType.kt")
|
||||
public void testFunctionalType() throws Exception {
|
||||
runTest("testData/refactoring/introduceProperty/functionalType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt21530.kt")
|
||||
public void testKt21530() throws Exception {
|
||||
runTest("testData/refactoring/introduceProperty/kt21530.kt");
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// EXTRACTION_TARGET: property with initializer
|
||||
|
||||
fun foo(p: (String) -> Boolean) {
|
||||
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo <selection>{ it.isBlank() }</selection>
|
||||
}
|
||||
|
||||
// IGNORE_K1
|
||||
@@ -0,0 +1,13 @@
|
||||
// EXTRACTION_TARGET: property with initializer
|
||||
|
||||
fun foo(p: (String) -> Boolean) {
|
||||
|
||||
}
|
||||
|
||||
private val function: (String) -> Boolean = { it.isBlank() }
|
||||
|
||||
fun bar() {
|
||||
foo(function)
|
||||
}
|
||||
|
||||
// IGNORE_K1
|
||||
@@ -12,6 +12,8 @@ import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisFromWriteAction
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtFunctionalType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtUsualClassType
|
||||
import org.jetbrains.kotlin.idea.base.codeInsight.ShortenReferencesFacility
|
||||
import org.jetbrains.kotlin.idea.base.psi.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.base.psi.moveInsideParenthesesAndReplaceWith
|
||||
@@ -645,7 +647,9 @@ abstract class ExtractFunctionGenerator<KotlinType, ExtractionResult : IExtracti
|
||||
|
||||
val returnType = descriptor.returnType
|
||||
val presentation = typeDescriptor.renderType(returnType, isReceiver = false, Variance.OUT_VARIANCE)
|
||||
if (typeDescriptor.unitType == returnType || with(typeDescriptor) { returnType.isError() } || extractionTarget == ExtractionTarget.PROPERTY_WITH_INITIALIZER) {
|
||||
if (typeDescriptor.unitType == returnType ||
|
||||
with(typeDescriptor) { returnType.isError() } ||
|
||||
extractionTarget == ExtractionTarget.PROPERTY_WITH_INITIALIZER && returnType !is KtFunctionalType) {
|
||||
noReturnType()
|
||||
} else {
|
||||
returnType(presentation)
|
||||
|
||||
@@ -277,6 +277,11 @@ public abstract class K2IntroducePropertyTestGenerated extends AbstractK2Introdu
|
||||
runTest("../../idea/tests/testData/refactoring/introduceProperty/extractWithParams.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionalType.kt")
|
||||
public void testFunctionalType() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/introduceProperty/functionalType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt21530.kt")
|
||||
public void testKt21530() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/introduceProperty/kt21530.kt");
|
||||
|
||||
Reference in New Issue
Block a user