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

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

Introduction

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

Prototype

void outdent();

Source Link

Usage

From source file:org.cruxframework.crux.plugin.gadget.rebind.gwt.DefaultPreferenceGenerator.java

License:Apache License

/**
 * Write an instantiation expression for a given Preference subtype.
 */// w w  w  . j ava 2s. co m
public void writeInstantiation(TreeLogger logger, SourceWriter sw, JClassType extendsPreferenceType,
        JMethod prefMethod) {
    sw.println("new " + extendsPreferenceType.getParameterizedQualifiedSourceName() + "() {");
    sw.indent();

    sw.println("public String getName() {return \"" + prefMethod.getName() + "\";}");
    sw.outdent();
    sw.println("}");
}

From source file:org.cruxframework.crux.plugin.gadget.rebind.gwt.UserPreferencesGenerator.java

License:Apache License

@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
        throws UnableToCompleteException {

    // The TypeOracle knows about all types in the type system
    TypeOracle typeOracle = context.getTypeOracle();

    // Get a reference to the type that the generator should implement
    JClassType sourceType = typeOracle.findType(typeName);

    // Ensure that the requested type exists
    if (sourceType == null) {
        logger.log(TreeLogger.ERROR, "Could not find requested typeName", null);
        throw new UnableToCompleteException();
    }// w w  w  .  j  a v a 2 s  .c  om

    // Make sure the UserPreferences type is correctly defined
    validateType(logger, sourceType);

    // Pick a name for the generated class to not conflict.
    String generatedSimpleSourceName = sourceType.getSimpleSourceName() + "UserPreferencesImpl";

    // Begin writing the generated source.
    ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(sourceType.getPackage().getName(),
            generatedSimpleSourceName);
    f.addImport(GWT.class.getName());
    f.addImport(PreferencesUtil.class.getName());
    f.addImplementedInterface(typeName);

    // All source gets written through this Writer
    PrintWriter out = context.tryCreate(logger, sourceType.getPackage().getName(), generatedSimpleSourceName);

    // If an implementation already exists, we don't need to do any work
    if (out != null) {
        JClassType preferenceType = typeOracle.findType(Preference.class.getName().replace('$', '.'));
        assert preferenceType != null;

        // We really use a SourceWriter since it's convenient
        SourceWriter sw = f.createSourceWriter(context, out);

        for (JMethod m : sourceType.getOverridableMethods()) {
            JClassType extendsPreferenceType = m.getReturnType().isClassOrInterface();
            if (extendsPreferenceType == null) {
                logger.log(TreeLogger.ERROR,
                        "Return type of " + m.getName() + " is not a class or interface (must be assignable to "
                                + preferenceType.getName() + ").",
                        null);
                throw new UnableToCompleteException();
            }

            if (!preferenceType.isAssignableFrom(extendsPreferenceType)) {
                logger.log(TreeLogger.ERROR, "Cannot assign " + extendsPreferenceType.getQualifiedSourceName()
                        + " to " + preferenceType.getQualifiedSourceName(), null);
                throw new UnableToCompleteException();
            }

            // private final FooProperty __propName = new FooProperty()
            // {...}
            sw.print("private final " + extendsPreferenceType.getParameterizedQualifiedSourceName() + " __"
                    + m.getName() + " = ");
            writeInstantiation(logger, sw, extendsPreferenceType, m);
            sw.println(";");

            // public FooProperty property() { return __property; }
            sw.print("public ");
            sw.print(m.getReadableDeclaration(true, true, true, true, true));
            sw.println("{");
            sw.indent();
            sw.println("return __" + m.getName() + ";");
            sw.outdent();
            sw.println("}");
        }

        sw.commit(logger);
    }

    return f.getCreatedClassName();
}

From source file:org.cruxframework.crux.plugin.gadget.rebind.rpc.CruxGadgetProxyCreator.java

License:Apache License

/**
 * @param srcWriter//w  w  w. j  av a 2s. co  m
 */
private void generateGadgetProxyContructor(SourceWriter srcWriter) {
    srcWriter.println("public " + getGadgetProxySimpleName() + "() {");
    srcWriter.indent();

    srcWriter.println("super();");

    if (HangoutUtils.isHangoutGadget()) {
        srcWriter.println("GadgetsGwtRpc.redirectThroughProxy((ServiceDefTarget) this, "
                + EscapeUtils.quote(HangoutUtils.getDeployURL()) + ");");
    } else {
        srcWriter.println("GadgetsGwtRpc.redirectThroughProxy((ServiceDefTarget) this);");
    }

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

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateGetRegisteredAssetEditorFormatsMethod(SourceWriter sourceWriter,
        List<AssetEditorConfiguration> registeredEditors) {
    sourceWriter.println("public String[] getRegisteredAssetEditorFormats() {");
    sourceWriter.indent();//w w w.j  ava2s.c  om
    sourceWriter.println("String[] formats = new String[] {");
    int i = 0;
    for (AssetEditorConfiguration a : registeredEditors) {
        String format = a.getFormat();
        sourceWriter.print("\"" + format + "\"");
        if (i < registeredEditors.size() - 1) {
            sourceWriter.print(", ");
        }
        i++;
    }

    sourceWriter.println("};");
    sourceWriter.println("return formats;");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateGetAssetEditorMethod(SourceWriter sourceWriter,
        List<AssetEditorConfiguration> registeredEditors) {
    sourceWriter.println(/*w  w w  . jav  a 2s  .c  o  m*/
            "public Widget getAssetEditor(Asset asset, RuleViewer viewer, ClientFactory clientFactory, EventBus eventBus) {");
    sourceWriter.indent();

    for (AssetEditorConfiguration a : registeredEditors) {
        String format = a.getFormat();
        String assetEditorClassName = a.getEditorClass();
        sourceWriter.println("if(asset.getFormat().equals(\"" + format + "\")) {");
        sourceWriter.indent();
        sourceWriter
                .println("return new " + assetEditorClassName + "(asset, viewer, clientFactory, eventBus);");
        sourceWriter.outdent();
        sourceWriter.println("}");
    }
    sourceWriter.println("return new DefaultContentUploadEditor(asset, viewer, clientFactory, eventBus);");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateGetAssetEditorIcon(SourceWriter sourceWriter,
        List<AssetEditorConfiguration> registeredEditors) {
    sourceWriter.println("public ImageResource getAssetEditorIcon(String format) {");
    sourceWriter.indent();//from ww  w .  java2  s. c om

    for (AssetEditorConfiguration a : registeredEditors) {
        String format = a.getFormat();
        String iconName = a.getIcon();
        sourceWriter.println("if(format.equals(\"" + format + "\")) {");
        sourceWriter.indent();
        sourceWriter.println("return " + iconName + ";");
        sourceWriter.outdent();
        sourceWriter.println("}");
    }
    sourceWriter.println("return images.ruleAsset();");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.drools.guvnor.gwtutil.AssetEditorFactoryGenerator.java

License:Apache License

private void generateGetAssetEditorTitle(SourceWriter sourceWriter,
        List<AssetEditorConfiguration> registeredEditors) {
    sourceWriter.println("public String getAssetEditorTitle(String format) {");
    sourceWriter.indent();/*  w ww  .  j ava  2 s .co  m*/

    for (AssetEditorConfiguration a : registeredEditors) {
        String format = a.getFormat();
        String title = a.getTitle();
        sourceWriter.println("if(format.equals(\"" + format + "\")) {");
        sourceWriter.indent();
        sourceWriter.println("return " + title + ";");
        sourceWriter.outdent();
        sourceWriter.println("}");
    }
    sourceWriter.println("return \"\";");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.drools.guvnor.gwtutil.PerspectiveFactoryGenerator.java

License:Apache License

private void generateGetRegisteredAssetEditorFormatsMethod(SourceWriter sourceWriter,
        Map<String, List<ModuleEditorConfiguration>> registeredEditors) {
    sourceWriter.println("public String[] getRegisteredAssetEditorFormats(String moduleType) {");
    sourceWriter.indent();/*  ww w  .  jav  a 2s .  co  m*/
    sourceWriter.println("String formats = \"\";");

    for (List<ModuleEditorConfiguration> moduleEditors : registeredEditors.values()) {
        for (ModuleEditorConfiguration moduleEditorConfiguration : moduleEditors) {
            sourceWriter.println("if(\"" + moduleEditorConfiguration.getFormat() + "\".equals(moduleType)) {");
            sourceWriter.indent();
            sourceWriter.println("formats = \"" + moduleEditorConfiguration.getAssetEditorFormats() + "\";");
            sourceWriter.outdent();
            sourceWriter.println("}");
        }
    }

    sourceWriter.println("String[] results = formats.split(\",\");");

    sourceWriter.println("return results;");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.drools.guvnor.gwtutil.PerspectiveFactoryGenerator.java

License:Apache License

private void generateGetRegisteredModuleEditorFormatsMethod(SourceWriter sourceWriter,
        Map<String, List<ModuleEditorConfiguration>> registeredEditors) {
    sourceWriter.println("public String[] getRegisteredModuleEditorFormats(String perspectiveType) {");
    sourceWriter.indent();//from  ww w  .j a  va  2s.  c om

    for (String perspectiveType : registeredEditors.keySet()) {
        List<ModuleEditorConfiguration> moduleEditors = registeredEditors.get(perspectiveType);
        sourceWriter.println("if(\"" + perspectiveType + "\".equals(perspectiveType)) {");
        sourceWriter.indent();
        sourceWriter.println("String[] formats = new String[] {");
        int i = 0;
        for (ModuleEditorConfiguration a : moduleEditors) {
            String format = a.getFormat();
            sourceWriter.print("\"" + format + "\"");
            if (i < moduleEditors.size() - 1) {
                sourceWriter.print(", ");
            }
            i++;
        }

        sourceWriter.println("};");
        sourceWriter.println("return formats;");
        sourceWriter.outdent();
        sourceWriter.println("}");
    }

    sourceWriter.println("return null;");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.drools.guvnor.gwtutil.PerspectiveFactoryGenerator.java

License:Apache License

private void generateGetRegisteredPerspectiveTypesMethod(SourceWriter sourceWriter,
        Map<String, List<ModuleEditorConfiguration>> registeredEditors) {
    sourceWriter.println("public String[] getRegisteredPerspectiveTypes() {");
    sourceWriter.indent();/*w w w .  j  a v a  2  s .co  m*/
    sourceWriter.println("String[] formats = new String[] {\"soaservice\"};");
    //sourceWriter.println( "String[] formats = new String[] {\"author\", \"runtime\"};" );

    sourceWriter.println("return formats;");
    sourceWriter.outdent();
    sourceWriter.println("}");
}