コード例 #1
0
 private Object replace(Class<?> type, ApplicableGenerator generator, boolean alternative) {
   for (Creator<?> creator : creators) {
     ParameterizedType generic =
         (ParameterizedType) creator.getClass().getGenericInterfaces()[0];
     Class<?> restrained =
         generic.getActualTypeArguments()[0] instanceof ParameterizedType
             ? (Class<?>) ((ParameterizedType) generic.getActualTypeArguments()[0]).getRawType()
             : (Class<?>) generic.getActualTypeArguments()[0];
     if (type.isAssignableFrom(restrained)) {
       return creator.create();
     }
   }
   return generator.generate(type, alternative);
 }
コード例 #2
0
 private Object generate(Class<?> type, boolean alternative) {
   for (Generator<?> generator : generators) {
     ParameterizedType generic =
         (ParameterizedType) generator.getClass().getGenericInterfaces()[0];
     Class<?> restrained =
         generic.getActualTypeArguments()[0] instanceof ParameterizedType
             ? (Class<?>) ((ParameterizedType) generic.getActualTypeArguments()[0]).getRawType()
             : (Class<?>) generic.getActualTypeArguments()[0];
     if (type.isAssignableFrom(restrained)) {
       type = generator.generate();
     }
   }
   return type == String.class ? alternative ? OTHER_STRING : DEFAULT_STRING : mock(type);
 }