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.pentaho.mantle.rebind.EventBusUtilGenerator.java

License:Open Source License

private void generateConstructor(SourceWriter sourceWriter) {
    // start constructor source generation
    sourceWriter.println("public " + className + "() { ");
    sourceWriter.indent();//ww w .  jav  a  2 s .c  o m
    sourceWriter.println("super();");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.pentaho.ui.xul.gwt.generators.EventHandlerGenerator.java

License:Open Source License

private void generateClass(TreeLogger logger, GeneratorContext context) {

    // get print writer that receives the source code
    PrintWriter printWriter = null;
    printWriter = context.tryCreate(logger, packageName, className);
    // print writer if null, source code has ALREADY been generated, return
    if (printWriter == null) {
        return;/*w w w .j  ava2s  . com*/
    }

    // init composer, set class properties, create source writer
    ClassSourceFileComposerFactory composer = null;
    composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImplementedInterface("org.pentaho.ui.xul.gwt.util.EventHandlerWrapper");
    composer.addImport("org.pentaho.ui.xul.impl.XulEventHandler");

    SourceWriter sourceWriter = null;
    sourceWriter = composer.createSourceWriter(context, printWriter);

    // generator constructor source code
    generateConstructor(sourceWriter);

    generateMethods(sourceWriter);

    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");

    // commit generated class
    context.commit(logger, printWriter);

}

From source file:org.pentaho.ui.xul.gwt.generators.EventHandlerGenerator.java

License:Open Source License

private void generateMethods(SourceWriter sourceWriter) {

    sourceWriter.println("public void execute(String method, Object[] args) { ");
    sourceWriter.indent();// ww w  . j  av  a2s  .  c o m

    try {
        JClassType classType = typeOracle.getType(typeName);

        do {
            for (JMethod m : classType.getMethods()) {
                String methodName = m.getName();

                if (!m.isPublic()) {
                    continue;
                }

                sourceWriter.println("if(method.equals(\"" + methodName + "\")){");
                sourceWriter.indent();

                boolean firstParam = true;
                // method call
                sourceWriter.print("handler." + methodName + "(");
                int argPos = 0;
                for (JParameter param : m.getParameters()) {
                    if (!firstParam) {
                        sourceWriter.print(", ");
                    } else {
                        firstParam = false;
                    }
                    sourceWriter.print("(" + boxPrimative(param.getType()) + ") args[" + argPos + "]");
                    argPos++;
                }
                sourceWriter.print(");");
                // end method call

                sourceWriter.println("return;");
                sourceWriter.outdent();
                sourceWriter.println("}");
            }
        } while ((classType = classType.getSuperclass()).getSimpleSourceName().equals("Object") == false);

    } catch (Exception e) {

        // record to logger that Map generation threw an exception
        logger.log(TreeLogger.ERROR, "PropertyMap ERROR!!!", e);

    }
    sourceWriter.println(
            "System.err.println(\"ERROR: method '\" + method + \"' not annotated with EventMethod.\");");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println(handlerClassName + " handler;");

    sourceWriter.println("public void setHandler(XulEventHandler handler) { ");
    sourceWriter.indent();
    sourceWriter.println("this.handler = (" + handlerClassName + ") handler;");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public XulEventHandler getHandler() { ");
    sourceWriter.indent();
    sourceWriter.println("return this.handler;");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public String getName() { ");
    sourceWriter.indent();
    sourceWriter.println("return this.handler.getName();");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public Object getData() { ");
    sourceWriter.indent();
    sourceWriter.println("return null;");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public void setData(Object o) { ");
    sourceWriter.println("}");

}

From source file:org.pentaho.ui.xul.gwt.generators.EventHandlerGenerator.java

License:Open Source License

private void generateConstructor(SourceWriter sourceWriter) {

    // start constructor source generation
    sourceWriter.println("public " + className + "() { ");
    sourceWriter.indent();/*from w w w  .  jav a2s  .c o  m*/
    sourceWriter.println("super();");

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

}

From source file:org.pentaho.ui.xul.gwt.generators.TypeControllerGenerator.java

License:Open Source License

private void generateClass(TreeLogger logger, GeneratorContext context) {

    // get print writer that receives the source code
    PrintWriter printWriter = null;
    printWriter = context.tryCreate(logger, packageName, className);
    // print writer if null, source code has ALREADY been generated, return
    if (printWriter == null) {
        return;//from  www.  j  a  v  a  2 s .  com
    }

    // init composer, set class properties, create source writer
    ClassSourceFileComposerFactory composer = null;
    composer = new ClassSourceFileComposerFactory(packageName, className);
    composer.addImplementedInterface("org.pentaho.ui.xul.gwt.binding.TypeController");
    composer.addImport("org.pentaho.ui.xul.gwt.binding.*");
    composer.addImport("java.util.Map");
    composer.addImport("java.util.HashMap");
    composer.addImport("org.pentaho.ui.xul.XulException");

    SourceWriter sourceWriter = null;
    sourceWriter = composer.createSourceWriter(context, printWriter);

    // generator constructor source code
    generateConstructor(sourceWriter);

    writeMethods(sourceWriter);

    // close generated class
    sourceWriter.outdent();
    sourceWriter.println("}");

    // commit generated class
    context.commit(logger, printWriter);

}

From source file:org.pentaho.ui.xul.gwt.generators.TypeControllerGenerator.java

License:Open Source License

private void generateConstructor(SourceWriter sourceWriter) {

    sourceWriter.println(/*from w w w .j a  v a2  s . c  o m*/
            "public Map<String, GwtBindingMethod> wrappedTypes = new HashMap<String, GwtBindingMethod>();");

    // start constructor source generation
    sourceWriter.println("public " + className + "() { ");
    sourceWriter.indent();
    sourceWriter.println("super();");

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

}

From source file:org.pentaho.ui.xul.gwt.generators.TypeControllerGenerator.java

License:Open Source License

private void writeMethods(SourceWriter sourceWriter) {
    sourceWriter.println("public GwtBindingMethod findGetMethod(Object obj, String propertyName){");
    sourceWriter.indent();/*from  w w w  .  j  a v a2s .c o m*/

    sourceWriter.println(
            "GwtBindingMethod retVal = findMethod(obj,\"get\"+propertyName.substring(0,1).toUpperCase()"
                    + "+propertyName.substring(1));");

    sourceWriter.println("if(retVal == null){");
    sourceWriter.indent();
    sourceWriter
            .println("retVal = findMethod(obj,\"is\"+propertyName.substring(0,1).toUpperCase()+propertyName."
                    + "substring(1));");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("return retVal;");

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

    sourceWriter.println("public GwtBindingMethod findSetMethod(Object obj, String propertyName){");
    sourceWriter.indent();

    sourceWriter.println("return findMethod(obj,\"set\"+propertyName.substring(0,1).toUpperCase()+propertyName"
            + ".substring(1));");
    sourceWriter.outdent();
    sourceWriter.println("}");

    sourceWriter.println("public GwtBindingMethod findMethod(Object obj, String propertyName){");
    sourceWriter.indent();

    sourceWriter.println("return findOrCreateMethod(obj.getClass().getName(), propertyName);");
    sourceWriter.outdent();
    sourceWriter.println("}");

    createFindMethod(sourceWriter);
}

From source file:org.pentaho.ui.xul.gwt.generators.TypeControllerGenerator.java

License:Open Source License

private void createFindMethod(SourceWriter sourceWriter) {

    // We create more than one findMethod as the body of one method would be too large. This is the int that we
    // increment to add to the name
    // i.e. findMethod0()
    int methodNum = 0;

    // This int keeps track of how many methods are generated. When it gets to 200 we create a new findMethodX()
    // and chain it to the previous.
    int methodCount = 0;

    sourceWriter.println("private GwtBindingMethod findOrCreateMethod(String obj, String methodName){ ");
    sourceWriter.indent();//from ww  w .  j a  va2  s  . c  o m

    sourceWriter.println("GwtBindingMethod newMethod;");

    // dummy first condition, rest are "else if". Keeps us from having conditional logic.
    sourceWriter.println("if(false){ }");

    for (JClassType type : implementingTypes) {

        // close last method, chain it to a new one.
        if (methodCount > 200) {
            sourceWriter.println("return findOrCreateMethod" + (methodNum) + "(obj, methodName);");
            sourceWriter.println("}");

            sourceWriter.println("private GwtBindingMethod findOrCreateMethod" + (methodNum++)
                    + "(String obj, String methodName){ ");
            sourceWriter.println("GwtBindingMethod newMethod;");
            // dummy first condition, rest are "else if". Keeps us from having conditional logic.
            sourceWriter.println("if(false){ }");

            methodCount = 0;
        }

        String keyRoot = generateTypeKey(type);

        // if(type.isAbstract()){
        // System.out.println("abstract");
        // continue;
        // }

        // determine if there are any methods that are bindable before writing out conditional for class

        JClassType loopType = type;
        boolean hasBindableMethods = false;
        JClassType eventSourceType = null;
        try {
            eventSourceType = typeOracle.getType("org.pentaho.ui.xul.XulEventSource");
        } catch (NotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        //CHECKSTYLE IGNORE Indentation FOR NEXT 1 LINES
        outer: while (loopType.getSuperclass() != null
                && loopType.getSimpleSourceName().equals("Object") == false
                && loopType.isAssignableTo(eventSourceType)) {

            for (JMethod m : loopType.getMethods()) {
                if (m.isPublic() && m.getAnnotation(Bindable.class) != null) {
                    hasBindableMethods = true;
                    break outer;
                }
            }
            loopType = loopType.getSuperclass();
        }
        if (hasBindableMethods == false) {
            continue;
        }
        sourceWriter.println("else if(obj.equals(\"" + type.getQualifiedSourceName() + "\")){ ");
        try {

            loopType = type;
            sourceWriter.indent();

            // Loop over class heirarchy and generate methods for every object that is declared a XulEventSource
            while (loopType.getSuperclass() != null && loopType.getSimpleSourceName().equals("Object") == false
                    && loopType.isAssignableTo(eventSourceType)) {
                String superName = generateTypeKey(loopType);

                boolean first = true;
                for (JMethod m : loopType.getMethods()) {
                    methodCount++;
                    if (!m.isPublic() || m.getAnnotation(Bindable.class) == null) {
                        continue;
                    }

                    sourceWriter.println(
                            (first ? "" : "else ") + "if(methodName.equals(\"" + m.getName() + "\")){ ");
                    if (first) {
                        first = false;
                    }
                    sourceWriter.indent();

                    String methodName = m.getName();

                    // check to see if we've already processed this classes' method. Point to that class instead.
                    if (generatedMethods.contains((superName + "_" + methodName).toLowerCase())
                            && type != loopType) {

                        sourceWriter.println("return findOrCreateMethod(\"" + superName + "\", methodName);");

                    } else {
                        // See if it's already been created and cached. If so, return that.
                        String keyName = (keyRoot + "_" + methodName).toLowerCase();

                        sourceWriter.println("GwtBindingMethod found = wrappedTypes.get(\"" + keyName + "\");");
                        sourceWriter.println("if(found != null){");
                        sourceWriter.indent();
                        sourceWriter.println("return found;");
                        sourceWriter.outdent();
                        sourceWriter.println("} else {");
                        sourceWriter.indent();

                        // Not cached, create a new instance and put it in the cache.
                        sourceWriter.println("newMethod = new GwtBindingMethod(){");

                        sourceWriter.println(
                                "public Object invoke(Object obj, Object[] args) throws XulException { ");
                        sourceWriter.indent();
                        sourceWriter.println("try{");
                        sourceWriter.println(loopType.getQualifiedSourceName() + " target = ("
                                + loopType.getQualifiedSourceName() + ") obj;");

                        JParameter[] params = m.getParameters();
                        String argList = "";
                        int pos = 0;
                        for (JParameter param : params) {
                            if (pos > 0) {
                                argList += ", ";
                            }
                            argList += "(" + getTypeName(param.getType()) + ") args[" + pos + "]";
                            pos++;
                        }

                        if (isVoidReturn(m.getReturnType())) {
                            sourceWriter.println("target." + methodName + "(" + argList + ");");
                            sourceWriter.println("return null;");
                        } else {
                            sourceWriter.println("return " + boxReturnType(m) + " target." + methodName + "("
                                    + argList + ");");
                        }

                        sourceWriter.println(
                                "}catch(Exception e){ e.printStackTrace(); throw new XulException(\"error with "
                                        + type.getQualifiedSourceName() + "\"+e.getMessage());}");
                        sourceWriter.println("}");

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

                        // Add it to the HashMap cache as type and decendant type if available.
                        sourceWriter.println("wrappedTypes.put((\"" + keyName + "\"), newMethod);");
                        if (keyRoot.equals(superName) == false) {
                            sourceWriter.println("wrappedTypes.put((\"" + keyName + "\"), newMethod);");
                        }
                        generatedMethods.add((keyRoot + "_" + methodName).toLowerCase());
                        generatedMethods.add((superName + "_" + methodName).toLowerCase());

                        sourceWriter.println("return newMethod;");

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

                    sourceWriter.println("}");

                }

                // go up a level in the heirarchy and check again.
                loopType = loopType.getSuperclass();
            }
            sourceWriter.outdent();
            sourceWriter.println("}");

        } catch (Exception e) {

            // record to logger that Map generation threw an exception
            logger.log(TreeLogger.ERROR, "PropertyMap ERROR!!!", e);

        }

    }

    sourceWriter.outdent();

    // This is the end of the line, if not found return null.
    sourceWriter.println("return null;");
    sourceWriter.println("}");
}

From source file:org.rapla.rest.gwtjsonrpc.rebind.ProxyCreator.java

License:Apache License

private void generateProxyConstructor(@SuppressWarnings("unused") final TreeLogger logger,
        final SourceWriter w) {
    final RemoteServiceRelativePath relPath = svcInf.getAnnotation(RemoteServiceRelativePath.class);
    if (relPath != null) {
        w.println();//from  ww w .  j a v  a 2 s  .  com
        w.println("public " + getProxySimpleName() + "() {");
        w.indent();
        w.println("setServiceEntryPoint(GWT.getModuleBaseURL() + \"" + relPath.value() + "\");");
        w.outdent();
        w.println("}");
    }
}

From source file:org.rapla.rest.gwtjsonrpc.rebind.ProxyCreator.java

License:Apache License

private void generateProxyCallCreator(final TreeLogger logger, final SourceWriter w)
        throws UnableToCompleteException {
    String callName = getJsonCallClassName(logger);
    w.println();//from  w  w w  .  j a  v  a  2  s  .com
    w.println("@Override");
    w.print("protected <T> ");
    w.print(callName);
    w.print("<T> newJsonCall(final AbstractJsonProxy proxy, ");
    w.print("final String methodName, final String reqData, ");
    w.println("final ResultDeserializer<T> ser) {");
    w.indent();

    w.print("return new ");
    w.print(callName);
    w.println("<T>(proxy, methodName, reqData, ser);");

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