@SuppressWarnings( {"raw", "unchecked"} )
public Object provideInjection( InjectionContext context )
throws InjectionProviderException
{
Class injectionClass = Classes.RAW_CLASS.map( dependencyModel.injectionType() );
final CompositeMethodModel methodModel = resolution.method();
if( injectionClass.equals( Method.class ) )
{
return methodModel.method();
}
final AnnotatedElement annotatedElement = methodModel.annotatedElement();
if( injectionClass.equals( AnnotatedElement.class ) )
{
return annotatedElement;
}
final Annotation annotation = annotatedElement.getAnnotation( injectionClass );
if( annotation != null )
{
return annotation;
}
if( dependencyModel.injectionType() instanceof Class<?> )
{
return annotatedElement.getAnnotation( (Class<Annotation>) dependencyModel.injectionType() );
}
if( dependencyModel.injectionType() instanceof ParameterizedType )
{
ParameterizedType injectionType = (ParameterizedType) dependencyModel.injectionType();
Type rawType = injectionType.getRawType();
Type[] actualTypeArguments = injectionType.getActualTypeArguments();
boolean isAnIterable = rawType.equals( Iterable.class );
boolean haveOneGenericType = actualTypeArguments.length == 1;
boolean thatIsOfTypeMethod = actualTypeArguments[ 0 ].equals( Method.class );
if( isAnIterable && haveOneGenericType && thatIsOfTypeMethod )
{
Class<?> injectedClass = dependencyModel.injectedClass();
Iterable<Method> result = methodModel.invocationsFor( injectedClass );
return result;
}
}
return null;
}