Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
platosha opened this issue Dec 20, 2022 · 4 comments · Fixed by #742
Closed

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

platosha opened this issue Dec 20, 2022 · 4 comments · Fixed by #742

Comments

@platosha
Copy link
Contributor

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.

platosha added a commit to platosha/classgraph that referenced this issue Dec 20, 2022
Fixes classgraph#741

Exposes missing API for accessing parsed annotations on type parameters
and wildcard type arguments.
@lukehutch
Copy link
Member

@platosha Thanks for reporting this, for explaining the background, and for providing the complete fix! Much appreciated. I'll roll out a release tonight with this.

@lukehutch
Copy link
Member

This is released in 4.8.153, but then I subsequently committed 42753ef, which moves this method into the superclass -- that way all type signature classes support getting type annotation information. (Adds support for ClassTypeSignature, MethodTypeSignature, BaseTypeSignature, ReferenceTypeSignature, etc.)

@platosha
Copy link
Contributor Author

@lukehutch thanks a lot!

@lukehutch
Copy link
Member

@platosha The weird thing is I went to document this API call in the wiki docs, and it was already there! So it looks like I always planned to add this getter, I just forgot to do it. 🤦‍♂️ I'm glad you caught it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants