"Convert property to function" intention should warn about the property overloads at child class constructor
#KT-29764 Fixed
This commit is contained in:
+10
-4
@@ -39,11 +39,9 @@ import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -108,6 +106,14 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
||||
conflicts.putValue(callable, "Can't modify $renderedCallable")
|
||||
}
|
||||
|
||||
if (callable is KtParameter) {
|
||||
conflicts.putValue(
|
||||
callable,
|
||||
if (callable.hasActualModifier()) "Property has an actual declaration in the class constructor"
|
||||
else "Property overloaded in child class constructor"
|
||||
)
|
||||
}
|
||||
|
||||
if (callable is KtProperty) {
|
||||
callableDescriptor.getContainingScope()
|
||||
?.findFunction(callableDescriptor.name, NoLookupLocation.FROM_IDE) { it.valueParameters.isEmpty() }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// SHOULD_FAIL_WITH: Property overloaded in child class constructor
|
||||
package test
|
||||
|
||||
open class Parent() {
|
||||
open val <caret>o: String = ""
|
||||
}
|
||||
|
||||
class Child(override val o: String) : Parent()
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Convert property to function" "true"
|
||||
// SHOULD_FAIL_WITH: Property has an actual declaration in the class constructor
|
||||
|
||||
expect class Main {
|
||||
val name<caret>: String
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
actual class Main(
|
||||
actual val name: String
|
||||
)
|
||||
@@ -6528,6 +6528,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/convertPropertyToFunction/overrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overrides2.kt")
|
||||
public void testOverrides2() throws Exception {
|
||||
runTest("idea/testData/intentions/convertPropertyToFunction/overrides2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyCallGroovy.kt")
|
||||
public void testPropertyCallGroovy() throws Exception {
|
||||
runTest("idea/testData/intentions/convertPropertyToFunction/propertyCallGroovy.kt");
|
||||
|
||||
+5
@@ -199,6 +199,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
||||
runTest("idea/testData/multiModuleQuickFix/convertPropertyGetterToInitializer/");
|
||||
}
|
||||
|
||||
@TestMetadata("convertPropertyToFunction")
|
||||
public void testConvertPropertyToFunction() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/convertPropertyToFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("createClassFromUsageImport")
|
||||
public void testCreateClassFromUsageImport() throws Exception {
|
||||
runTest("idea/testData/multiModuleQuickFix/createClassFromUsageImport/");
|
||||
|
||||
Reference in New Issue
Block a user