/** * Deduces the role type based on the given @{@link Requirement} and expected type. * * @param requirement The Plexus requirement * @param asType The expected type * @return "Best-fit" role type */ public static TypeLiteral<?> roleType( final Requirement requirement, final TypeLiteral<?> asType ) { final Type role = requirement.role(); if ( role != Object.class ) { return TypeLiteral.get( role ); } final Class<?> rawType = asType.getRawType(); if ( Map.class == rawType ) { // Map<String, T> --> T return TypeParameters.get( asType, 1 ); } if ( List.class == rawType ) { // List<T> --> T return TypeParameters.get( asType, 0 ); } return asType; }
public final void configure( final Binder binder ) { // make sure we pick up the right super type parameter, i.e. Foo from AbstractTypeConverter<Foo> final TypeLiteral<?> superType = TypeLiteral.get( getClass() ).getSupertype( AbstractTypeConverter.class ); binder.convertToTypes( Matchers.only( TypeParameters.get( superType, 0 ) ), this ); } }