Package com.google.gwt.user.rebind

Examples of com.google.gwt.user.rebind.SourceWriter


  void writeExtractorJSNIReference(FragmentGeneratorContext context)
      throws UnableToCompleteException {
    TreeLogger logger = context.parentLogger.branch(TreeLogger.DEBUG,
        "Writing JSNI reference to Extractor", null);
    TypeOracle typeOracle = context.typeOracle;
    SourceWriter sw = context.sw;
    JParameterizedType listType = context.returnType.isParameterized();
    JType argumentType = listType.getTypeArgs()[0];

    sw.print("@com.google.gwt.jsio.client.impl.JSListWrapper::createExtractor(Lcom/google/gwt/jsio/client/impl/Extractor;)(");

    FragmentGenerator fragmentGenerator = context.fragmentGeneratorOracle.findFragmentGenerator(
        logger, typeOracle, argumentType.isClassOrInterface());

    FragmentGeneratorContext subParams = new FragmentGeneratorContext(context);
    subParams.returnType = argumentType;

    fragmentGenerator.writeExtractorJSNIReference(subParams);
    sw.print(")");
  }
View Full Code Here


        // init composer, set class properties, create source writer
        ClassSourceFileComposerFactory composer = null;
        composer = new ClassSourceFileComposerFactory(packageName, className);
        composer.addImport("com.google.gwt.core.client.GWT");
        composer.setSuperclass("com.vaadin.client.ui.dd.VAcceptCriterionFactory");
        SourceWriter sourceWriter = composer.createSourceWriter(context,
                printWriter);

        // generator constructor source code
        generateInstantiatorMethod(sourceWriter, context, logger);
        // close generated class
        sourceWriter.outdent();
        sourceWriter.println("}");
        // commit generated class
        context.commit(logger, printWriter);
        logger.log(Type.INFO,
                "Done. (" + (new Date().getTime() - date.getTime()) / 1000
                        + "seconds)");
View Full Code Here

        ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(
                packageName, className);
        composer.setSuperclass(requestedType);

        SourceWriter w = composer.createSourceWriter(context, printWriter);

        w.println("public void init() {");
        w.indent();

        for (ConnectorBundle bundle : bundles) {
            detectBadProperties(bundle, logger);

            String name = bundle.getName();
            boolean isEager = name
                    .equals(ConnectorBundleLoader.EAGER_BUNDLE_NAME);

            w.print("addAsyncBlockLoader(new AsyncBundleLoader(\"");
            w.print(escape(name));
            w.print("\", ");

            w.print("new String[] {");
            for (Entry<JClassType, Set<String>> entry : bundle.getIdentifiers()
                    .entrySet()) {
                Set<String> identifiers = entry.getValue();
                for (String id : identifiers) {
                    w.print("\"");
                    w.print(escape(id));
                    w.print("\",");
                }
            }
            w.println("}) {");
            w.indent();

            w.print("protected void load(final ");
            w.print(TypeDataStore.class.getName());
            w.println(" store) {");
            w.indent();

            if (!isEager) {
                w.print(GWT.class.getName());
                w.print(".runAsync(");
            }

            w.println("new %s() {", RunAsyncCallback.class.getName());
            w.indent();

            w.println("public void onSuccess() {");
            w.indent();

            w.println("load();");
            w.println("%s.get().setLoaded(getName());",
                    ConnectorBundleLoader.class.getName());

            // Close onSuccess method
            w.outdent();
            w.println("}");

            w.println("private void load() {");
            w.indent();

            String loadNativeJsBundle = "loadJsBundle";
            printBundleData(logger, w, bundle, loadNativeJsBundle);

            // Close load method
            w.outdent();
            w.println("}");

            // Separate method for loading native JS stuff (e.g. callbacks)
            String loadNativeJsMethodName = "loadNativeJs";
            // To support fields of type long (#13692)
            w.println("@com.google.gwt.core.client.UnsafeNativeLong");
            w.println("private native void %s(%s store) /*-{",
                    loadNativeJsMethodName, TypeDataStore.class.getName());
            w.indent();
            List<String> jsMethodNames = printJsBundleData(logger, w, bundle,
                    loadNativeJsMethodName);

            w.outdent();
            w.println("}-*/;");

            // Call all generated native method inside one Java method to avoid
            // refercences inside native methods to each other
            w.println("private void %s(%s store) {", loadNativeJsBundle,
                    TypeDataStore.class.getName());
            w.indent();
            printLoadJsBundleData(w, loadNativeJsBundle, jsMethodNames);
            w.outdent();
            w.println("}");

            // onFailure method declaration starts
            w.println("public void onFailure(Throwable reason) {");
            w.indent();

            w.println("%s.get().setLoadFailure(getName(), reason);",
                    ConnectorBundleLoader.class.getName());

            w.outdent();
            w.println("}");

            // Close new RunAsyncCallback() {}
            w.outdent();
            w.print("}");

            if (isEager) {
                w.println(".onSuccess();");
            } else {
                w.println(");");
            }

            // Close load method
            w.outdent();
            w.println("}");

            // Close add(new ...
            w.outdent();
            w.println("});");
        }

        if (cvalInfos != null && !cvalInfos.isEmpty()) {
            w.println("{");
            for (CValUiInfo c : cvalInfos) {
                if ("evaluation".equals(c.type)) {
                    w.println("cvals.add(new CValUiInfo(\"" + c.product
                            + "\", \"" + c.version + "\", \"" + c.widgetset
                            + "\", null));");
                }
            }
            w.println("}");
        }

        w.outdent();
        w.println("}");

        w.commit(logger);
    }
View Full Code Here

      String implClassName, PrintWriter printWriter, GinjectorBindings rootBindings)
      throws UnableToCompleteException {
    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
        implClassName);

    SourceWriter writer = null;

    try {
      composerFactory.addImplementedInterface(ReflectUtil.getSourceName(ginjectorInterface));

      writer = composerFactory.createSourceWriter(ctx, printWriter);

      String rootInjectorClass = ginjectorNameGenerator.getClassName(rootBindings);
      String rootFieldName = ginjectorNameGenerator.getFieldName(rootBindings);
      writer.beginJavaDocComment();
      writer.print("Top-level injector instance for injector " + rootBindings.getModule() + ".");
      writer.endJavaDocComment();
      writer.println("private final %1$s %2$s = new %1$s(this);", rootInjectorClass, rootFieldName);

      SourceWriteUtil sourceWriteUtil = sourceWriteUtilFactory.create(rootBindings);

      String staticInjectionInitialization = rootBindings.hasStaticInjectionRequestInSubtree()
          ? String.format("%s.initializeStaticInjections();\n", rootFieldName)
          : "";

      String eagerSingletonsInitialization = rootBindings.hasEagerSingletonBindingInSubtree()
          ? String.format("%s.initializeEagerSingletons();\n", rootFieldName)
          : "";

      sourceWriteUtil.writeMethod(writer, "public " + implClassName + "()", String.format(
          // To imitate the behavior of Guice and provide more predictable
          // bootstrap ordering, we initialize the injectors in two phases:
          // static injections first, followed by eager singletons.  Each of
          // these method calls performs all necessary initialization of the
          // given type in all fragments, ensuring that the initializers run in
          // the proper order.
          //
          // See http://code.google.com/p/google-guice/wiki/Bootstrap
          "%s%s", staticInjectionInitialization, eagerSingletonsInitialization));

      outputInterfaceMethods(rootBindings, ginjectorInterface, sourceWriteUtil, writer);
    } catch (NoSourceNameException e) {
      // TODO(schmitt): Collect errors and log list of them.
      logger.log(TreeLogger.Type.ERROR, e.getMessage(), e);
    }

    if (writer != null) {
      writer.commit(logger);
    }
  }
View Full Code Here

      return;
    }

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName,
        implClassName);
    SourceWriter writer = composerFactory.createSourceWriter(ctx, printWriter);

    FragmentMap fragments = new FragmentMap(bindings, packageName, implClassName,
        fragmentOutputterFactory);

    outputBindings(bindings, fragments, writer);
    errorManager.checkForError();

    fragments.commitAll();
    writer.commit(logger);
  }
View Full Code Here

  private SourceWriteUtil sourceWriteUtil;

  // TODO(schmitt):  Add unit tests for method and field inject generation.

  public void testWriteMethod() {
    SourceWriter writer = new UnitTestSourceWriter();

    String signature = "public void foo()";
    String body = "int bar;\\nString baz = \"la\";";

    sourceWriteUtil.writeMethod(writer, signature, body);

    assertEquals(signature + " {\\n" + body + "\\n}\\n\\n", writer.toString());
  }
View Full Code Here

    assertEquals(signature + " {\\n" + body + "\\n}\\n\\n", writer.toString());
  }

  public void testWriteNativeMethod() {
    SourceWriter writer = new UnitTestSourceWriter();

    String signature = "public native void foo()";
    String body = "int bar;\\nString baz = \"la\";";

    sourceWriteUtil.writeNativeMethod(writer, signature, body);

    assertEquals(signature + " /*-{\\n" + body + "\\n}-*/;\\n\\n", writer.toString());
  }
View Full Code Here

    ClassSourceFileComposerFactory composerFactory =
        new ClassSourceFileComposerFactory(packageName, newClassName);
    composerFactory.setSuperclass(requestedType.getQualifiedSourceName());
    composerFactory.addImport(GWT.class.getCanonicalName());
    SourceWriter writer = composerFactory
        .createSourceWriter(context, context.tryCreate(logger, packageName, newClassName));
    writer.println("public void initialize() {");
    writer.indent();
    writer.println(
        "((" +  ginjectorName + ") GWT.create(" + ginjectorName + ".class)).injectMembers(this);");
    writer.outdent();
    writer.println("}");
    writer.commit(logger);

    return packageName + "." + newClassName;
  }
View Full Code Here

        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;
  }
View Full Code Here

    String moduleName = requestedName + "Module";
    ClassSourceFileComposerFactory moduleFactory =
        new ClassSourceFileComposerFactory(packageName, moduleName);
    moduleFactory.setSuperclass(AbstractGinModule.class.getCanonicalName());
    moduleFactory.addImport(Names.class.getCanonicalName());
    SourceWriter moduleWriter = moduleFactory.createSourceWriter(context,
        context.tryCreate(logger, packageName, moduleName));

    moduleWriter.println("public void configure() {");
    moduleWriter.indent();
    for (JMethod method : requestedType.getMethods()) {
      if (method.getName().startsWith("set")) {
        String name = method.getParameters()[0].getAnnotation(Named.class).value();
        moduleWriter.println("bindConstant().annotatedWith(Names.named(\"" + name + "\")).to(\""
            + Math.pow(Integer.parseInt(name), 2) + "\");");
      }
    }
    moduleWriter.outdent();
    moduleWriter.println("}");
    moduleWriter.commit(logger);
    return moduleName;
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.user.rebind.SourceWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.