Introduce "redundant async" inspection #KT-24235 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-05-11 15:01:05 +03:00
parent 365c13c38e
commit 13be7803bb
19 changed files with 564 additions and 1 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.coroutines.RedundantAsyncInspection
@@ -0,0 +1,48 @@
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test(ctx: CoroutineContext) {
<caret>async(ctx) { 42 }.await()
}
@@ -0,0 +1,48 @@
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test(ctx: CoroutineContext) {
withContext(ctx) { 42 }
}
@@ -0,0 +1,48 @@
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test() {
<caret>async { 42 }.await()
}
@@ -0,0 +1,48 @@
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test() {
runBlocking { 42 }
}
@@ -0,0 +1,49 @@
// PROBLEM: none
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test(ctx: CoroutineContext) {
<caret>async(parent = null) { 42 }.await()
}
@@ -0,0 +1,48 @@
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test(ctx: CoroutineContext) {
<caret>async(ctx, CoroutineStart.LAZY) { 42 }.await()
}
@@ -0,0 +1,48 @@
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test(ctx: CoroutineContext) {
withContext(ctx, CoroutineStart.LAZY) { 42 }
}
@@ -0,0 +1,49 @@
// PROBLEM: none
// WITH_RUNTIME
package kotlinx.coroutines.experimental
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object DefaultContext : CoroutineContext
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface Job
fun <T> async(
context: CoroutineContext = DefaultContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
parent: Job? = null,
f: suspend () -> T
): Deferred<T> {
TODO()
}
fun <T> runBlocking(
context: CoroutineContext = DefaultContext,
f: suspend () -> T
) {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
f: suspend () -> T
) {
TODO()
}
suspend fun test(ctx: CoroutineContext) {
<caret>async(start = CoroutineStart.LAZY) { 42 }.await()
}