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;
}
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));
}
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;
}
Aggregations