Search in sources :

Example 1 with GwtTestGinException

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);
}
Also used : Binding(com.google.inject.Binding) Type(java.lang.reflect.Type) GwtTestGinException(com.googlecode.gwt.test.gin.GwtTestGinException) GWT(com.google.gwt.core.client.GWT) CtClass(javassist.CtClass) PatchClass(com.googlecode.gwt.test.patchers.PatchClass) AbstractBindingBuilder(com.google.inject.internal.AbstractBindingBuilder) PatchMethod(com.googlecode.gwt.test.patchers.PatchMethod)

Aggregations

GWT (com.google.gwt.core.client.GWT)1 Binding (com.google.inject.Binding)1 AbstractBindingBuilder (com.google.inject.internal.AbstractBindingBuilder)1 GwtTestGinException (com.googlecode.gwt.test.gin.GwtTestGinException)1 PatchClass (com.googlecode.gwt.test.patchers.PatchClass)1 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)1 Type (java.lang.reflect.Type)1 CtClass (javassist.CtClass)1