-
Notifications
You must be signed in to change notification settings - Fork 93
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 for just resolving type variables #12
base: master
Are you sure you want to change the base?
Conversation
Added support for just resolving type variables into classes/parameterized types etc.
Awesome contribution! This seems to work good for method refs, but for non-method refs, resolving #8 was somewhat calling for an API that returns What do you think? |
To be honest, my understanding of the So maybe it would be best to see this as PR as a guide for how to handle one use case, that someone else may want to build on in future? |
Sure, no problem. I'll probably pick up this PR and add onto it a bit, using it as an excuse to add proper |
Sounds like a plan. |
I would like to pick this up again, since I have a use-case for it. However, please @jhalterman re-read the changeset and proposals, and reformulate what should be done/how these changes should be integrated before I start working. I am asking for this since this is a very old PR, and I would like to get your updated view on it in order to avoid wasting my energy. |
@lorenzleutgeb I don't have any firm ideas on this, but the general high level idea would be to add a new resolve capability that resolves a container type like class SomeFunction extends Function<String, List<Boolean>> {}
List<GenericType> args = resolveArguments(Function.class, SomeFunction.class);
GenericType stringArg = args.get(0);
GenericType listArg = args.get(1);
assert stringArg.getRawClass() == String.class;
assert listArg.getRawClass() == List.class;
GenericType booleanArg = listArg.getArgument();
assert booleanArg.getRawClass() == Boolean.class;
// And also
assert listArg.equals(new GenericType<List<Boolean>>() { }); |
@jhalterman you might want to consider closing this since #46 was merged, or is there something that I missed? |
Added support for just resolving type variables into classes/parameterized types etc.
This is one possible solution for #8.
This is useful for when you have a method reference, and you want to find out what its arguments are, including generic type argument information.
To implement this, I look up the method specified by the method ref from the class that the method ref lives on.
One limitation is that it doesn't actually work for lambdas, it only works for method references (ie, using the :: syntax), since the Java compiler does not include generic type information in the generated synthetic methods for the lambda. I don't think there's anything that can be done about this, short of raising a bug on javac to ask that lambda methods get generated with full type information.