Skip to content

Missing API access for annotations on type parameters and wildcard type arguments  #741

@platosha

Description

@platosha

TypeParameter and TypeArgument (in case of using a wildcard) could hold annotations, but they do not have a getTypeAnnotationInfo() getter exposed, despite parsing works seemingly correctly in both cases.

Consider analysing annotations specified on the method parameter types in the scan result of the following class:

class GenericTypeAnnotationTest {
    @Target({ ElementType.FIELD, ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
    private static @interface A {
    }

    <@A T> void saveT(T param) {
    }

    void saveUList(List<@A ?> param) {
    }
}

typeParameter.toString() and typeArgument.toString() results show the @A annotation where expected, but there is no API to access the @A annotation info other than toString().

Apart from Java, this has a big impact on working with Kotlin compiled code, as for some types (BigDecimal and BigInteger are known examples, my wild guess, for supporting Kotlin language extensions) compiler emits List<@A ? extends Type> param in JVM bytecode whereas the source had List<@A Type> param.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions