use of com.googlecode.gwt.test.gin.GwtTestGinException in project gwt-test-utils by gwt-test-utils.
the class GwtDotCreateProviderPatcher method bind.
@PatchMethod
static <T> ScopedBindingBuilder bind(LinkedBindingBuilder<T> builder) {
if (!(builder instanceof AbstractBindingBuilder)) {
throw new GwtTestGinException("Not managed " + LinkedBindingBuilder.class.getSimpleName() + " implementation : " + builder.getClass().getName());
}
Binding<T> binding = GwtReflectionUtils.<Binding<T>>getPrivateFieldValue(builder, "binding");
Type type = binding.getKey().getTypeLiteral().getType();
if (!(type instanceof Class)) {
throw new GwtTestGinException("Not managed binded type : " + type);
}
Constructor<T> atInjectConstructor = getAtInjectConstructor((Class<T>) type);
if (atInjectConstructor != null) {
return builder.toConstructor(atInjectConstructor);
}
GwtDotCreateProvider<T> gwtDotCreateProvider = GwtReflectionUtils.instantiateClass(GwtDotCreateProvider.class);
GwtReflectionUtils.setPrivateFieldValue(gwtDotCreateProvider, BINDED_CLASS_FIELD, type);
return builder.toProvider(gwtDotCreateProvider);
}
Aggregations