Flapi
Flapi copied to clipboard
Support Bounded Generics in Methods
Trying to add a method that uses generics:
addMethod("withApplicationSettings(Class<? extends com.a.b.c.ApplicationSettings> settingsClass)")
Causes this exception:
Caused by: unquietcode.tools.flapi.MethodParser$ParseException: Expected to find character in {)} but was '?' (method signature is [ 'withApplicationSettings(Class<? extends com.paypal.creditpd.rappstack.server.flapi.application.RSApplicationSettings> settings)' ]).
at unquietcode.tools.flapi.MethodParser.throwUnexpectedCharException(MethodParser.java:273)
at unquietcode.tools.flapi.MethodParser.match(MethodParser.java:214)
at unquietcode.tools.flapi.MethodParser.<init>(MethodParser.java:120)
at unquietcode.tools.flapi.MethodParser.<init>(MethodParser.java:42)
at unquietcode.tools.flapi.DescriptorPreValidator._checkForInvalidMethodSignatures(DescriptorPreValidator.java:119)
Version 0.4 added support for generic types, but not wildcards. Adding the wildcard type '?' is likely straightforward, but supporting the full bounds of 'x super y' or 'x extends y' is more difficult. These require changes to JCodeModel, because wildcard support there is a bit spotty. This is definitely worth looking into for the next release though.
Here's a little gem from the CodeModel code: :-)
/**
* Represents a wildcard type like "? extends Foo".
*
* Our modeling of types are starting to look really ugly.
* ideally it should have been done somewhat like APT,
* but it's too late now.
*
* @author Kohsuke Kawaguchi
*/
final class JTypeWildcard extends JClass {
...
}
Related to the required changes in JCodeModel: https://github.com/UnquietCode/JCodeModel/issues/4
#214 will add support for wildcards, and this issue can remain open for a future enhancement to implement bounded generics, which is much more difficult.