Search in sources :

Example 1 with GeneratorContext

use of com.google.gwt.core.ext.GeneratorContext in project google-gin by gwtplus.

the class GinjectorBindingsOutputterTest method testOutputStaticInjections.

// Verify that outputting static injections creates and dispatches to the
// correct fragment classes.
public void testOutputStaticInjections() throws Exception {
    PrintWriter printWriter = new PrintWriter(new ByteArrayOutputStream());
    GeneratorContext ctx = createMock(GeneratorContext.class, "ctx");
    expect(ctx.tryCreate((TreeLogger) anyObject(), (String) anyObject(), (String) anyObject())).andStubReturn(printWriter);
    Capture<FieldLiteral<SuperClass>> fieldCapture = new Capture<FieldLiteral<SuperClass>>();
    Capture<MethodLiteral<SuperClass, Method>> methodCapture = new Capture<MethodLiteral<SuperClass, Method>>();
    NameGenerator nameGenerator = createMock(NameGenerator.class, "nameGenerator");
    expect(nameGenerator.convertToValidMemberName("injectStatic_com.google.gwt.inject.rebind.output." + "GinjectorBindingsOutputterTest$SubClass")).andStubReturn("test_injectSubClass");
    expect(nameGenerator.convertToValidMemberName("injectStatic_com.google.gwt.inject.rebind.output.subpackage." + "SubPackageClass")).andStubReturn("test_injectSubPackageClass");
    SourceWriteUtil sourceWriteUtil = createMock(SourceWriteUtil.class, "sourceWriteUtil");
    expect(sourceWriteUtil.createFieldInjection(capture(fieldCapture), (String) anyObject(), (NameGenerator) anyObject(), (List<InjectorMethod>) anyObject())).andReturn(SourceSnippets.forText(""));
    MethodCallUtil methodCallUtil = createMock(MethodCallUtil.class, "methodCallUtil");
    expect(methodCallUtil.createMethodCallWithInjection(capture(methodCapture), (String) anyObject(), (NameGenerator) anyObject(), (List<InjectorMethod>) anyObject())).andReturn(SourceSnippets.forText(""));
    GinjectorBindings bindings = createMock(GinjectorBindings.class, "bindings");
    expect(bindings.getNameGenerator()).andStubReturn(nameGenerator);
    expect(bindings.getStaticInjectionRequests()).andStubReturn(Arrays.<Class<?>>asList(SubClass.class, SubPackageClass.class));
    String ginjectorPackageName = "com.google.gwt.inject.rebind.output";
    String ginjectorClassName = "GinjectorFragmentOutputterTest$FakeGinjector";
    GinjectorFragmentOutputter.Factory fragmentOutputterFactory = createMock(GinjectorFragmentOutputter.Factory.class, "fragmentOutputterFactory");
    GinjectorFragmentOutputter fragmentOutputter = createMock(GinjectorFragmentOutputter.class, "fragmentOutputter");
    GinjectorFragmentOutputter fragmentOutputterSubpackage = createMock(GinjectorFragmentOutputter.class, "fragmentOutputterSubpackage");
    expect(fragmentOutputterFactory.create(bindings, new FragmentPackageName(null, "com.google.gwt.inject.rebind.output"), ginjectorPackageName, ginjectorClassName)).andStubReturn(fragmentOutputter);
    expect(fragmentOutputterFactory.create(bindings, new FragmentPackageName(null, "com.google.gwt.inject.rebind.output.subpackage"), ginjectorPackageName, ginjectorClassName)).andStubReturn(fragmentOutputterSubpackage);
    fragmentOutputter.outputMethod((InjectorMethod) anyObject());
    fragmentOutputterSubpackage.outputMethod((InjectorMethod) anyObject());
    fragmentOutputter.invokeInInitializeStaticInjections("test_injectSubClass");
    fragmentOutputterSubpackage.invokeInInitializeStaticInjections("test_injectSubPackageClass");
    replay();
    GinjectorBindingsOutputter outputter = new GinjectorBindingsOutputter(ctx, null, fragmentOutputterFactory, new TestFragmentPackageNameFactory(), null, TreeLogger.NULL, methodCallUtil, null, null);
    GinjectorBindingsOutputter.FragmentMap fragments = new GinjectorBindingsOutputter.FragmentMap(bindings, ginjectorPackageName, ginjectorClassName, fragmentOutputterFactory);
    outputter.outputStaticInjections(bindings, fragments, sourceWriteUtil);
    verify();
    TypeLiteral<SuperClass> superClass = TypeLiteral.get(SuperClass.class);
    assertEquals(superClass, methodCapture.getValue().getDeclaringType());
    assertEquals(superClass, fieldCapture.getValue().getDeclaringType());
}
Also used : InjectorMethod(com.google.gwt.inject.rebind.util.InjectorMethod) NameGenerator(com.google.gwt.inject.rebind.util.NameGenerator) GeneratorContext(com.google.gwt.core.ext.GeneratorContext) Capture(org.easymock.Capture) SourceWriteUtil(com.google.gwt.inject.rebind.util.SourceWriteUtil) MethodCallUtil(com.google.gwt.inject.rebind.util.MethodCallUtil) SubPackageClass(com.google.gwt.inject.rebind.output.subpackage.SubPackageClass) MethodLiteral(com.google.gwt.inject.rebind.reflect.MethodLiteral) PrintWriter(java.io.PrintWriter) GinjectorBindings(com.google.gwt.inject.rebind.GinjectorBindings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Method(java.lang.reflect.Method) InjectorMethod(com.google.gwt.inject.rebind.util.InjectorMethod) FieldLiteral(com.google.gwt.inject.rebind.reflect.FieldLiteral)

Example 2 with GeneratorContext

use of com.google.gwt.core.ext.GeneratorContext in project google-gin by gwtplus.

the class GinBridgeClassLoaderTest method testJavaCoreClass.

public void testJavaCoreClass() throws ClassNotFoundException {
    GeneratorContext context = GeneratorContextBuilder.newEmptyBuilder().add(createFakeString()).buildGeneratorContext();
    GinBridgeClassLoader loader = new GinBridgeClassLoader(context, createLogger(), new HashSet<String>());
    assertTrue(loader.loadClass("java.lang.String").getMethods().length > 0);
}
Also used : GeneratorContext(com.google.gwt.core.ext.GeneratorContext)

Example 3 with GeneratorContext

use of com.google.gwt.core.ext.GeneratorContext in project google-gin by gwtplus.

the class GinBridgeClassLoaderTest method testExceptedPackages.

public void testExceptedPackages() throws ClassNotFoundException, NoSuchMethodException {
    GeneratorContext context = GeneratorContextBuilder.newEmptyBuilder().add(createSimple()).buildGeneratorContext();
    GinBridgeClassLoader gwtLoader = new GinBridgeClassLoader(context, createLogger(), new HashSet<String>());
    assertClassVersion(gwtLoader, "a", "b", "com.google.gwt.inject.rebind.types.Simple");
    GinBridgeClassLoader javaLoader = new GinBridgeClassLoader(context, createLogger(), Collections.singleton("com.google.gwt.inject.rebind.types"));
    assertClassVersion(javaLoader, "b", "a", "com.google.gwt.inject.rebind.types.Simple");
}
Also used : GeneratorContext(com.google.gwt.core.ext.GeneratorContext)

Example 4 with GeneratorContext

use of com.google.gwt.core.ext.GeneratorContext in project google-gin by gwtplus.

the class GinBridgeClassLoaderTest method testExceptedPackagesWithDot.

public void testExceptedPackagesWithDot() throws ClassNotFoundException, NoSuchMethodException {
    GeneratorContext context = GeneratorContextBuilder.newEmptyBuilder().add(createSimple()).buildGeneratorContext();
    GinBridgeClassLoader loader = new GinBridgeClassLoader(context, createLogger(), Collections.singleton("com.google.gwt.inject.rebind.types."));
    assertClassVersion(loader, "b", "a", "com.google.gwt.inject.rebind.types.Simple");
}
Also used : GeneratorContext(com.google.gwt.core.ext.GeneratorContext)

Aggregations

GeneratorContext (com.google.gwt.core.ext.GeneratorContext)4 GinjectorBindings (com.google.gwt.inject.rebind.GinjectorBindings)1 SubPackageClass (com.google.gwt.inject.rebind.output.subpackage.SubPackageClass)1 FieldLiteral (com.google.gwt.inject.rebind.reflect.FieldLiteral)1 MethodLiteral (com.google.gwt.inject.rebind.reflect.MethodLiteral)1 InjectorMethod (com.google.gwt.inject.rebind.util.InjectorMethod)1 MethodCallUtil (com.google.gwt.inject.rebind.util.MethodCallUtil)1 NameGenerator (com.google.gwt.inject.rebind.util.NameGenerator)1 SourceWriteUtil (com.google.gwt.inject.rebind.util.SourceWriteUtil)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 Method (java.lang.reflect.Method)1 Capture (org.easymock.Capture)1