Search in sources :

Example 1 with GinModule

use of com.google.gwt.inject.client.GinModule in project gwt-test-utils by gwt-test-utils.

the class GInjectorCreateHandler method readGinModules.

private Class<? extends GinModule>[] readGinModules(Class<? extends Ginjector> classLiteral) {
    LOGGER.debug("inspecting classLiteral " + classLiteral);
    GinModules annotation = classLiteral.getAnnotation(GinModules.class);
    if (annotation == null) {
        // Throw an exception if we don't find this specific annotation.
        throw new IllegalArgumentException(classLiteral.getName() + " doesn't have any @GinModules annotation present");
    }
    Class<? extends GinModule>[] ginModules = annotation.value();
    if (ginModules == null || ginModules.length == 0) {
        // there are no GinModules present in the Ginjector.
        throw new IllegalArgumentException(classLiteral.getName() + " doesn't have any GinModules. " + "Runtime should not work.");
    }
    LOGGER.debug("discovered modules " + annotation);
    return ginModules;
}
Also used : GinModules(com.google.gwt.inject.client.GinModules) GinModule(com.google.gwt.inject.client.GinModule)

Example 2 with GinModule

use of com.google.gwt.inject.client.GinModule in project gwt-test-utils by gwt-test-utils.

the class GInjectorCreateHandler method create.

public Object create(Class<?> classLiteral) throws Exception {
    // Make sure this is a Ginjector
    if (!Ginjector.class.isAssignableFrom(classLiteral)) {
        return null;
    }
    @SuppressWarnings("unchecked") Class<? extends Ginjector> ginjectorClass = (Class<? extends Ginjector>) classLiteral;
    if (injectors == null) {
        injectors = new HashMap<Class<? extends Ginjector>, Object>();
    }
    Object guiceInjectorProxy = injectors.get(classLiteral);
    if (guiceInjectorProxy != null) {
        LOGGER.debug("Proxy for class '" + ginjectorClass.getName() + "'has been found in cache. It is returned");
        return guiceInjectorProxy;
    }
    Class<? extends GinModule>[] ginModules = readGinModules(ginjectorClass);
    // create a set of Guice Module bases on the GinModules
    Set<Module> guiceModules = readGuiceModules(ginModules, ginjectorClass);
    // Use Guice SPI to solve deferred binding dependencies
    DeferredBindingModule deferredBindingModule = DeferredBindingModule.getDeferredBindingModule(ginjectorClass, guiceModules);
    guiceModules.add(deferredBindingModule);
    // Instantiate an injector, based on the modules read above + the
    // deferredBindingModule
    Injector injector = Guice.createInjector(guiceModules);
    LOGGER.debug("creating new Proxy for class '" + ginjectorClass.getName() + "'");
    guiceInjectorProxy = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { ginjectorClass }, new GinInjectorInvocationHandler(injector));
    injectors.put(ginjectorClass, guiceInjectorProxy);
    return guiceInjectorProxy;
}
Also used : GinModule(com.google.gwt.inject.client.GinModule) Injector(com.google.inject.Injector) Ginjector(com.google.gwt.inject.client.Ginjector) Module(com.google.inject.Module) GinModule(com.google.gwt.inject.client.GinModule)

Example 3 with GinModule

use of com.google.gwt.inject.client.GinModule in project google-gin by gwtplus.

the class GinjectorGenerator method getPropertyModuleClasses.

// We check that the class is a GinModule before casting it.
@SuppressWarnings("unchecked")
private void getPropertyModuleClasses(Class<?> ginjectorType, Set<Class<? extends GinModule>> ginModules) throws UnableToCompleteException {
    Set<String> propertyModuleNames = getPropertyModuleNames(ginjectorType);
    for (String moduleName : propertyModuleNames) {
        try {
            // Gin modules must be initialized when loading since we will instantiate it. It is
            // officially illegal to call any GWT-client code in a Gin module.
            Class<?> ginModule = loadClass(moduleName, true);
            if (!GinModule.class.isAssignableFrom(ginModule)) {
                logger.log(TreeLogger.Type.ERROR, String.format("The gin module type [%s] does not " + "inherit from GinModule.", moduleName));
                throw new UnableToCompleteException();
            }
            ginModules.add((Class<? extends GinModule>) ginModule);
        } catch (ClassNotFoundException e) {
            logger.log(TreeLogger.ERROR, String.format("Unable to load gin module type [%s], " + "maybe you haven't compiled your client java sources?", moduleName), e);
            throw new UnableToCompleteException();
        }
    }
}
Also used : UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) GinModule(com.google.gwt.inject.client.GinModule)

Example 4 with GinModule

use of com.google.gwt.inject.client.GinModule in project gwt-test-utils by gwt-test-utils.

the class GInjectorCreateHandler method readGuiceModules.

private Set<Module> readGuiceModules(Class<? extends GinModule>[] classLiterals, Class<? extends Ginjector> ginectorClass) throws Exception {
    Set<Module> modules = new HashSet<Module>();
    for (Class<? extends GinModule> literal : classLiterals) {
        LOGGER.debug("wrapping GinModule literal " + literal);
        MemberCollector memberCollector = new MemberCollector(GwtTreeLogger.get());
        GuiceUtil guiceUtil = new GuiceUtil(memberCollector);
        modules.add(new GinModuleAdapter(literal.newInstance(), new GinjectorBindings(null, GwtTreeLogger.get(), guiceUtil, ginectorClass, null, memberCollector, null, null)));
    }
    return modules;
}
Also used : GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) GuiceUtil(com.google.gwt.inject.rebind.util.GuiceUtil) GinModuleAdapter(com.google.gwt.inject.rebind.adapter.GinModuleAdapter) Module(com.google.inject.Module) GinModule(com.google.gwt.inject.client.GinModule) MemberCollector(com.google.gwt.inject.rebind.util.MemberCollector) HashSet(java.util.HashSet)

Example 5 with GinModule

use of com.google.gwt.inject.client.GinModule in project google-gin by gwtplus.

the class BinderAdapter method install.

public void install(GinModule install) {
    // Filtering out fake factory modules.
    if (install instanceof FactoryModule) {
        if (bindings != null) {
            bindings.addFactoryModule((FactoryModule<?>) install);
        }
    } else {
        // Here we need to take care to ensure that PrivateGinModule uses the appropriate
        // type of adapter, and also get the corresponding Guice private binder.
        final Module moduleAdapter;
        if (install == null) {
            moduleAdapter = null;
        } else if (install instanceof PrivateGinModule) {
            moduleAdapter = new PrivateGinModuleAdapter((PrivateGinModule) install, bindings);
        } else {
            moduleAdapter = new GinModuleAdapter(install, bindings);
        }
        binder.install(moduleAdapter);
    }
}
Also used : PrivateGinModule(com.google.gwt.inject.client.PrivateGinModule) FactoryModule(com.google.gwt.inject.client.assistedinject.FactoryModule) Module(com.google.inject.Module) GinModule(com.google.gwt.inject.client.GinModule) FactoryModule(com.google.gwt.inject.client.assistedinject.FactoryModule) PrivateGinModule(com.google.gwt.inject.client.PrivateGinModule)

Aggregations

GinModule (com.google.gwt.inject.client.GinModule)5 Module (com.google.inject.Module)3 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 GinModules (com.google.gwt.inject.client.GinModules)1 Ginjector (com.google.gwt.inject.client.Ginjector)1 PrivateGinModule (com.google.gwt.inject.client.PrivateGinModule)1 FactoryModule (com.google.gwt.inject.client.assistedinject.FactoryModule)1 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)1 GinModuleAdapter (com.google.gwt.inject.rebind.adapter.GinModuleAdapter)1 GuiceUtil (com.google.gwt.inject.rebind.util.GuiceUtil)1 MemberCollector (com.google.gwt.inject.rebind.util.MemberCollector)1 Injector (com.google.inject.Injector)1 HashSet (java.util.HashSet)1