mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Fix false Positive "Add constructor parameter" quickfix for value class
^KTIJ-16740 Fixed closes https://github.com/JetBrains/intellij-community/pull/2446 GitOrigin-RevId: f60af82b0daa5cef13b495f979be75ea9def45f8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3b147864f1
commit
1101873f41
+6
@@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
@@ -28,6 +29,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getType
|
||||
import org.jetbrains.kotlin.resolve.isValueClass
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
|
||||
@@ -91,6 +93,10 @@ abstract class ChangeFunctionSignatureFix(
|
||||
val arguments = originalElement.valueArguments
|
||||
|
||||
if (arguments.size > parameters.size) {
|
||||
if (functionDescriptor is ConstructorDescriptor &&
|
||||
functionDescriptor.containingDeclaration.isValueClass()
|
||||
) return null
|
||||
|
||||
val bindingContext = originalElement.analyze()
|
||||
val call = originalElement.getCall(bindingContext) ?: return null
|
||||
val argumentToParameter = call.mapArgumentsToParameters(functionDescriptor)
|
||||
|
||||
+10
@@ -2875,6 +2875,16 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
|
||||
runTest("testData/quickfix/changeSignature/addConstructorParameterForConstantTypeMismatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("addConstructorParameterForInlineClass.kt")
|
||||
public void testAddConstructorParameterForInlineClass() throws Exception {
|
||||
runTest("testData/quickfix/changeSignature/addConstructorParameterForInlineClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("addConstructorParameterForValueClass.kt")
|
||||
public void testAddConstructorParameterForValueClass() throws Exception {
|
||||
runTest("testData/quickfix/changeSignature/addConstructorParameterForValueClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("addEnumConstructorParameter.kt")
|
||||
public void testAddEnumConstructorParameter() throws Exception {
|
||||
runTest("testData/quickfix/changeSignature/addEnumConstructorParameter.kt");
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Add parameter to constructor 'Foo'" "false"
|
||||
// DISABLE-ERRORS
|
||||
// ACTION: Convert property initializer to getter
|
||||
// ACTION: Convert to lazy property
|
||||
// ACTION: Create function 'Foo'
|
||||
// ACTION: Create secondary constructor
|
||||
// ACTION: Put arguments on separate lines
|
||||
// ACTION: Remove argument
|
||||
inline class Foo(val i: Int)
|
||||
|
||||
val foo = Foo(10, 20<caret>)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Add parameter to constructor 'Foo'" "false"
|
||||
// DISABLE-ERRORS
|
||||
// ACTION: Convert property initializer to getter
|
||||
// ACTION: Convert to lazy property
|
||||
// ACTION: Create function 'Foo'
|
||||
// ACTION: Create secondary constructor
|
||||
// ACTION: Put arguments on separate lines
|
||||
// ACTION: Remove argument
|
||||
@JvmInline
|
||||
value class Foo(val i: Int)
|
||||
|
||||
val foo = Foo(10, 20<caret>)
|
||||
Reference in New Issue
Block a user