Example usage for com.google.gwt.user.rebind SourceWriter indentln

List of usage examples for com.google.gwt.user.rebind SourceWriter indentln

Introduction

In this page you can find the example usage for com.google.gwt.user.rebind SourceWriter indentln.

Prototype

void indentln(String s);

Source Link

Usage

From source file:org.rstudio.core.rebind.command.CommandBundleGenerator.java

License:Open Source License

private void emitConstructor(SourceWriter writer, ImageResourceInfo images) throws UnableToCompleteException {
    writer.println("public " + simpleName_ + "() {");

    // Get additional properties from XML resource file, if exists
    Map<String, Element> props = getCommandProperties();
    // Implement the methods for the commands
    for (JMethod method : commandMethods_)
        emitCommandInitializers(writer, props, method, images);

    writer.println();//from   www  .j av a 2 s.com
    writer.indentln("__registerShortcuts();");

    writer.println("}");
}

From source file:org.rstudio.core.rebind.command.CommandBundleGenerator.java

License:Open Source License

private void emitMenus(SourceWriter writer) throws UnableToCompleteException {
    for (JMethod method : menuMethods_) {
        String name = method.getName();
        NodeList nodes = getConfigDoc("/commands/menu[@id='" + name + "']");
        if (nodes.getLength() == 0) {
            logger_.log(TreeLogger.Type.ERROR, "Unable to find config info for menu " + name);
            throw new UnableToCompleteException();
        } else if (nodes.getLength() > 1) {
            logger_.log(TreeLogger.Type.ERROR, "Duplicate menu entries for menu " + name);
        }//ww w.  j  a  v a  2s  .  c om

        String menuClass = new MenuEmitter(logger_, context_, bundleType_, (Element) nodes.item(0)).generate();

        writer.println("public void " + name + "(MenuCallback callback) {");
        writer.indentln("new " + menuClass + "(this).createMenu(callback);");
        writer.println("}");
    }
}

From source file:org.rstudio.core.rebind.command.MenuEmitter.java

License:Open Source License

private void emitConstructor(SourceWriter writer, String className) {
    writer.println("public " + className + "(" + bundleType_.getQualifiedSourceName() + " commands) {");
    writer.indentln("this.cmds = commands;");
    writer.println("}");
}

From source file:org.switchyard.console.components.rebind.ComponentExtensionManagerGenerator.java

License:Apache License

private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className,
        List<JClassType> componentExtensionClasses) {
    PrintWriter pw = context.tryCreate(logger, packageName, className);
    if (pw == null) {
        return;//from   www  . j  av  a2 s  .  com
    }

    ClassSourceFileComposerFactory composerFactory = new ClassSourceFileComposerFactory(packageName, className);

    // imports
    composerFactory.addImport(HashMap.class.getCanonicalName());
    composerFactory.addImport(Map.class.getCanonicalName());
    composerFactory.addImport(ComponentProvider.class.getCanonicalName());
    composerFactory.addImport(ComponentExtensionManager.class.getCanonicalName());
    composerFactory.addImport(ComponentProviderProxyImpl.class.getCanonicalName());
    composerFactory.addImport(GWT.class.getCanonicalName());
    composerFactory.addImport(Inject.class.getCanonicalName());

    // interface
    composerFactory.addImplementedInterface(ComponentExtensionManager.class.getCanonicalName());

    SourceWriter sw = composerFactory.createSourceWriter(context, pw);

    // fields
    sw.println(
            "private Map<String, ComponentProviderProxy> _providers = new HashMap<String, ComponentProviderProxy>();");
    sw.println("private Map<String, String> _typeToName = new HashMap<String, String>();");

    // constructor
    sw.println("public " + className + "() {");
    sw.indent();
    for (JClassType extensionClass : componentExtensionClasses) {
        ComponentExtension extensionAnnotation = extensionClass.getAnnotation(ComponentExtension.class);
        sw.println("_providers.put(\"" + extensionAnnotation.componentName()
                + "\", new ComponentProviderProxyImpl(\"" + extensionAnnotation.displayName() + "\") {");
        sw.indent();
        sw.println("public ComponentProvider instantiate() {");
        sw.indentln("return GWT.create(" + extensionClass.getQualifiedSourceName() + ".class);");
        sw.println("}");
        sw.outdent();
        sw.println("});");
        for (String type : extensionAnnotation.activationTypes()) {
            sw.println("_typeToName.put(\"" + type + "\", \"" + extensionAnnotation.componentName() + "\");");
        }
    }
    sw.outdent();
    sw.println("}");

    // methods
    // getExtensionProviders
    sw.println("public Map<String, ComponentProviderProxy> getExtensionProviders() {");
    sw.indentln("return _providers;");
    sw.println("}");

    // getExtensionProviderByComponentName
    sw.println("public ComponentProviderProxy getExtensionProviderByComponentName(String componentName) {");
    sw.indent();
    sw.println("if (_providers.containsKey(componentName)) {");
    sw.indentln("return _providers.get(componentName);");
    sw.println("}");
    sw.println("return null;");
    sw.outdent();
    sw.println("}");

    // getExtensionProviderByTypeName
    sw.println("public ComponentProviderProxy getExtensionProviderByTypeName(String typeName) {");
    sw.indent();
    sw.println("if (_typeToName.containsKey(typeName)) {");
    sw.indentln("return getExtensionProviderByComponentName(_typeToName.get(typeName));");
    sw.println("}");
    sw.println("return null;");
    sw.outdent();
    sw.println("}");

    // close it out
    sw.outdent();
    sw.println("}");

    context.commit(logger, pw);
}

From source file:xapi.dev.generators.AbstractInjectionGenerator.java

License:Open Source License

public static InjectionCallbackArtifact ensureAsyncInjected(TreeLogger logger, String packageName,
        String className, String outputClass, GeneratorContext ctx) throws UnableToCompleteException {

    GwtInjectionMap gwtInjectionMap = getInjectionMap(logger, ctx);
    InjectionCallbackArtifact artifact = gwtInjectionMap.getOrCreateArtifact(ctx, packageName, className);
    if (artifact.isTargetUnbound()) {
        artifact.bindTo(outputClass);//from w w  w  .  java  2s  .  c o m
        ensureProviderClass(logger, packageName, artifact.getSimpleName(), artifact.getCanonicalName(),
                artifact.getBoundTarget(), ctx);
        logger = logger.branch(Type.TRACE,
                "Creating asynchronous callback for " + artifact.getCanonicalName() + " -> " + outputClass);
        String generatedName = InjectionUtils.generatedAsyncProviderName(artifact.getGeneratedName());
        String implPackage = artifact.getImplementationPackage();
        PrintWriter printWriter = ctx.tryCreate(logger, implPackage, generatedName);
        if (printWriter == null) {
            logger.log(Type.WARN,
                    "Could not create the source writer for " + implPackage + "." + generatedName);
            return artifact;
        }
        artifact.addCallback(implPackage + "." + generatedName + ".Deproxy");
        ctx.commitArtifact(logger, artifact);

        ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(implPackage,
                generatedName);
        composer.setPrivacy("public final");

        composer.addImport(com.google.gwt.core.client.GWT.class.getName());
        composer.addImport(RunAsyncCallback.class.getName());
        composer.addImport(Fifo.class.getName());
        composer.addImport(JsFifo.class.getName());
        composer.addImport(AsyncProxy.class.getName());
        composer.addImport(ApplyMethod.class.getName());
        composer.addImport(ReceivesValue.class.getName());
        composer.addImport(ReceiverAdapter.class.getCanonicalName());
        composer.addImport(artifact.getCanonicalName());

        String simpleName = artifact.getSimpleName();
        SourceWriter sw = composer.createSourceWriter(ctx, printWriter);

        sw.println();
        sw.println("static final class Callbacks implements ApplyMethod{");
        sw.indent();
        sw.println("public void apply(Object ... args){");
        sw.println("}");
        sw.outdent();
        sw.println("}");
        sw.println();

        sw.println("static final class Deproxy implements ReceivesValue<" + simpleName + ">{");
        sw.indent();
        sw.println("public final void set(final " + simpleName + " value){");
        sw.indentln("getter = new ReceiverAdapter<" + simpleName + ">(value);");
        sw.println("}");
        sw.outdent();
        sw.println("}");
        sw.println();

        sw.println("private static final class Proxy implements ReceivesValue<ReceivesValue<" + simpleName
                + ">>{");
        sw.indent();
        sw.println("public final void set(final ReceivesValue<" + simpleName + "> receiver){");
        sw.indent();

        sw.print("GWT.runAsync(");
        sw.println(artifact.getCanonicalName() + ".class,new Request(receiver));");

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

        sw.println("private static final class Request");
        sw.indent();
        sw.println("extends AsyncProxy<" + simpleName + "> ");
        sw.println("implements RunAsyncCallback{");

        DefermentWriter defer = new DefermentWriter(sw);
        defer.setStrategy(DefermentStrategy.NONE);

        sw.println("private static final Fifo<ReceivesValue<" + simpleName + ">> pending =");
        sw.indentln("JsFifo.newFifo();");
        sw.println();

        sw.println("protected Request(ReceivesValue<" + simpleName + "> receiver){");
        sw.indentln("accept(receiver);");
        sw.println("}");
        sw.println();

        sw.println("@Override");
        sw.println("protected final Fifo<ReceivesValue<" + simpleName + ">> pending(){");
        sw.indentln("return pending;");
        sw.println("}");
        sw.println();

        sw.println("protected final void dispatch(){");
        sw.indentln("go();");
        sw.println("}");
        sw.println();

        sw.println("public final void onSuccess(){");
        sw.indent();
        defer.printStart();

        sw.println("final " + simpleName + " value = ");
        sw.print(packageName + "." + InjectionUtils.generatedProviderName(simpleName));
        sw.println(".theProvider.get();");
        sw.println();

        sw.print("final ApplyMethod callbacks = GWT.create(");
        sw.print(packageName + ".impl." + generatedName + ".Callbacks.class");
        sw.println(");");
        sw.println("callbacks.apply(value);");
        sw.println();

        sw.println("apply(value);");
        sw.outdent();
        sw.println("}");
        sw.outdent();
        defer.printFinish();
        sw.println("}");
        sw.println();

        sw.println("private static ReceivesValue<ReceivesValue<" + simpleName + ">> getter = new Proxy();");
        sw.println();

        sw.println("static void request(final ReceivesValue<" + simpleName + "> request){");
        sw.indentln("getter.set(request);");
        sw.println("}");
        sw.println();

        sw.println("static void go(){");
        sw.indentln("request(null);");
        sw.println("}");
        sw.println();

        sw.println("private " + generatedName + "(){}");

        sw.commit(logger);

    } else {
        assert artifact.getBoundTarget().equals(outputClass) : "The injection target "
                + artifact.getCanonicalName() + " was bound " + "to " + artifact.getBoundTarget()
                + ", but you tried to bind it again, " + "to a different class: " + outputClass;
    }
    return artifact;
}