Search in sources :

Example 1 with Ginjector

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

the class FrameworkGenerator method createGinjector.

private String createGinjector(TreeLogger logger, GeneratorContext context, String packageName, String requestedName, String newClassName, String moduleName) {
    String ginjectorName = requestedName + "Ginjector";
    ClassSourceFileComposerFactory ginjectorFactory = new ClassSourceFileComposerFactory(packageName, ginjectorName);
    ginjectorFactory.makeInterface();
    ginjectorFactory.addImplementedInterface(Ginjector.class.getCanonicalName());
    ginjectorFactory.addImport(GinModules.class.getCanonicalName());
    ginjectorFactory.addAnnotationDeclaration("@GinModules(" + moduleName + ".class)");
    SourceWriter ginjectorWriter = ginjectorFactory.createSourceWriter(context, context.tryCreate(logger, packageName, ginjectorName));
    ginjectorWriter.println("void injectMembers(" + newClassName + " obj);");
    ginjectorWriter.commit(logger);
    return ginjectorName;
}
Also used : ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) Ginjector(com.google.gwt.inject.client.Ginjector) GinModules(com.google.gwt.inject.client.GinModules) SourceWriter(com.google.gwt.user.rebind.SourceWriter)

Example 2 with Ginjector

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

the class GinjectorGeneratorModule method configure.

@Override
protected void configure() {
    install(new ResolutionModule());
    install(new OutputModule());
    bind(TreeLogger.class).toInstance(logger);
    bind(GeneratorContext.class).toInstance(ctx);
    bind(new TypeLiteral<Class<? extends Ginjector>>() {
    }).annotatedWith(GinjectorInterfaceType.class).toInstance(ginjectorInterface);
    bind(GinjectorBindings.class).annotatedWith(RootBindings.class).to(GinjectorBindings.class).in(Singleton.class);
    bind(BindingIndex.class).to(Key.get(GinjectorBindings.class, RootBindings.class)).in(Singleton.class);
    install(new FactoryModuleBuilder().build(GuiceElementVisitor.GuiceElementVisitorFactory.class));
    bind(new TypeLiteral<Set<Class<? extends GinModule>>>() {
    }).annotatedWith(ModuleClasses.class).toInstance(moduleClasses);
    bind(BindingFactory.class).to(BindingFactoryImpl.class);
    install(new FactoryModuleBuilder().build(SourceWriteUtil.Factory.class));
}
Also used : Set(java.util.Set) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) BindingFactory(com.google.gwt.inject.rebind.binding.BindingFactory) GeneratorContext(com.google.gwt.core.ext.GeneratorContext) OutputModule(com.google.gwt.inject.rebind.output.OutputModule) ResolutionModule(com.google.gwt.inject.rebind.resolution.ResolutionModule) TreeLogger(com.google.gwt.core.ext.TreeLogger) Ginjector(com.google.gwt.inject.client.Ginjector) BindingFactory(com.google.gwt.inject.rebind.binding.BindingFactory)

Example 3 with Ginjector

use of com.google.gwt.inject.client.Ginjector 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<>();
    }
    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)

Aggregations

Ginjector (com.google.gwt.inject.client.Ginjector)3 GeneratorContext (com.google.gwt.core.ext.GeneratorContext)1 TreeLogger (com.google.gwt.core.ext.TreeLogger)1 GinModule (com.google.gwt.inject.client.GinModule)1 GinModules (com.google.gwt.inject.client.GinModules)1 BindingFactory (com.google.gwt.inject.rebind.binding.BindingFactory)1 OutputModule (com.google.gwt.inject.rebind.output.OutputModule)1 ResolutionModule (com.google.gwt.inject.rebind.resolution.ResolutionModule)1 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)1 SourceWriter (com.google.gwt.user.rebind.SourceWriter)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 Set (java.util.Set)1