Skip to content

Question - Resolve the TypeName of a type argument with type arguments. #1378

Description

@callius

The following is a class structure for example purposes:

interface Target<V> {
    val value: V 
}

interface TargetBuilder<I, T : Target<I>> {
    …
}

abstract class GenericTargetBuilder<I> : TargetBuilder<I, GenericTarget<I>> {
    …
}

class A : GenericTargetBuilder<Int>() {
    …
}

I would like to resolve GenericTarget<Int> from class A using kotlinpoet-ksp.

Following the docs, I tried the following:

  1. I do a tree search on the super types of class A to find the first TypeReference of TargetBuilder.
  2. At this point, I have the TypeReferences and TypeDeclarations of all the super types of class A.
  3. I take the second type argument (index 1) of the TargetBuilder declaration on GenericTargetBuilder.
  4. Now, I call toTypeName on the type argument type's TypeReference, passing in a recursive TypeParametersResolver (foldRight on all of the parent declarations’ type parameters, if any).

I get GenericTarget<I>, instead of the expected GenericTarget<Int>.

How should I go about resolving GenericTarget<Int> from this kind of class structure?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions