Simplify for now works even if no variables are declared inside loop #KT-12145 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-05-17 17:33:46 +03:00
parent 46ac26147b
commit a56248a11a
20 changed files with 337 additions and 36 deletions
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
data class XY(val x: Int, val y: Int)
fun test(xys: Array<XY>) {
for (xy in xys) {
val x = xy.x
println(x)
val y = xy.y + x
println(y)
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
val xx = xy.x
println(xx + xy.y)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for ((xx, y) in xys) {
println(xx + y)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
println(xy.x + xy.y)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for ((x, y) in xys) {
println(x + y)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
println(xy.x + xy.y + xy?.x + xy?.y)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for ((x, y) in xys) {
println(x + y + x + y)
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
println(xy.x + xy.y)
val xyx = xy.x
println(xyx + xy.y)
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for ((xyx, y) in xys) {
println(xyx + y)
println(xyx + y)
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
val y = xy.y
println(xy.x + y)
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>) {
for ((x, y) in xys) {
println(x + y)
}
}
@@ -0,0 +1,9 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
data class XY(var x: String, val y: String)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
xy.x = xy.y
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>, base: XY) {
for (<caret>xy in xys) {
if (xy.x == base.x) {
println(xy.y)
}
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
data class XY(val x: String, val y: String)
fun test(xys: Array<XY>, base: XY) {
for ((x, y) in xys) {
if (x == base.x) {
println(y)
}
}
}
@@ -0,0 +1,10 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
data class XY(var x: Int, var y: Int)
fun test(xys: Array<XY>) {
for (<caret>xy in xys) {
xy.x++
xy.y--
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test(map: Map<String, Int>) {
for (<caret>entry in map.entries) {
if (entry.key == "my_name") println("My index is ${entry.value}")
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test(map: Map<String, Int>) {
for ((key, value) in map) {
if (key == "my_name") println("My index is ${value}")
}
}
@@ -71,4 +71,68 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify 'for' using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassNoVariablesInside.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassNoVariablesInside.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassNoVariablesMultiUsages.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassNoVariablesMultiUsages.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassPropertyBetweenUsages.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassPropertyBetweenUsages.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassSecondVariable.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassSecondVariable.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassWithExternalUsage.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassWithExternalUsage.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassDependentLocal.kt</file>
<line>6</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassDependentLocal.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>DataClassFirstVariable.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/DataClassFirstVariable.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
<problem>
<file>MapNoProperties.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/MapNoProperties.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'for' that can be simplified using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
</problems>