Intentions: Implement "Convert sealed class to enum" intention
#KT-14245 Fixed
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ConvertSealedClassToEnumIntention
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
sealed class <caret>MyClass {
|
||||
object FOO : MyClass()
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
enum class <caret>MyClass {
|
||||
FOO
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// SHOULD_FAIL_WITH: All inheritors must be nested objects of the class itself and may not inherit from other classes or interfaces. Following problems are found: object <b><code>A</code></b>
|
||||
|
||||
interface I
|
||||
|
||||
sealed class <caret>X {
|
||||
object A : X(), I
|
||||
object B : X()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
sealed class <caret>MyClass(val s: String = "") {
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
|
||||
object FOO : MyClass("FOO")
|
||||
object BAR : MyClass("BAR")
|
||||
object DEFAULT : MyClass()
|
||||
}
|
||||
|
||||
fun test(e: MyClass) {
|
||||
if (e == MyClass.BAR) {
|
||||
println()
|
||||
}
|
||||
|
||||
val n = when (e) {
|
||||
MyClass.BAR -> 1
|
||||
MyClass.FOO -> 2
|
||||
MyClass.DEFAULT -> 0
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
enum class <caret>MyClass(val s: String = "") {
|
||||
FOO("FOO"), BAR("BAR"), DEFAULT();
|
||||
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun test(e: MyClass) {
|
||||
if (e == MyClass.BAR) {
|
||||
println()
|
||||
}
|
||||
|
||||
val n = when (e) {
|
||||
MyClass.BAR -> 1
|
||||
MyClass.FOO -> 2
|
||||
MyClass.DEFAULT -> 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
sealed class <caret>MyClass(val s: String = "") {
|
||||
object FOO : MyClass("FOO")
|
||||
object BAR : MyClass("BAR")
|
||||
object DEFAULT : MyClass()
|
||||
}
|
||||
|
||||
fun test(e: MyClass) {
|
||||
if (e == MyClass.BAR) {
|
||||
println()
|
||||
}
|
||||
|
||||
val n = when (e) {
|
||||
MyClass.BAR -> 1
|
||||
MyClass.FOO -> 2
|
||||
MyClass.DEFAULT -> 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
enum class <caret>MyClass(val s: String = "") {
|
||||
FOO("FOO"), BAR("BAR"), DEFAULT()
|
||||
}
|
||||
|
||||
fun test(e: MyClass) {
|
||||
if (e == MyClass.BAR) {
|
||||
println()
|
||||
}
|
||||
|
||||
val n = when (e) {
|
||||
MyClass.BAR -> 1
|
||||
MyClass.FOO -> 2
|
||||
MyClass.DEFAULT -> 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
sealed class <caret>MyEnum(val s: String = "") {
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
enum class MyEnum(val s: String = "") {
|
||||
;
|
||||
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// SHOULD_FAIL_WITH: All inheritors must be nested objects of the class itself and may not inherit from other classes or interfaces. Following problems are found: object <b><code>B</code></b>
|
||||
|
||||
sealed class <caret>X {
|
||||
object A : X()
|
||||
}
|
||||
|
||||
object B : X()
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
class <caret>X {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
<caret>private sealed class X {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// SHOULD_FAIL_WITH: All inheritors must be nested objects of the class itself and may not inherit from other classes or interfaces. Following problems are found: class <b><code>A</code></b>, class <b><code>B</code></b>
|
||||
|
||||
sealed class <caret>X {
|
||||
class A : X()
|
||||
}
|
||||
|
||||
class B : X()
|
||||
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: false
|
||||
|
||||
open class C
|
||||
|
||||
sealed class <caret>X : C() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user