Fix KNPE in "Move member to companion" for expect class #KT-28383 Fixed
This commit is contained in:
+5
-3
@@ -161,11 +161,11 @@ class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntention<KtNamed
|
||||
val javaCodeStyleManager = JavaCodeStyleManager.getInstance(project)
|
||||
|
||||
val companionObject = containingClass.getOrCreateCompanionObject()
|
||||
val companionLightClass = companionObject.toLightClass()!!
|
||||
val companionLightClass = companionObject.toLightClass()
|
||||
|
||||
val ktPsiFactory = KtPsiFactory(project)
|
||||
val javaPsiFactory = JavaPsiFacade.getInstance(project).elementFactory
|
||||
val javaCompanionRef = javaPsiFactory.createReferenceExpression(companionLightClass)
|
||||
val javaCompanionRef = companionLightClass?.let { javaPsiFactory.createReferenceExpression(it) }
|
||||
val ktCompanionRef = ktPsiFactory.createExpression(companionObject.fqName!!.asString())
|
||||
|
||||
val elementsToShorten = SmartList<KtElement>()
|
||||
@@ -217,10 +217,12 @@ class MoveMemberToCompanionObjectIntention : SelfTargetingRangeIntention<KtNamed
|
||||
|
||||
when (usage) {
|
||||
is JavaUsageInfo -> {
|
||||
(usageElement as? PsiReferenceExpression)
|
||||
if (javaCompanionRef != null) {
|
||||
(usageElement as? PsiReferenceExpression)
|
||||
?.qualifierExpression
|
||||
?.replace(javaCompanionRef)
|
||||
?.let { javaCodeStyleManager.shortenClassReferences(it) }
|
||||
}
|
||||
}
|
||||
|
||||
is ExplicitReceiverUsageInfo -> {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly
|
||||
|
||||
expect class Some {
|
||||
val <caret>x: Int
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// ERROR: The feature "multi platform projects" is experimental and should be enabled explicitly
|
||||
|
||||
expect class Some {
|
||||
companion object {
|
||||
val x: Int
|
||||
}
|
||||
}
|
||||
@@ -12133,6 +12133,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/moveToCompanion/enumEntry.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expectClass.kt")
|
||||
public void testExpectClass() throws Exception {
|
||||
runTest("idea/testData/intentions/moveToCompanion/expectClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithOverride.kt")
|
||||
public void testFunctionWithOverride() throws Exception {
|
||||
runTest("idea/testData/intentions/moveToCompanion/functionWithOverride.kt");
|
||||
|
||||
Reference in New Issue
Block a user