Refine MethodParameter#isOptional Kotlin implementation
This commit adds support for Continuation parameter that is now considered as an optional parameter since it is never provided by the user. It also simplifies and optimizes the implementation. Closes gh-23991
This commit is contained in:
@@ -20,6 +20,7 @@ import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.lang.reflect.Method
|
||||
import java.lang.reflect.TypeVariable
|
||||
import kotlin.coroutines.Continuation
|
||||
import kotlin.reflect.full.declaredFunctions
|
||||
import kotlin.reflect.jvm.javaMethod
|
||||
|
||||
@@ -101,6 +102,13 @@ class KotlinMethodParameterTests {
|
||||
assertThat(returnGenericParameterType("suspendFun8")).isEqualTo(Object::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Continuation parameter is optional`() {
|
||||
val method = this::class.java.getDeclaredMethod("suspendFun", String::class.java, Continuation::class.java)
|
||||
assertThat(MethodParameter(method, 0).isOptional).isFalse()
|
||||
assertThat(MethodParameter(method, 1).isOptional).isTrue()
|
||||
}
|
||||
|
||||
private fun returnParameterType(funName: String) = returnMethodParameter(funName).parameterType
|
||||
private fun returnGenericParameterType(funName: String) = returnMethodParameter(funName).genericParameterType
|
||||
private fun returnGenericParameterTypeName(funName: String) = returnGenericParameterType(funName).typeName
|
||||
|
||||
Reference in New Issue
Block a user