Skip to content

Improve isReturnTypeList for non suspend method #15

@tuanchauict

Description

@tuanchauict

Currently, as mentioned in #11 , isReturnTypeList can work with any return type which contains java.util.List.
However, this approach has some issues:

  1. Incorrect if the return type is something like this: Foo<Bar<Baz<List<Something>>>
  2. Cannot work with other collection types like Set, Array.

I tried an update like this:

private fun isMethodWithListReturnValue(method: Method): Boolean {
    if (method.returnType.isArray) {
        return true
    }
    val genericReturnType = method.genericReturnType as? ParameterizedType ?: return false
    return isArrayOrCollectionClass(genericReturnType.rawType.typeName)
}

However, this doesn't work if List-type is the secondary type like: Flow<List<Something>>.

If we extract secondary type from Flow like what we did with Continuation for suspend method, we cannot guarantee whether the list is hidden under the third type like Flow<Resource<List<Type>>>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions