leangen / geantyref

Advanced generic type reflection library with support for working with AnnotatedTypes (for Java 8+)
Apache License 2.0
99 stars 15 forks source link

getExactParameterTypes() for constructors #2

Closed pniederw closed 7 years ago

pniederw commented 7 years ago

I would be useful to support getExactParameterTypes() not only for methods but also for constructors.

Given that geantyref already requires Java 1.8+, the easiest way to accomplish this is to change the method signature

public static AnnotatedType[] getExactParameterTypes(Method m, AnnotatedType declaringType)

to

public static AnnotatedType[] getExactParameterTypes(Executable m, AnnotatedType declaringType)

Likewise for the Type overload. No other changes required.

PS: Since Type overloads are implemented in terms of AnnotatedType overloads but discard annotation information, would it be more efficient to lift Type to AnnotatedType using new AnnotatedTypeImpl(type) rather than annotate(type)?

kaqqao commented 7 years ago

Thanks for this! I fixed it in b616414565bb6675c6b1d969c528f880c27a4837 and it's in v1.1.1 release.

The thing with new AnnotatedTypeImpl(type) vs annotate(type), is that new AnnotatedTypeImpl(type) will always produce just a top-level AnnotatedType while annotate(type) may result in AnnotatedParameterizedType or other more specific types. Having a non exact type, in turn, will mess up the checks in getExactDirectSuperTypes and potentially other places that expect the AnnotatedType and the contained Type to always correspond e.g. that only an AnnotatedParameterizedType can contain a ParameterizedType. I'll see if I can do something reasonable about it or if it's better left untouched.