Enhancement for "join declaration and assignment": now can handle also local variables, relevant inspection added #KT-12095 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-11-17 16:02:19 +03:00
parent c44ecded42
commit 45e28bef1c
27 changed files with 244 additions and 61 deletions
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
fun foo(flag: Boolean) {
var x: Double<caret>
if (flag) {
x = 3.14
}
x = 2.71
}
@@ -1,7 +1,7 @@
class A {
var a: String?
var a<caret>: String?
init {
<caret>a = null
a = null
}
}
@@ -1,9 +1,9 @@
// WITH_RUNTIME
class A {
var a: List<String>
var a<caret>: List<String>
init {
<caret>a = emptyList()
a = emptyList()
}
}
@@ -1,7 +0,0 @@
class A {
val a: String?
init {
<caret>a = null
}
}
@@ -1,4 +0,0 @@
class A {
val a<selection>: String?</selection><caret> = null
}
@@ -0,0 +1,11 @@
// IS_APPLICABLE: false
fun bar() {
var x: <caret>String
fun foo() {
x = "456"
x.hashCode()
}
foo()
x = "123"
x.hashCode()
}
@@ -1,8 +1,8 @@
class A {
var a: Int
var a<caret>: Int
init {
// Initialize a
<caret>a = 1
a = 1
}
}
@@ -0,0 +1,4 @@
fun foo(flag: Boolean) {
val x: Double<caret>
x = if (flag) 3.14 else 2.71
}
@@ -0,0 +1,3 @@
fun foo(flag: Boolean) {
val x<selection>: Double</selection><caret> = if (flag) 3.14 else 2.71
}
@@ -1,7 +1,7 @@
class A {
var a: Int
var a<caret>: Int
init {
<caret>a = 1
a = 1
}
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
fun foo() {
val x: Double<caret>
val flag = false
x = if (flag) 3.14 else 2.71
}
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
class A {
constructor() {
a = 1
}
constructor(aa: Int) {
a = aa
}
val a<caret>: Int
}
@@ -0,0 +1,9 @@
class C {
var s<caret>: Int
init {
s = 1
s.hashCode()
s = 2
}
}
@@ -0,0 +1,8 @@
class C {
var s<selection>: Int</selection><caret> = 1
init {
s.hashCode()
s = 2
}
}
@@ -1,9 +1,9 @@
class A {
var a: Int
var a<caret>: Int
var b: Int
init {
<caret>a = 1
a = 1
b = 2
}
}
@@ -0,0 +1,4 @@
fun foo() {
val s: String<caret>
s = "Hello"
}
@@ -0,0 +1,3 @@
fun foo() {
val s<selection>: String</selection><caret> = "Hello"
}
@@ -0,0 +1,7 @@
class A {
constructor() {
a = 1
}
val a<caret>: Int
}
@@ -0,0 +1,6 @@
class A {
constructor() {
}
val a<selection>: Int</selection><caret> = 1
}
@@ -1,9 +1,9 @@
// IS_APPLICABLE: false
class A {
var b: Int
var b<caret>: Int
init {
val i = 0
b = <caret>i
b = i
}
}
@@ -0,0 +1,7 @@
// IS_APPLICABLE: false
fun foo() {
// It's possible here to join with assignment but move the result after declaration of i
var b<caret>: Int
val i = 0
b = i
}
@@ -0,0 +1,6 @@
fun foo() {
var s<caret>: Int
s = 1
s.hashCode()
s = 2
}
@@ -0,0 +1,5 @@
fun foo() {
var s<selection>: Int</selection><caret> = 1
s.hashCode()
s = 2
}