Created
July 7, 2014 17:57
-
-
Save gissuebot/c3e1b2155bacddacb00f to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 83, comment 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: com/google/inject/ProviderMethods.java | |
=================================================================== | |
--- com/google/inject/ProviderMethods.java (revision 332) | |
+++ com/google/inject/ProviderMethods.java (working copy) | |
@@ -112,7 +112,29 @@ | |
}; | |
// TODO: Fix type warnings. | |
- Class type = method.getReturnType(); | |
+ TypeLiteral literalType = null; | |
+ | |
+ Type genericType = method.getGenericReturnType(); | |
+ if (genericType != null) { | |
+ Type[] params = method.getDeclaringClass().getTypeParameters(); | |
+ for (int i = 0; i < params.length; i++) | |
+ { | |
+ if ( genericType.equals( params[i] )) | |
+ { | |
+ Type superclass = providers.getClass().getGenericSuperclass(); | |
+ Type actualType = ((java.lang.reflect.ParameterizedType) superclass).getActualTypeArguments()[i]; | |
+ literalType = TypeLiteral.get( actualType ); | |
+ break; | |
+ } | |
+ } | |
+ } | |
+ | |
+ if ( null == literalType ) { | |
+ literalType = TypeLiteral.get(method.getReturnType()); | |
+ } | |
+ | |
+ TypeLiteral<Object> type = literalType; | |
+ | |
if (scopeAnnotation == null && bindingAnnotation == null) { | |
bind(type).toProvider(provider); | |
} else if (scopeAnnotation == null) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment