use of com.google.gwt.inject.client.AsyncProvider in project gwt-test-utils by gwt-test-utils.
the class DeferredBindingModule method generatedAsyncProvider.
@SuppressWarnings("unchecked")
private Class<Object> generatedAsyncProvider(String className, Key<?> providedKey) {
CtClass providedCtClass = GwtClassPool.getCtClass(providedKey.getTypeLiteral().getRawType());
CtClass c = GwtClassPool.get().makeClass(className);
c.addInterface(GwtClassPool.getCtClass(AsyncProvider.class));
try {
ClassFile classFile = c.getClassFile();
classFile.setVersionToJava5();
ConstPool constantPool = classFile.getConstPool();
CtField provider = CtField.make("private " + Provider.class.getName() + " provider;", c);
c.addField(provider);
FieldInfo fieldInfo = provider.getFieldInfo();
// Make it generic
SignatureAttribute signatureAttribute = new SignatureAttribute(fieldInfo.getConstPool(), "Lcom/google/inject/Provider<" + Descriptor.of(providedCtClass) + ">;");
fieldInfo.addAttribute(signatureAttribute);
AnnotationsAttribute attr = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag);
javassist.bytecode.annotation.Annotation a = new javassist.bytecode.annotation.Annotation(Inject.class.getName(), constantPool);
attr.setAnnotation(a);
provider.getFieldInfo().addAttribute(attr);
CtMethod get = CtMethod.make("public void get(" + AsyncCallback.class.getName() + " callback) { callback.onSuccess(provider.get()); }", c);
c.addMethod(get);
return c.toClass();
} catch (CannotCompileException e) {
throw new GwtTestGinException("Error while creating AsyncProvider subclass [" + className + "]", e);
}
}
Aggregations