KT-9839: intention introduced: convert secondary constructor to primary one #KT-9839 Fixed

(cherry picked from commit f3fa779)
This commit is contained in:
Mikhail Glukhikh
2016-09-29 16:47:35 +03:00
committed by Mikhail Glukhikh
parent 28b70faa99
commit 725df49c8c
44 changed files with 555 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.ConvertSecondaryConstructorToPrimaryIntention
@@ -0,0 +1,11 @@
class DefaultValueChain {
val x1: Int
val x3: Int
val x5: Int
<caret>constructor(x1: Int, x2: Int = x1, x3: Int = x2, x4: Int = x3, x5: Int = x4) {
this.x1 = x1
this.x3 = x3
this.x5 = x5
}
}
@@ -0,0 +1,3 @@
class DefaultValueChain(val x1: Int, x2: Int = x1, val x3: Int = x2, x4: Int = x3, val x5: Int = x4) {
}
@@ -0,0 +1,10 @@
class ConvertToInit {
fun foo() {}
fun bar() {}
constructor(<caret>) {
foo()
bar()
}
}
@@ -0,0 +1,11 @@
class ConvertToInit() {
fun foo() {}
fun bar() {}
init {
foo()
bar()
}
}
@@ -0,0 +1,15 @@
class InitAndParams {
constructor<caret>(x: Int, z: Int) {
this.y = x
w = foo(y)
this.v = w + z
}
val y: Int
val w: Int
fun foo(arg: Int) = arg
val v: Int
}
@@ -0,0 +1,15 @@
class InitAndParams(x: Int, z: Int) {
val y: Int = x
val w: Int
fun foo(arg: Int) = arg
val v: Int
init {
w = foo(y)
this.v = w + z
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
class NonReachableConstructor {
constructor<caret>(x: String)
constructor(x: Int)
}
@@ -0,0 +1,11 @@
// IS_APPLICABLE: false
// ERROR: There's a cycle in the delegation calls chain
// ERROR: There's a cycle in the delegation calls chain
class NonReachableLoop {
constructor<caret>(x: String)
constructor(x: Int, y: Int): this(x + y)
constructor(x: Int): this(x, x)
}
@@ -0,0 +1,7 @@
class Protected {
internal var s: String
protected <caret>constructor(s: String) {
this.s = s
}
}
@@ -0,0 +1,3 @@
class Protected protected constructor(internal var s: String) {
}
@@ -0,0 +1,3 @@
class Simple {
constructor<caret>()
}
@@ -0,0 +1,2 @@
class Simple() {
}
@@ -0,0 +1,7 @@
class UseParam {
constructor<caret>(x: Int) {
this.y = x
}
val y: Int
}
@@ -0,0 +1,4 @@
class UseParam(x: Int) {
val y: Int = x
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
class WithVarArg {
val x: List<String>
constructor(<caret>vararg zz: String) {
x = listOf(*zz)
}
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
class WithVarArg(vararg zz: String) {
val x: List<String>
init {
x = listOf(*zz)
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class VarargVal {
val param: Array<out String>
constructor<caret>(vararg param: String) {
this.param = param
}
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
class VarargVal(vararg val param: String) {
}
@@ -0,0 +1,5 @@
abstract class Base(val x: String)
class Derived : Base {
constructor(x: String<caret>): super(x)
}
@@ -0,0 +1,4 @@
abstract class Base(val x: String)
class Derived(x: String) : Base(x) {
}
@@ -0,0 +1,14 @@
interface Interface
interface Another
abstract class Base
class Derived : Interface, Base, Another {
val x: String
constructor(x: String<caret>): super() {
this.x = x
}
}
@@ -0,0 +1,9 @@
interface Interface
interface Another
abstract class Base
class Derived(val x: String) : Interface, Base(), Another {
}
@@ -0,0 +1,12 @@
annotation class AnnParam
annotation class AnnProperty
abstract class WithComposedModifiers {
@AnnProperty
open val x: Array<out String>
constructor<caret>(@AnnParam vararg x: String) {
this.x = x
}
}
@@ -0,0 +1,8 @@
annotation class AnnParam
annotation class AnnProperty
abstract class WithComposedModifiers(@AnnParam vararg @AnnProperty
open val x: String) {
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
class WithDelegation {
constructor()
constructor<caret>(x: Int): this()
}
@@ -0,0 +1,10 @@
class WithDifferentTypeProperty {
val x: Number
val y: String
constructor(x: Int, <caret>z: String) {
this.x = x
this.y = z
}
}
@@ -0,0 +1,6 @@
class WithDifferentTypeProperty(x: Int, z: String) {
val x: Number = x
val y: String = z
}
@@ -0,0 +1,6 @@
annotation class Ann
internal class WithModifiers {
@Ann
private constructor<caret>()
}
@@ -0,0 +1,4 @@
annotation class Ann
internal class WithModifiers @Ann private constructor() {
}
@@ -0,0 +1,3 @@
class WithParameters {
constructor(<caret>x: Int = 42, y: String = "Hello")
}
@@ -0,0 +1,2 @@
class WithParameters(x: Int = 42, y: String = "Hello") {
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// ERROR: Primary constructor call expected
class WithPrimary() {
constructor<caret>(x: Int)
}
@@ -0,0 +1,11 @@
class WithProperties {
val x: Int
val y: Int
private val z: Int
constructor(x: Int, y: Int = 7, z: Int = 13<caret>) {
this.x = x
this.y = y
this.z = z
}
}
@@ -0,0 +1,3 @@
class WithProperties(val x: Int, val y: Int = 7, private val z: Int = 13) {
}