Intention / inspection for unnecessary lateinit #KT-13011 Fixed

(cherry picked from commit 45d82f1)
This commit is contained in:
shiraji
2016-07-26 01:12:50 +03:00
committed by Mikhail Glukhikh
parent d868410093
commit 5fb79259f7
26 changed files with 428 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.RemoveUnnecessaryLateinitIntention
@@ -0,0 +1,9 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
<caret>lateinit var bar: String
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,9 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
var bar: String
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
// ERROR: None of the following functions can be called with the arguments supplied: <br>public constructor Foo() defined in Foo<br>public constructor Foo(x: String, y: String) defined in Foo
class Foo {
<caret>lateinit var x: String
constructor() {
x = "Foo"
}
constructor(x: String, y: String): this(y.hashCode())
}
@@ -0,0 +1,9 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
<caret>lateinit var bar: String
init {
bar = ""
}
}
@@ -0,0 +1,9 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
var bar: String
init {
bar = ""
}
}
@@ -0,0 +1,13 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,13 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
var bar: String
constructor() {
bar = ""
}
constructor(baz: Int) {
bar = ""
}
}
@@ -0,0 +1,15 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this() {
}
constructor(a: Int, b: Int) : this(a) {
}
}
@@ -0,0 +1,15 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this() {
}
constructor(a: Int, b: Int) : this(a) {
}
}
@@ -0,0 +1,14 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
<caret>lateinit var bar: String
var baz: Int
init {
baz = 1
}
init {
bar = ""
}
}
@@ -0,0 +1,14 @@
// INTENTION_TEXT: Remove unnecessary lateinit
class Foo {
var bar: String
var baz: Int
init {
baz = 1
}
init {
bar = ""
}
}
@@ -0,0 +1,9 @@
// IS_APPLICABLE: false
class Foo {
<caret>lateinit var bar: String
constructor(baz: Int) {
bar += baz
}
}
@@ -0,0 +1,9 @@
// IS_APPLICABLE: false
class Foo() {
<caret>lateinit var bar: String
constructor(baz: Int) : this() {
bar = ""
}
}
@@ -0,0 +1,9 @@
// IS_APPLICABLE: false
class Foo {
lateinit var bar: String
fun init() {
bar = ""
}
}
@@ -0,0 +1,14 @@
// IS_APPLICABLE: true
// ERROR: There's a cycle in the delegation calls chain
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this(a) {
bar = "a"
}
}
@@ -0,0 +1,14 @@
// IS_APPLICABLE: true
// ERROR: There's a cycle in the delegation calls chain
class Foo {
<caret>var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this(a) {
bar = "a"
}
}
@@ -0,0 +1,21 @@
// IS_APPLICABLE: false
// ERROR: There's a cycle in the delegation calls chain
// ERROR: There's a cycle in the delegation calls chain
// ERROR: There's a cycle in the delegation calls chain
class Foo {
<caret>lateinit var bar: String
constructor() {
bar = ""
}
constructor(a: Int) : this(a, 0, 0) {
}
constructor(a: Int, b: Int) : this(a) {
}
constructor(a: Int, b: Int, c: Int) : this(a, b) {
}
}
@@ -0,0 +1,14 @@
// IS_APPLICABLE: false
open class Bar(val a: Int = 0)
class Foo : Bar {
<caret>lateinit var bar: String
constructor() : super() {
bar = ""
}
constructor(a: Int) : super(a) {
}
}