Introduce "redundant suspend" inspection #KT-19103 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-12-04 18:17:42 +03:00
parent edefb45585
commit 4404439521
9 changed files with 283 additions and 21 deletions
@@ -0,0 +1,67 @@
<problems>
<problem>
<file>test.kt</file>
<line>13</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<problem>
<file>test.kt</file>
<line>33</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<problem>
<file>test.kt</file>
<line>35</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<problem>
<file>test.kt</file>
<line>40</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<!-- FIXME: Incorrect problem -->
<problem>
<file>test.kt</file>
<line>57</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<problem>
<file>operators.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/operators.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<problem>
<file>operators.kt</file>
<line>23</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/operators.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
<problem>
<file>operators.kt</file>
<line>37</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/operators.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'suspend' modifier</problem_class>
<description>Redundant 'suspend' modifier</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.RedundantSuspendModifierInspection
@@ -0,0 +1,43 @@
// WITH_RUNTIME
class A(val x: Int) {
// Redundant
suspend operator fun plus(a: A): A {
return A(x + a.x)
}
}
// Not redundant
suspend fun foo(a1: A, a2: A): A {
return a1 + a2
}
// Not redundant
suspend fun bar(a1: A, a2: A): A {
var result = a1
result += a2
return result
}
class B(var x: Int) {
// Redundant
suspend operator fun minusAssign(b: B) {
x -= b.x
}
}
// Not redundant
suspend fun foo(b1: B, b2: B): B {
val result = b1
result -= b2
return result
}
class C(val x: Int, val y: Int) {
// Redundant
suspend operator fun invoke() = x + y
}
// Not redundant
suspend fun foo(c1: C, c2: C): Int {
return c1() + c2()
}
@@ -0,0 +1,69 @@
// WITH_RUNTIME
fun coroutine(block: suspend () -> Unit) {}
// Not redundant
suspend fun rootSuspend() {
coroutine {
empty()
}
}
// Redundant
suspend fun empty() {}
suspend fun suspendUser() = rootSuspend() // not redundant
open class My {
// Not redundant
open suspend fun baseSuspend() {
rootSuspend()
}
}
class Your : My() {
override fun baseSuspend() {
}
}
class SIterable {
operator fun iterator() = this
// Redundant
suspend operator fun hasNext(): Boolean = false
// Redundant
suspend operator fun next(): Int = 0
}
class SIterator {
// Redundant
suspend operator fun iterator() = this
operator fun hasNext(): Boolean = false
operator fun next(): Int = 0
}
// Not redundant
suspend fun foo() {
val iterable = SIterable()
coroutine {
for (x in iterable) {
println(x)
}
}
}
// Not redundant
suspend fun bar() {
val iterator = SIterator()
coroutine {
for (x in iterator) {
println(x)
}
}
}
interface Suspended {
// Not redundant
suspend fun bar()
}