[kotlin] Port InitializePropertyQuickFixFactory to K2

^KTIJ-29621 Fixed

GitOrigin-RevId: 6c3d594880b4afce2f8ef2f7f1df5ec9ea601e52
This commit is contained in:
aleksandrina-streltsova
2024-07-29 10:03:19 +00:00
committed by intellij-monorepo-bot
parent 45ef647ae1
commit c433a4c2b1
66 changed files with 713 additions and 137 deletions
@@ -184,4 +184,13 @@ fun KtExpression.prependDotQualifiedReceiver(receiver: KtExpression, factory: Kt
fun KtExpression.appendDotQualifiedSelector(selector: KtExpression, factory: KtPsiFactory): KtExpression {
val dotQualified = factory.createExpressionByPattern("$0.$1", this, selector)
return this.replaced(dotQualified)
}
fun KtSecondaryConstructor.getOrCreateBody(): KtBlockExpression {
bodyExpression?.let { return it }
val delegationCall = getDelegationCall()
val anchor = if (delegationCall.isImplicit) valueParameterList else delegationCall
val newBody = KtPsiFactory(project).createEmptyBody()
return addAfter(newBody, anchor) as KtBlockExpression
}
@@ -1119,6 +1119,7 @@ replace.annotation.with.0=Replace annotation with {0}
add.initializer=Add initializer
move.to.constructor.parameters=Move to constructor parameters
initialize.with.constructor.parameter=Initialize with constructor parameter
initialize.with.constructor.parameter.analyzing.existing.variables=Analyzing Existing Variables\u2026
inline.type.parameter=Inline type parameter
insert.explicit.delegation.call=Insert explicit delegation call
the.anonymous.object=the anonymous object
@@ -37,6 +37,7 @@
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.lang" />
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
<orderEntry type="module" module-name="intellij.java.psi" />
<orderEntry type="module" module-name="intellij.java.analysis.impl" />
<orderEntry type="module" module-name="kotlin.base.analysis-api.utils" />
@@ -1,106 +1,353 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
import com.intellij.codeInsight.intention.CommonIntentionAction
import com.intellij.codeInspection.util.IntentionFamilyName
import com.intellij.codeInspection.util.IntentionName
import com.intellij.modcommand.ActionContext
import com.intellij.modcommand.ModPsiUpdater
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.createSmartPointer
import com.intellij.usageView.UsageInfo
import com.intellij.util.application
import com.intellij.util.containers.MultiMap
import com.intellij.util.containers.addIfNotNull
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.idea.base.analysis.api.utils.analyzeInModalWindow
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinDeclarationNameValidator
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggestionProvider
import org.jetbrains.kotlin.idea.base.psi.getOrCreateBody
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction
import org.jetbrains.kotlin.idea.k2.refactoring.changeSignature.*
import org.jetbrains.kotlin.idea.k2.refactoring.changeSignature.KotlinChangeSignatureProcessor
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.extractionEngine.KotlinNameSuggester
import org.jetbrains.kotlin.idea.refactoring.addElement
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinValVar
import org.jetbrains.kotlin.idea.refactoring.changeSignature.toValVar
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
object InitializePropertyQuickFixFactories {
private data class ElementContext(
val initializerText: String,
private data class PropertyContext(
val defaultInitializer: String,
)
private data class PropertyContextForNewParameter(
val defaultInitializer: String,
val propertyName: String,
val propertyType: String,
)
private class InitializePropertyModCommandAction(
element: KtProperty,
elementContext: ElementContext,
) : KotlinPsiUpdateModCommandAction.ElementBased<KtProperty, ElementContext>(element, elementContext) {
property: KtProperty,
propertyContext: PropertyContext,
) : KotlinPsiUpdateModCommandAction.ElementBased<KtProperty, PropertyContext>(property, propertyContext) {
override fun getFamilyName(): String = KotlinBundle.message("add.initializer")
override fun invoke(
actionContext: ActionContext,
element: KtProperty,
elementContext: ElementContext,
elementContext: PropertyContext,
updater: ModPsiUpdater,
) {
val expression = KtPsiFactory(actionContext.project)
.createExpression(elementContext.initializerText)
.createExpression(elementContext.defaultInitializer)
val initializer = element.setInitializer(expression)!!
updater.select(TextRange(initializer.startOffset, initializer.endOffset))
updater.moveCaretTo(initializer.endOffset)
}
}
private class InitializeWithConstructorParameterFix(
property: KtProperty,
private val propertyContext: PropertyContextForNewParameter,
) : KotlinQuickFixAction<KtProperty>(property) {
override fun getText(): @IntentionName String = KotlinBundle.message("initialize.with.constructor.parameter")
override fun getFamilyName(): @IntentionFamilyName String = text
override fun startInWriteAction(): Boolean = false
override fun invoke(
project: Project,
editor: Editor?,
file: KtFile
) {
val property = element ?: return
val containingClass = property.containingClassOrObject as? KtClass ?: return
val constructors = buildList {
addIfNotNull(containingClass.primaryConstructor)
addAll(containingClass.secondaryConstructors)
// add `null` to change signature of the implicit primary constructor
if (isEmpty()) add(null)
}
// the constructor with a changed signature might conflict with an existing one, which is not updated at the moment;
// to avoid such conflicts, we need to update constructors in order defined by their parameter count
val sortedConstructors = constructors.sortedByDescending { it?.valueParameters?.size ?: 0 }
val updatedConstructors = sortedConstructors.map { constructor ->
changeConstructorSignature(project, property, constructor, containingClass)
}
application.runWriteAction {
for (updatedConstructor in updatedConstructors) {
initializeProperty(project, property, updatedConstructor, containingClass)
}
}
}
private fun initializeProperty(
project: Project,
property: KtProperty,
constructor: KtConstructor<*>,
containingClass: KtClass,
) {
val newParameterName = constructor.valueParameters.last().name
?: errorWithAttachment(property, constructor, containingClass)
val psiFactory = org.jetbrains.kotlin.psi.KtPsiFactory(project)
when (constructor) {
is KtPrimaryConstructor -> property.setInitializer(psiFactory.createExpression(newParameterName))
is KtSecondaryConstructor -> {
val callToThis = constructor.getDelegationCall().takeIf { it.isCallToThis }
if (callToThis != null) {
callToThis.valueArguments.last().getArgumentExpression()?.replace(psiFactory.createExpression(newParameterName))
} else {
val initialization = psiFactory.createExpression("this.${propertyContext.propertyName} = $newParameterName")
constructor.getOrCreateBody().addElement(initialization)
}
}
}
}
private fun changeConstructorSignature(
project: Project,
property: KtProperty,
constructor: KtConstructor<*>?,
containingClass: KtClass,
): KtConstructor<*> {
val constructorPointer = constructor?.createSmartPointer()
val containingClassPointer = containingClass.createSmartPointer()
val validator = KotlinDeclarationNameValidator(
visibleDeclarationsContext = containingClass.parent as KtElement,
checkVisibleDeclarationsContext = false,
target = KotlinNameSuggestionProvider.ValidatorTarget.PARAMETER,
)
val existingNames = constructor?.valueParameters?.mapNotNull { it.name }?.toSet() ?: emptySet()
val parameterName = analyzeInModalWindow(
containingClass,
KotlinBundle.message("initialize.with.constructor.parameter.analyzing.existing.variables")
) {
KotlinNameSuggester.suggestNameByName(propertyContext.propertyName) { it !in existingNames && validator.validate(it) }
}
val changeInfo = buildChangeInfoForAddingParameter(
constructor,
containingClass,
parameterName,
propertyContext.propertyType,
propertyContext.defaultInitializer
)
KotlinChangeSignatureProcessor(project, changeInfo).run()
val updatedConstructor = if (constructorPointer != null) {
constructorPointer.element
} else {
containingClassPointer.element?.primaryConstructor
} ?: errorWithAttachment(property, constructor, containingClass)
return updatedConstructor
}
}
private class MoveToConstructorParametersFix(
property: KtProperty,
private val propertyContext: PropertyContextForNewParameter,
) : KotlinQuickFixAction<KtProperty>(property) {
override fun getText(): @IntentionName String = KotlinBundle.message("move.to.constructor.parameters")
override fun getFamilyName(): @IntentionFamilyName String = text
override fun startInWriteAction(): Boolean = false
override fun invoke(
project: Project,
editor: Editor?,
file: KtFile
) {
val property = element ?: return
val containingClass = property.containingClassOrObject as? KtClass ?: return
val primaryConstructor = containingClass.primaryConstructor
val changeInfo = buildChangeInfoForAddingParameter(
primaryConstructor,
containingClass,
propertyContext.propertyName,
propertyContext.propertyType,
propertyContext.defaultInitializer,
valOrVar = property.valOrVarKeyword.toValVar(),
)
val changeSignatureProcessor = object : KotlinChangeSignatureProcessor(project, changeInfo) {
override fun performRefactoring(usages: Array<out UsageInfo>) {
super.performRefactoring(usages)
val newParameter = containingClass.primaryConstructor?.valueParameters?.lastOrNull<KtParameter>()
?: errorWithAttachment(property, primaryConstructor, containingClass)
// replace a new parameter with the property text to preserve the property's modifiers and comments
val parameterToReplaceWith = KtPsiFactory(project).createParameter(property.text)
newParameter.replace(parameterToReplaceWith)
property.delete()
}
override fun showConflicts(conflicts: MultiMap<PsiElement, String>, usages: Array<out UsageInfo>?): Boolean {
// don't show a conflict with the property as it will be removed after the refactoring is performed
conflicts.remove(property)
return super.showConflicts(conflicts, usages)
}
}
changeSignatureProcessor.setPrepareSuccessfulSwingThreadCallback {}
changeSignatureProcessor.run()
}
}
// todo refactor
val mustBeInitialized = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitialized ->
val mustBeInitialized = KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitialized ->
createFixes(diagnostic.psi)
}
val mustBeInitializedWarning = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedWarning ->
val mustBeInitializedWarning = KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedWarning ->
createFixes(diagnostic.psi)
}
val mustBeInitializedOrBeFinal = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeFinal ->
val mustBeInitializedOrBeFinal = KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeFinal ->
createFixes(diagnostic.psi)
}
val mustBeInitializedOrBeFinalWarning =
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeFinalWarning ->
KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeFinalWarning ->
createFixes(diagnostic.psi)
}
val mustBeInitializedOrBeAbstract = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeAbstract ->
val mustBeInitializedOrBeAbstract = KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeAbstract ->
createFixes(diagnostic.psi)
}
val mustBeInitializedOrBeAbstractWarning =
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeAbstractWarning ->
KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedOrBeAbstractWarning ->
createFixes(diagnostic.psi)
}
val mustBeInitializedOrFinalOrAbstract =
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedOrFinalOrAbstract ->
KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedOrFinalOrAbstract ->
createFixes(diagnostic.psi)
}
val mustBeInitializedOrFinalOrAbstractWarning =
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.MustBeInitializedOrFinalOrAbstractWarning ->
KotlinQuickFixFactory { diagnostic: KaFirDiagnostic.MustBeInitializedOrFinalOrAbstractWarning ->
createFixes(diagnostic.psi)
}
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun createFixes(
element: KtProperty,
): List<KotlinPsiUpdateModCommandAction<KtProperty, *>> {
property: KtProperty,
): List<CommonIntentionAction> {
// An extension property cannot be initialized because it has no backing field
if (element.receiverTypeReference != null) return emptyList()
if (property.receiverTypeReference != null) return emptyList()
return buildList {
val elementContext = ElementContext(
initializerText = element.returnType.defaultInitializer ?: "TODO()",
)
add(InitializePropertyModCommandAction(element, elementContext))
val propertyType = property.returnType
val initializerText = propertyType.defaultInitializer ?: "TODO()"
val propertyContext = PropertyContext(initializerText)
(element.containingClassOrObject as? KtClass)?.let { ktClass ->
add(InitializePropertyModCommandAction(property, propertyContext))
val propertyName = property.name ?: return@buildList
(property.containingClassOrObject as? KtClass)?.let { ktClass ->
if (ktClass.isAnnotation() || ktClass.isInterface()) return@let
if (ktClass.primaryConstructor?.hasActualModifier() == true) return@let
// TODO: Add quickfixes MoveToConstructorParameters and InitializeWithConstructorParameter after change signature
// refactoring is available. See org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory
val propertyContextForNewParameter = PropertyContextForNewParameter(
initializerText,
propertyName,
propertyType.render(position = Variance.INVARIANT)
)
val secondaryConstructors = ktClass.secondaryConstructors.filterNot(::hasExplicitDelegationCallToThis)
if (property.accessors.isEmpty() && secondaryConstructors.isEmpty()) {
add(MoveToConstructorParametersFix(property, propertyContextForNewParameter))
} else {
if (secondaryConstructors.none { it.hasActualModifier() }) {
add(InitializeWithConstructorParameterFix(property, propertyContextForNewParameter))
}
}
}
}
}
private fun buildChangeInfoForAddingParameter(
constructor: KtConstructor<*>?,
containingClass: KtClass,
name: String,
type: String,
defaultValueForCall: String,
valOrVar: KotlinValVar = KotlinValVar.None,
): KotlinChangeInfo {
val constructorOrClass = constructor ?: containingClass
val methodDescriptor = KotlinMethodDescriptor(constructorOrClass)
val changeInfo = KotlinChangeInfo(methodDescriptor)
val parameterInfo = KotlinParameterInfo(
originalType = KotlinTypeInfo(type, constructorOrClass),
name = name,
valOrVar = valOrVar,
defaultValueForCall = KtPsiFactory.contextual(constructorOrClass).createExpression(defaultValueForCall),
defaultValueAsDefaultParameter = false,
defaultValue = null,
context = constructorOrClass,
)
changeInfo.addParameter(parameterInfo)
return changeInfo
}
private fun hasExplicitDelegationCallToThis(constructor: KtSecondaryConstructor): Boolean = constructor.getDelegationCall().isCallToThis
private fun errorWithAttachment(property: KtProperty, constructor: KtConstructor<*>?, containingClass: KtClass): Nothing {
errorWithAttachment("Failed to perform fix") {
withPsiEntry("property", property)
withPsiEntry("constructor", constructor)
withPsiEntry("containingClass", containingClass)
}
}
}
@@ -9029,7 +9029,124 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter")
public static class InitializeWithConstructorParameter extends AbstractHighLevelQuickFixTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K2;
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("constructorWithThisDelegation.kt")
public void testConstructorWithThisDelegation() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/constructorWithThisDelegation.kt");
}
@TestMetadata("genericParameterInScope.kt")
public void testGenericParameterInScope() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/genericParameterInScope.kt");
}
@TestMetadata("localVar.kt")
public void testLocalVar() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/localVar.kt");
}
@TestMetadata("memberPropertyInClassNameClashInPrimaryConstructor.kt")
public void testMemberPropertyInClassNameClashInPrimaryConstructor() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNameClashInPrimaryConstructor.kt");
}
@TestMetadata("memberPropertyInClassNameClashInPrimaryConstructor2.kt")
public void testMemberPropertyInClassNameClashInPrimaryConstructor2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNameClashInPrimaryConstructor2.kt");
}
@TestMetadata("memberPropertyInClassNameClashInSecondaryConstructor.kt")
public void testMemberPropertyInClassNameClashInSecondaryConstructor() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNameClashInSecondaryConstructor.kt");
}
@TestMetadata("memberPropertyInClassNoConstructors.kt")
public void testMemberPropertyInClassNoConstructors() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNoConstructors.kt");
}
@TestMetadata("memberPropertyInClassPrimaryAndSecondaryConstructors.kt")
public void testMemberPropertyInClassPrimaryAndSecondaryConstructors() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassPrimaryAndSecondaryConstructors.kt");
}
@TestMetadata("memberPropertyInClassPrimaryConstructorOnly.kt")
public void testMemberPropertyInClassPrimaryConstructorOnly() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassPrimaryConstructorOnly.kt");
}
@TestMetadata("memberPropertyInClassSecondaryConstructorsOnly.kt")
public void testMemberPropertyInClassSecondaryConstructorsOnly() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassSecondaryConstructorsOnly.kt");
}
@TestMetadata("memberPropertyInInterface.kt")
public void testMemberPropertyInInterface() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInInterface.kt");
}
@TestMetadata("memberPropertyInObject.kt")
public void testMemberPropertyInObject() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyInObject.kt");
}
@TestMetadata("memberPropertyNoAccessorsInClassNoConstructors.kt")
public void testMemberPropertyNoAccessorsInClassNoConstructors() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyNoAccessorsInClassNoConstructors.kt");
}
@TestMetadata("memberPropertyNoAccessorsInClassPrimaryAndSecondaryConstructors.kt")
public void testMemberPropertyNoAccessorsInClassPrimaryAndSecondaryConstructors() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyNoAccessorsInClassPrimaryAndSecondaryConstructors.kt");
}
@TestMetadata("memberPropertyNoAccessorsInClassPrimaryConstructorOnly.kt")
public void testMemberPropertyNoAccessorsInClassPrimaryConstructorOnly() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyNoAccessorsInClassPrimaryConstructorOnly.kt");
}
@TestMetadata("memberPropertyWithDelegateRuntime.kt")
public void testMemberPropertyWithDelegateRuntime() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/memberPropertyWithDelegateRuntime.kt");
}
@TestMetadata("multipleConstructors.kt")
public void testMultipleConstructors() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/multipleConstructors.kt");
}
@TestMetadata("multipleConstructorsClash.kt")
public void testMultipleConstructorsClash() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/multipleConstructorsClash.kt");
}
@TestMetadata("multipleConstructorsClash2.kt")
public void testMultipleConstructorsClash2() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/multipleConstructorsClash2.kt");
}
@TestMetadata("namelessProperty.kt")
public void testNamelessProperty() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/namelessProperty.kt");
}
@TestMetadata("topLevelProperty.kt")
public void testTopLevelProperty() throws Exception {
runTest("../../../idea/tests/testData/quickfix/initializeWithConstructorParameter/topLevelProperty.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/inlineClass")
@@ -9289,7 +9406,79 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../../../idea/tests/testData/quickfix/moveToConstructorParameters")
public static class MoveToConstructorParameters extends AbstractHighLevelQuickFixTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K2;
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("localVar.kt")
public void testLocalVar() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/localVar.kt");
}
@TestMetadata("memberExtensionProperty.kt")
public void testMemberExtensionProperty() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberExtensionProperty.kt");
}
@TestMetadata("memberPropertyInClassNameClash.kt")
public void testMemberPropertyInClassNameClash() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInClassNameClash.kt");
}
@TestMetadata("memberPropertyInClassNoPrimaryConstructor.kt")
public void testMemberPropertyInClassNoPrimaryConstructor() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInClassNoPrimaryConstructor.kt");
}
@TestMetadata("memberPropertyInClassWithConstructorDelegatingToSuper.kt")
public void testMemberPropertyInClassWithConstructorDelegatingToSuper() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInClassWithConstructorDelegatingToSuper.kt");
}
@TestMetadata("memberPropertyInClassWithImplicitlyDelegatingConstructor.kt")
public void testMemberPropertyInClassWithImplicitlyDelegatingConstructor() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInClassWithImplicitlyDelegatingConstructor.kt");
}
@TestMetadata("memberPropertyInClassWithPrimaryConstructor.kt")
public void testMemberPropertyInClassWithPrimaryConstructor() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInClassWithPrimaryConstructor.kt");
}
@TestMetadata("memberPropertyInInterface.kt")
public void testMemberPropertyInInterface() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInInterface.kt");
}
@TestMetadata("memberPropertyInObject.kt")
public void testMemberPropertyInObject() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyInObject.kt");
}
@TestMetadata("memberPropertyWithDelegateRuntime.kt")
public void testMemberPropertyWithDelegateRuntime() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/memberPropertyWithDelegateRuntime.kt");
}
@TestMetadata("propertyWithModifiersAndComments.kt")
public void testPropertyWithModifiersAndComments() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/propertyWithModifiersAndComments.kt");
}
@TestMetadata("topLevelProperty.kt")
public void testTopLevelProperty() throws Exception {
runTest("../../../idea/tests/testData/quickfix/moveToConstructorParameters/topLevelProperty.kt");
}
}
@@ -468,15 +468,6 @@ private fun KtDeclaration.predictImplicitModality(): KtModifierKeywordToken {
return KtTokens.FINAL_KEYWORD
}
fun KtSecondaryConstructor.getOrCreateBody(): KtBlockExpression {
bodyExpression?.let { return it }
val delegationCall = getDelegationCall()
val anchor = if (delegationCall.isImplicit) valueParameterList else delegationCall
val newBody = KtPsiFactory(project).createEmptyBody()
return addAfter(newBody, anchor) as KtBlockExpression
}
fun KtParameter.dropDefaultValue() {
val from = equalsToken ?: return
val to = defaultValue ?: from
@@ -19,12 +19,12 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester
import org.jetbrains.kotlin.idea.base.psi.getOrCreateBody
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.codeInsight.shorten.runRefactoringAndKeepDelayedRequests
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction
import org.jetbrains.kotlin.idea.core.getOrCreateBody
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.refactoring.CompositeRefactoringRunner
import org.jetbrains.kotlin.idea.refactoring.addElement
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
@@ -10117,6 +10117,11 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
runTest("testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNameClashInPrimaryConstructor.kt");
}
@TestMetadata("memberPropertyInClassNameClashInPrimaryConstructor2.kt")
public void testMemberPropertyInClassNameClashInPrimaryConstructor2() throws Exception {
runTest("testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNameClashInPrimaryConstructor2.kt");
}
@TestMetadata("memberPropertyInClassNameClashInSecondaryConstructor.kt")
public void testMemberPropertyInClassNameClashInSecondaryConstructor() throws Exception {
runTest("testData/quickfix/initializeWithConstructorParameter/memberPropertyInClassNameClashInSecondaryConstructor.kt");
@@ -10177,6 +10182,21 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
runTest("testData/quickfix/initializeWithConstructorParameter/multipleConstructors.kt");
}
@TestMetadata("multipleConstructorsClash.kt")
public void testMultipleConstructorsClash() throws Exception {
runTest("testData/quickfix/initializeWithConstructorParameter/multipleConstructorsClash.kt");
}
@TestMetadata("multipleConstructorsClash2.kt")
public void testMultipleConstructorsClash2() throws Exception {
runTest("testData/quickfix/initializeWithConstructorParameter/multipleConstructorsClash2.kt");
}
@TestMetadata("namelessProperty.kt")
public void testNamelessProperty() throws Exception {
runTest("testData/quickfix/initializeWithConstructorParameter/namelessProperty.kt");
}
@TestMetadata("topLevelProperty.kt")
public void testTopLevelProperty() throws Exception {
runTest("testData/quickfix/initializeWithConstructorParameter/topLevelProperty.kt");
@@ -1,14 +1,6 @@
// "Initialize with constructor parameter" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Apply all 'Add modifier' fixes in file
// ACTION: Convert member to extension
// ACTION: Convert property to function
// ACTION: Introduce backing property
// ACTION: Make 'b' 'abstract'
// ACTION: Move to companion object
// IGNORE_IRRELEVANT_ACTIONS
// ERROR: Property must be initialized or be abstract
// IGNORE_K2
actual class SimpleWConstructor {
val <caret>b: String
@@ -1,14 +1,6 @@
// "Initialize with constructor parameter" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Apply all 'Add modifier' fixes in file
// ACTION: Convert member to extension
// ACTION: Convert property to function
// ACTION: Introduce backing property
// ACTION: Make 'b' 'abstract'
// ACTION: Move to companion object
// IGNORE_IRRELEVANT_ACTIONS
// ERROR: Property must be initialized or be abstract
// IGNORE_K2
actual class SimpleWConstructor {
actual val <caret>b: String
@@ -1,14 +1,6 @@
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Apply all 'Add modifier' fixes in file
// ACTION: Convert member to extension
// ACTION: Convert property to function
// ACTION: Introduce backing property
// ACTION: Make 'b' 'abstract'
// ACTION: Move to companion object
// IGNORE_IRRELEVANT_ACTIONS
// ERROR: Property must be initialized or be abstract
// IGNORE_K2
actual class SimpleWConstructor actual constructor(i: Int) {
val <caret>b: String
@@ -1,14 +1,6 @@
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Apply all 'Add modifier' fixes in file
// ACTION: Convert member to extension
// ACTION: Convert property to function
// ACTION: Introduce backing property
// ACTION: Make 'b' 'abstract'
// ACTION: Move to companion object
// IGNORE_IRRELEVANT_ACTIONS
// ERROR: Property must be initialized or be abstract
// IGNORE_K2
actual class SimpleWConstructor actual constructor(i: Int) {
actual val <caret>b: String
@@ -0,0 +1,13 @@
// "Initialize with constructor parameter" "true"
open class RGrandAccessor(x: Int) {}
open class RAccessor : RGrandAccessor {
<caret>val f: Int
constructor(p: Boolean, f: Int) : super(1) {
this.f = f
}
constructor(p: String, f: Int) : this(true, f)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -6,4 +6,5 @@ open class RAccessor : RGrandAccessor {
constructor(p: Boolean) : super(1)
constructor(p: String) : this(true)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ open class RAccessor : RGrandAccessor {
constructor(p: String) : this(true, 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ abstract class Form<T>(val name: String){
abstract protected fun processData(data: T)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ abstract class Form<T>(val name: String, data: T?){
abstract protected fun processData(data: T)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -1,4 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// "Initialize with constructor parameter" "false"
fun test() {
<caret>val n: Int
}
@@ -9,4 +9,5 @@ class B : A(0)
fun test() {
val a = A(0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ class B : A(0, 0)
fun test() {
val a = A(0, 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,10 @@
// IGNORE_K1
// "Initialize with constructor parameter" "true"
val n: Int = 1
class A(m: Int = n) {
<caret>var n: Int
get() = 1
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,10 @@
// IGNORE_K1
// "Initialize with constructor parameter" "true"
val n: Int = 1
class A(m: Int = n, n1: Int) {
var n: Int = n1
get() = 1
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -10,4 +10,5 @@ class B : A(1)
fun test() {
val a = A(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -12,4 +12,5 @@ class B : A(1, 0)
fun test() {
val a = A(1, 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ class B : A()
fun test() {
val a = A()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ class B : A(0)
fun test() {
val a = A(0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,16 @@
// "Initialize with constructor parameter" "true"
open class A(s: String, n: Int) {
var n: Int = n
get() = 1
constructor(n: Int) : this("", n)
constructor(a: Int, n: Int): this("" + a, n)
}
class B : A("", 0)
fun test() {
val a = A("", 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -12,4 +12,5 @@ class B : A("")
fun test() {
val a = A("")
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -12,4 +12,5 @@ class B : A("", 0)
fun test() {
val a = A("", 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ class B : A("")
fun test() {
val a = A("")
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -9,4 +9,5 @@ class B : A("", 0)
fun test() {
val a = A("", 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -17,4 +17,5 @@ fun test() {
val a = A("")
val aa = A(1)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -20,4 +20,5 @@ fun test() {
val a = A("", 0)
val aa = A(1, 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -1,7 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
// "Initialize with constructor parameter" "false"
interface A {
<caret>val n: Int
}
@@ -1,6 +1,6 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// ACTION: Initialize property 'n'
// ACTION: Make 'n' abstract
// "Initialize with constructor parameter" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Make internal
// ACTION: Make private
// ERROR: Property must be initialized or be abstract
@@ -1,4 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// "Initialize with constructor parameter" "false"
// ERROR: Property must be initialized or be abstract
open class A {
<caret>val n: Int
@@ -0,0 +1,15 @@
// "Initialize with constructor parameter" "true"
open class A(s: String, n: Int) {
val n: Int = n
constructor(n: Int) : this("", n)
constructor(a: Int, n: Int): this("" + a, n)
}
class B : A("", 0)
fun test() {
val a = A("", 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -1,4 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// "Initialize with constructor parameter" "false"
// ERROR: Property must be initialized or be abstract
open class A(s: String) {
<caret>val n: Int
@@ -1,4 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// "Initialize with constructor parameter" "false"
// ERROR: Property must be initialized or be abstract
open class A(s: String) {
<caret>val n: Int
@@ -1,4 +1,5 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// "Initialize with constructor parameter" "false"
// ACTION: Convert to ordinary property
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
@@ -6,4 +6,5 @@ class User {
val userN<caret>ame: String
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -11,4 +11,5 @@ class User {
val userN<caret>ame: String
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,13 @@
// IGNORE_K1
// "Initialize with constructor parameter" "true"
class User {
constructor()
constructor(blah: String): this()
constructor(blah: String, n: Int, default: Int = 2)
constructor(d: Double): this("", 1)
constructor(n: Int)
val userN<caret>ame: String
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,21 @@
// IGNORE_K1
// "Initialize with constructor parameter" "true"
class User {
constructor(userName: String) {
this.userName = userName
}
constructor(blah: String, userName: String): this(userName)
constructor(blah: String, n: Int, default: Int = 2, userName: String) {
this.userName = userName
}
constructor(d: Double, userName: String): this("", 1, userName = userName)
constructor(n: Int, userName: String) {
this.userName = userName
}
val userN<caret>ame: String
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,9 @@
// IGNORE_K1
// "Initialize with constructor parameter" "true"
class User(n: Int) {
constructor(n: Int, s: String) : this(n)
val userN<caret>ame: String
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,9 @@
// IGNORE_K1
// "Initialize with constructor parameter" "true"
class User(n: Int, userName: String) {
constructor(n: Int, s: String, userName: String) : this(n, userName)
val userN<caret>ame: String = userName
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$InitializeWithConstructorParameterFix
@@ -0,0 +1,6 @@
// "Initialize with constructor parameter" "false"
// ERROR: Property must be initialized
class A {
<caret>var : Int
get() = 1
}
@@ -1,5 +1,6 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$InitializeWithConstructorParameter" "false"
// ACTION: Initialize property 'n'
// "Initialize with constructor parameter" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Make internal
// ACTION: Make private
// ERROR: Property must be initialized
@@ -1,6 +1,7 @@
// "Add 'lateinit' modifier" "false"
// ACTION: Add initializer
// ACTION: Make 'a' 'abstract'
// ACTION: Initialize with constructor parameter
// ACTION: Move to constructor parameters
// ACTION: Move to constructor
// ACTION: Add getter
@@ -4,6 +4,7 @@
// ACTION: Add full qualifier
// ACTION: Introduce import alias
// ACTION: Make 'a' 'abstract'
// ACTION: Initialize with constructor parameter
// ACTION: Move to constructor parameters
// ACTION: Move to constructor
// ACTION: Add getter
@@ -1,4 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// "Move to constructor parameters" "false"
fun test() {
<caret>val n: Int
}
@@ -1,8 +1,9 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// ACTION: Make 'n' abstract
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
// ACTION: Move to constructor
// ERROR: Extension property must have accessors or be abstract
class A {
<caret>val Int.n: Int
@@ -7,4 +7,5 @@ open class A(n: Int) {
fun test() {
val a = A(0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -8,4 +8,5 @@ class B : A()
fun test() {
val a = A()
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -7,4 +7,5 @@ class B : A(0)
fun test() {
val a = A(0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -1,10 +1,11 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// ACTION: Initialize property 'n'
// ACTION: Make 'n' abstract
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Initialize with constructor parameter
// ACTION: Make 'n' 'abstract'
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
// ACTION: Initialize with constructor parameter
// ERROR: Property must be initialized or be abstract
open class A(x: Int)
@@ -1,10 +1,11 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// ACTION: Initialize property 'n'
// ACTION: Make 'n' abstract
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Initialize with constructor parameter
// ACTION: Make 'n' 'abstract'
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
// ACTION: Initialize with constructor parameter
// ERROR: Property must be initialized or be abstract
open class A
@@ -10,4 +10,5 @@ class B : A("")
fun test() {
val a = A("")
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -9,4 +9,5 @@ class B : A("", 0)
fun test() {
val a = A("", 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -1,7 +1,4 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
// "Move to constructor parameters" "false"
interface A {
<caret>val n: Int
}
@@ -1,6 +1,6 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// ACTION: Initialize property 'n'
// ACTION: Make 'n' abstract
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Make internal
// ACTION: Make private
// ERROR: Property must be initialized or be abstract
@@ -1,4 +1,5 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// "Move to constructor parameters" "false"
// ACTION: Convert to ordinary property
// ACTION: Make internal
// ACTION: Make private
// ACTION: Make protected
@@ -10,4 +10,5 @@ class B : A("")
fun test() {
val a = A("")
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -9,4 +9,5 @@ class B : A("", 0)
fun test() {
val a = A("", 0)
}
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.InitializePropertyQuickFixFactories$MoveToConstructorParametersFix
@@ -1,5 +1,6 @@
// "class org.jetbrains.kotlin.idea.quickfix.InitializePropertyQuickFixFactory$MoveToConstructorParameters" "false"
// ACTION: Initialize property 'n'
// "Move to constructor parameters" "false"
// ACTION: Add getter
// ACTION: Add initializer
// ACTION: Make internal
// ACTION: Make private
// ERROR: Property must be initialized
@@ -123,7 +123,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
model("$idea/quickfix/implement", pattern = pattern)
model("$idea/quickfix/importAlias", pattern = pattern, isIgnored = true)
model("$idea/quickfix/increaseVisibility", pattern = pattern)
model("$idea/quickfix/initializeWithConstructorParameter", pattern = pattern, isIgnored = true)
model("$idea/quickfix/initializeWithConstructorParameter", pattern = pattern)
model("$idea/quickfix/inlineClass", pattern = pattern)
model("$idea/quickfix/inlineTypeParameterFix", pattern = pattern, isIgnored = true)
model("$idea/quickfix/insertDelegationCall", pattern = pattern)
@@ -141,7 +141,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
model("$idea/quickfix/missingConstructorBrackets", pattern = pattern)
model("$idea/quickfix/moveMemberToCompanionObject", pattern = pattern, isIgnored = true)
model("$idea/quickfix/moveReceiverAnnotation", pattern = pattern)
model("$idea/quickfix/moveToConstructorParameters", pattern = pattern, isIgnored = true)
model("$idea/quickfix/moveToConstructorParameters", pattern = pattern)
model("$idea/quickfix/moveToSealedParent", pattern = pattern, isIgnored = true)
model("$idea/quickfix/moveTypeAliasToTopLevel", pattern = pattern)
model("$idea/quickfix/obsoleteKotlinJsPackages", pattern = pattern, isIgnored = true)