CreateTypeParameterFromUsageFix: fix KNPE for type alias
#KT-33302 Fixed #EA-120181 Fixed
This commit is contained in:
@@ -489,9 +489,10 @@ fun KtTypeParameterListOwner.addTypeParameter(typeParameter: KtTypeParameter): K
|
||||
val list = KtPsiFactory(this).createTypeParameterList("<X>")
|
||||
list.parameters[0].replace(typeParameter)
|
||||
val leftAnchor = when (this) {
|
||||
is KtClass -> nameIdentifier ?: getClassOrInterfaceKeyword()
|
||||
is KtClass -> nameIdentifier
|
||||
is KtNamedFunction -> funKeyword
|
||||
is KtProperty -> valOrVarKeyword
|
||||
is KtTypeAlias -> nameIdentifier
|
||||
else -> null
|
||||
} ?: return null
|
||||
return (addAfter(list, leftAnchor) as KtTypeParameterList).parameters.first()
|
||||
|
||||
+2
-1
@@ -97,7 +97,8 @@ class CreateTypeParameterFromUsageFix(
|
||||
} else null
|
||||
val upperBound = upperBoundText?.let { psiFactory.createType(it) }
|
||||
val newTypeParameterText = if (upperBound != null) "${typeParameter.name} : ${upperBound.text}" else typeParameter.name
|
||||
val newTypeParameter = declaration.addTypeParameter(psiFactory.createTypeParameter(newTypeParameterText))!!
|
||||
val newTypeParameter = declaration.addTypeParameter(psiFactory.createTypeParameter(newTypeParameterText))
|
||||
?: error("Couldn't create type parameter from '$newTypeParameterText' for '$declaration'")
|
||||
elementsToShorten += newTypeParameter
|
||||
|
||||
val anonymizedTypeParameter = createFakeTypeParameterDescriptor(typeParameter.fakeTypeParameter.containingDeclaration, "_")
|
||||
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// "Create type parameter in type alias 'G'" "true"
|
||||
|
||||
class C
|
||||
typealias G = C
|
||||
|
||||
fun <T> a(g: G<T<caret>>) = Unit
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Create type parameter in type alias 'G'" "true"
|
||||
|
||||
class C
|
||||
typealias G<T> = C
|
||||
|
||||
fun <T> a(g: G<T>) = Unit
|
||||
@@ -4780,6 +4780,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
public void testNotOnTypeArgumentList() throws Exception {
|
||||
runTest("idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/notOnTypeArgumentList.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typealias.kt")
|
||||
public void testTypealias() throws Exception {
|
||||
runTest("idea/testData/quickfix/createFromUsage/createTypeParameter/inReferencedDeclaration/typealias.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user