Skip to content

Commit

Permalink
Update FlowResponseConverterFunctionProvider Type Extension functio…
Browse files Browse the repository at this point in the history
…ns toClass() (#5201)

### Type of PR

Hello! While reviewing the Kotlin part of Armeria, I noticed that in the `FlowResponseConverterFunctionProvider` class, there's an extension function for `Type` used in the `createResponseConverterFunction()` function of `DelegatingResponseConverterFunctionProvider`. The `toClass()` function returns a type of `Class<*>?`.

<br>

In the past, when working with Kotlin, I found it beneficial to define extension functions that return nullable values with names following the `toXXXOrNull()` pattern. This made the code more understandable for me and my teammates, especially during maintenance.

<br>

Since the extension function is defined just below `createResponseConverterFunction()`, it may lead to questions like "Why use `toClass()?.let` here?" Adding `OrNull` to the function name can make the code more readable.

<br>

> I understand that naming conventions can vary among teams, and it may not be a critical issue. However, if you find the suggestion helpful, I'd appreciate it if you could consider applying the change.

---

```kt
private fun Type.toClassOrNull(): Class<*>? =
    when (this) {
        is ParameterizedType -> this.rawType as Class<*>
        is Class<*> -> this
        else -> null
    }
  • Loading branch information
esperar authored Sep 25, 2023
1 parent 411d65f commit 33f1b57
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FlowResponseConverterFunctionProvider : DelegatingResponseConverterFunctio
responseConverter: ResponseConverterFunction
): ResponseConverterFunction? =
returnType
.toClass()
.toClassOrNull()
?.let {
if (Flow::class.java.isAssignableFrom(it)) {
FlowResponseConverterFunction(responseConverter)
Expand All @@ -41,7 +41,7 @@ class FlowResponseConverterFunctionProvider : DelegatingResponseConverterFunctio
}
}

private fun Type.toClass(): Class<*>? =
private fun Type.toClassOrNull(): Class<*>? =
when (this) {
is ParameterizedType -> this.rawType as Class<*>
is Class<*> -> this
Expand Down

0 comments on commit 33f1b57

Please sign in to comment.