File tree 2 files changed +46
-1
lines changed
src/org/jetbrains/plugins/scala/autoImport/quickFix
test/org/jetbrains/plugins/scala/lang/autoImport 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import org.jetbrains.plugins.scala.lang.psi.api.ScalaFile
18
18
import org .jetbrains .plugins .scala .lang .psi .api .base .ScReference
19
19
import org .jetbrains .plugins .scala .lang .psi .api .base .types .{ScSimpleTypeElement , ScTypeProjection }
20
20
import org .jetbrains .plugins .scala .lang .psi .api .expr .{ScMethodCall , ScSugarCallExpr }
21
- import org .jetbrains .plugins .scala .lang .psi .api .statements .{ScFunction , ScTypeAlias }
21
+ import org .jetbrains .plugins .scala .lang .psi .api .statements .{ScEnumCase , ScFunction , ScTypeAlias }
22
22
import org .jetbrains .plugins .scala .lang .psi .api .toplevel .templates .ScTemplateBody
23
23
import org .jetbrains .plugins .scala .lang .psi .api .toplevel .typedef ._
24
24
import org .jetbrains .plugins .scala .lang .psi .api .toplevel .{ScPackaging , ScTypedDefinition }
@@ -77,6 +77,7 @@ object ScalaImportTypeFix {
77
77
78
78
@ annotation.tailrec
79
79
private [this ] def notInner (clazz : PsiClass , ref : PsiElement ): Boolean = clazz match {
80
+ case enumCase : ScEnumCase => notInner(enumCase.enumParent, ref)
80
81
case o : ScObject if o.isSyntheticObject =>
81
82
val companion = getCompanionModule(o)
82
83
companion match {
Original file line number Diff line number Diff line change @@ -500,4 +500,48 @@ class Scala3ImportTypeFixTest extends ScalaImportTypeFixTestBase {
500
500
| """ .stripMargin,
501
501
" MyObject.MyEnumInClass"
502
502
)
503
+
504
+ def testEnumSingletonCase (): Unit = {
505
+ val fileText =
506
+ s """ enum Source:
507
+ | case Foo
508
+ |
509
+ |object Target:
510
+ | val foo = ${CARET }Foo
511
+ | """ .stripMargin
512
+ val qNameToImport = " Source.Foo"
513
+
514
+ checkElementsToImport(
515
+ fileText,
516
+ qNameToImport
517
+ )
518
+
519
+ doTest(
520
+ fileText,
521
+ expectedText = s " import $qNameToImport\n\n ${fileText.replace(CARET , " " )}" ,
522
+ selected = qNameToImport
523
+ )
524
+ }
525
+
526
+ def testEnumClassCase (): Unit = {
527
+ val fileText =
528
+ s """ enum Source:
529
+ | case Foo(i: Int)
530
+ |
531
+ |object Target:
532
+ | val foo = ${CARET }Foo(2)
533
+ | """ .stripMargin
534
+ val qNameToImport = " Source.Foo"
535
+
536
+ checkElementsToImport(
537
+ fileText,
538
+ qNameToImport
539
+ )
540
+
541
+ doTest(
542
+ fileText,
543
+ expectedText = s " import $qNameToImport\n\n ${fileText.replace(CARET , " " )}" ,
544
+ selected = qNameToImport
545
+ )
546
+ }
503
547
}
You can’t perform that action at this time.
0 commit comments