Intention to simplify for using destructing declaration

This commit is contained in:
Natalia Ukhorskaya
2016-01-13 14:47:02 +03:00
parent 5667a92472
commit ea3ba6f534
34 changed files with 631 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.SimplifyForIntention
@@ -0,0 +1,10 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>(key, value) in map) {
println(key)
println(value)
}
}
@@ -0,0 +1,13 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (entry <caret>in map) {
val key = entry.key
val value = entry.value
println(key)
println(value)
}
}
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
for (<caret>klass in list) {
val a = klass.a
val b = klass.b
val c = klass.c
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
for ((a, b, c) in list) {
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,11 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
for (<caret>klass in list) {
val a = klass.a
val b = klass.b
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
for ((a, b) in list) {
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3, 4))
for (<caret>klass in list) {
val a = klass.a
val c = klass.c
}
}
data class MyClass(val a: Int, val b: Int, val c: Int, val d: Int)
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
for (<caret>klass in list) {
val a1 = klass.a
val c1 = klass.c
val b1 = klass.b
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val list = listOf(MyClass(1, 2, 3), MyClass(2, 3, 4))
for ((a1, b1, c1) in list) {
}
}
data class MyClass(val a: Int, val b: Int, val c: Int)
@@ -0,0 +1,13 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
val entries = map.entries
for (<caret>entry in entries) {
val key = entry.key
val value = entry.value
println(key)
println(value)
}
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
val entries = map.entries
for ((key, value) in entries) {
println(key)
println(value)
}
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>entry in map.entrySet()) {
val key = entry.getKey()
val value = entry.getValue()
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for ((key, value) in map) {
}
}
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>entry in map) {
val key = entry.key
val key2 = entry.key
println(key)
}
}
@@ -0,0 +1,13 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>entry in map) {
val myKey = entry.key
val myValue = entry.value
println(entry)
}
}
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>entry in map) {
val myKey = entry.key
println(entry)
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>entry in map) {
val myKey = entry.key
val myValue = entry.value
}
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for ((myKey, myValue) in map) {
}
}
+12
View File
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for (<caret>entry in map) {
val key = entry.key
val value = entry.value
println(key)
println(value)
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
val map = hashMapOf(1 to 1)
for ((key, value) in map) {
println(key)
println(value)
}
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
for (<caret>entry in 1.createListOfDataClasses()) {
val int1 = entry.a
val int2 = entry.b
}
}
fun Int.createListOfDataClasses() = listOf(MyClass(this, this))
data class MyClass(val a: Int, val b: Int)
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun main(args: Array<String>) {
for ((int1, int2) in 1.createListOfDataClasses()) {
}
}
fun Int.createListOfDataClasses() = listOf(MyClass(this, this))
data class MyClass(val a: Int, val b: Int)
@@ -0,0 +1,74 @@
<problems>
<problem>
<file>SomeQualifiedExpressionInRange.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="SomeQualifiedExpressionInRange.kt" />
<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>Simple.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="Simple.kt" />
<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>PropertiesNames.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="PropertiesNames.kt" />
<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>Getters.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="Getters.kt" />
<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>DataClassParametersOrder.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="DataClassParametersOrder.kt" />
<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>DataClass.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="DataClass.kt" />
<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>EntriesCallIsMissing.kt</file>
<line>6</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="EntriesCallIsMissing.kt" />
<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>DataClassFirstNPropertiesUsed.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="DataClassFirstNPropertiesUsed.kt" />
<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>CaretOffset.kt</file>
<line>6</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="CaretOffset.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify 'for' using destructing declaration</problem_class>
<description>Simplify 'for' using destructing declaration</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.SimplifyForInspection