Initialize with Constructor Parameter Intention: Fix IDE freeze on properties in generic class
#KT-14459 Fixed
This commit is contained in:
@@ -334,6 +334,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
||||
- [`KT-14569`](https://youtrack.jetbrains.com/issue/KT-14569) Convert Property to Function Intention: Search occurrences using progress dialog
|
||||
- [`KT-14501`](https://youtrack.jetbrains.com/issue/KT-14501) Create from Usage: Support array access expressions/binary expressions with type mismatch errors
|
||||
- [`KT-14500`](https://youtrack.jetbrains.com/issue/KT-14500) Create from Usage: Suggest functional type based on the call with lambda argument and unresolved invoke()
|
||||
- [`KT-14459`](https://youtrack.jetbrains.com/issue/KT-14459) Initialize with Constructor Parameter: Fix IDE freeze on properties in generic class
|
||||
|
||||
#### Refactorings
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
||||
@@ -137,7 +138,9 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() {
|
||||
val classDescriptor = propertyDescriptor.containingDeclaration as ClassDescriptorWithResolutionScopes
|
||||
val constructorScope = classDescriptor.scopeForClassHeaderResolution
|
||||
val validator = CollectingNameValidator(originalDescriptor.parameters.map { it.name }) { name ->
|
||||
constructorScope.getContributedDescriptors(DescriptorKindFilter.VARIABLES, { it.asString() == name }).isEmpty()
|
||||
constructorScope.getContributedDescriptors(DescriptorKindFilter.VARIABLES).all {
|
||||
it !is VariableDescriptor || it.name.asString() != name
|
||||
}
|
||||
}
|
||||
val initializerText = CodeInsightUtils.defaultInitializer(propertyDescriptor.type) ?: "null"
|
||||
val newParam = KotlinParameterInfo(
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Initialize with constructor parameter" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class Form<T>(val name: String){
|
||||
var <caret>data: T?
|
||||
set(value){
|
||||
value?.let { processData(it) }
|
||||
field = data
|
||||
}
|
||||
|
||||
abstract protected fun processData(data: T)
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Initialize with constructor parameter" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class Form<T>(val name: String, data: T?){
|
||||
var <caret>data: T? = data
|
||||
set(value){
|
||||
value?.let { processData(it) }
|
||||
field = data
|
||||
}
|
||||
|
||||
abstract protected fun processData(data: T)
|
||||
}
|
||||
@@ -5516,6 +5516,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("genericParameterInScope.kt")
|
||||
public void testGenericParameterInScope() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/initializeWithConstructorParameter/genericParameterInScope.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localVar.kt")
|
||||
public void testLocalVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/initializeWithConstructorParameter/localVar.kt");
|
||||
|
||||
Reference in New Issue
Block a user