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

Support Bounded Generics in Methods #3

Open
spraguep opened this issue Jul 29, 2013 · 3 comments
Open

Support Bounded Generics in Methods #3

spraguep opened this issue Jul 29, 2013 · 3 comments

Comments

@spraguep
Copy link

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)
@UnquietCode
Copy link
Owner

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 {
   ...
}

@UnquietCode
Copy link
Owner

Related to the required changes in JCodeModel: UnquietCode/JCodeModel#4

@UnquietCode UnquietCode changed the title Support Wildcard and Bounded Generics in Methods Support Bounded Generics in Methods Jan 26, 2015
@UnquietCode
Copy link
Owner

#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.

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

No branches or pull requests

2 participants