Introduce Property: Place property before its usages

This commit is contained in:
Alexey Sedunov
2015-03-02 19:44:13 +03:00
parent ada5ffee57
commit 5ae9bb600c
14 changed files with 49 additions and 48 deletions
@@ -86,9 +86,10 @@ data class ExtractionData(
val project: Project = originalFile.getProject()
val originalElements: List<PsiElement> = originalRange.elements
val insertBefore: Boolean = targetSibling.getStrictParentOfType<JetDeclaration>()?.let {
it is JetDeclarationWithBody || it is JetClassInitializer
} ?: false
val insertBefore: Boolean = options.extractAsProperty
|| targetSibling.getStrictParentOfType<JetDeclaration>()?.let {
it is JetDeclarationWithBody || it is JetClassInitializer
} ?: false
fun getExpressions(): List<JetExpression> = originalElements.filterIsInstance<JetExpression>()
@@ -3,15 +3,15 @@ import kotlin.properties.Delegates
// WITH_RUNTIME
// EXTRACTION_TARGET: lazy property
class A {
fun foo(): Int {
val b = i
val c = b - 1
}
private val i: Int by Delegates.lazy {
val a = 1 + 2
val b = a * 2
b
}
fun foo(): Int {
val b = i
val c = b - 1
}
}
@@ -6,12 +6,12 @@ import kotlin.properties.Delegates
class A(val n: Int = 1) {
val m: Int = 2
fun foo(): Int {
return i
}
private val i: Int by Delegates.lazy {
m + n + 1
}
fun foo(): Int {
return i
}
}
@@ -5,10 +5,10 @@ import kotlin.properties.Delegates
val n: Int = 1
fun foo(): Int {
return i
}
private val i: Int by Delegates.lazy {
n + 1
}
fun foo(): Int {
return i
}
@@ -6,15 +6,15 @@ import kotlin.properties.Delegates
class A(val n: Int = 1) {
val m: Int = 2
private val i: Int by Delegates.lazy {
println(n)
m + n + 1
}
fun foo(): Int {
return if (n > 1) {
i
} else 0
}
private val i: Int by Delegates.lazy {
println(n)
m + n + 1
}
}
@@ -2,10 +2,10 @@
class A {
val i = 1
private val i1 = 1 + 2
fun foo(): Int {
return i1
}
private val i1 = 1 + 2
}
@@ -1,9 +1,9 @@
// EXTRACTION_TARGET: property with initializer
val i = 1
private val i1 = 1 + 2
fun foo(): Int {
return i1
}
private val i1 = 1 + 2
@@ -1,15 +1,15 @@
// EXTRACTION_TARGET: property with getter
class A {
fun foo(): Int {
val b = i
val c = b - 1
}
private val i: Int
get() {
val a = 1 + 2
val b = a * 2
return b
}
fun foo(): Int {
val b = i
val c = b - 1
}
}
@@ -2,13 +2,13 @@
class A(val n: Int = 1) {
val m: Int = 2
fun foo(): Int {
return i
}
private val i: Int
get() {
return m + n + 1
}
fun foo(): Int {
return i
}
}
@@ -1,11 +1,11 @@
// EXTRACTION_TARGET: property with getter
val n: Int = 1
fun foo(): Int {
return i
}
private val i: Int
get() {
return n + 1
}
}
fun foo(): Int {
return i
}
@@ -3,12 +3,12 @@
class A(val n: Int = 1) {
val m: Int = 2
private val i = m + n + 1
fun foo(): Int {
return if (n > 1) {
i
} else 0
}
private val i = m + n + 1
}
@@ -3,10 +3,10 @@
class A(val n: Int = 1) {
val m: Int = 2
private val i = m + n + 1
fun foo(): Int {
return i
}
private val i = m + n + 1
}
@@ -2,8 +2,8 @@
val n: Int = 1
private val i = n + 1
fun foo(): Int {
return i
}
private val i = n + 1
}
@@ -1,11 +1,11 @@
// EXTRACTION_TARGET: property with initializer
class A(val n: Int) {
private val i = n + 1
fun foo(k: Int) {
val a = i
val b = i - 2
val c = foo(i)
}
private val i = n + 1
}