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

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

Introduction

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

Prototype

void print(String s);

Source Link

Usage

From source file:com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory.java

License:Apache License

private void generateClass(TreeLogger logger, GeneratorContext context, String packageName, String className,
        String requestedType) throws Exception {
    PrintWriter printWriter = context.tryCreate(logger, packageName, className);
    if (printWriter == null) {
        return;//  w  w w. j  a v  a 2s .c o m
    }

    List<CValUiInfo> cvalInfos = null;
    try {
        if (cvalChecker != null) {
            cvalInfos = cvalChecker.run();
            // Don't run twice
            cvalChecker = null;
        }
    } catch (InvalidCvalException e) {
        System.err.println("\n\n\n\n" + CvalChecker.LINE);
        for (String line : e.getMessage().split("\n")) {
            System.err.println(line);
        }
        System.err.println(CvalChecker.LINE + "\n\n\n\n");
        System.exit(1);
        throw new UnableToCompleteException();
    }

    List<ConnectorBundle> bundles = buildBundles(logger, context.getTypeOracle());

    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);
}

From source file:com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory.java

License:Apache License

public static void writeClassLiteral(SourceWriter w, JType type) {
    w.print(getClassLiteralString(type));
}

From source file:com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory.java

License:Apache License

public static void writeTypeCreator(SourceWriter sourceWriter, JType type) {
    String typeName = ConnectorBundleLoaderFactory.getBoxedTypeName(type);
    JParameterizedType parameterized = type.isParameterized();
    if (parameterized != null) {
        sourceWriter.print("new Type(\"" + typeName + "\", ");
        sourceWriter.print("new Type[] {");
        JClassType[] typeArgs = parameterized.getTypeArgs();
        for (JClassType jClassType : typeArgs) {
            writeTypeCreator(sourceWriter, jClassType);
            sourceWriter.print(", ");
        }//from   ww  w  .j a  v  a 2  s  . c o  m
        sourceWriter.print("}");
    } else {
        sourceWriter.print("new Type(" + typeName + ".class");
    }
    sourceWriter.print(")");
}

From source file:com.vaadin.server.widgetsetutils.metadata.ArraySerializer.java

License:Apache License

@Override
protected void printDeserializerBody(TreeLogger logger, SourceWriter w, String type, String jsonValue,
        String connection) {/*from  w  ww  .  ja  v  a2 s  .c  o  m*/
    JType leafType = arrayType.getLeafType();
    int rank = arrayType.getRank();

    w.println(JsonArray.class.getName() + " jsonArray = (" + JsonArray.class.getName() + ")" + jsonValue + ";");

    // Type value = new Type[jsonArray.size()][][];
    w.print(arrayType.getQualifiedSourceName() + " value = new " + leafType.getQualifiedSourceName()
            + "[jsonArray.length()]");
    for (int i = 1; i < rank; i++) {
        w.print("[]");
    }
    w.println(";");

    w.println("for(int i = 0 ; i < value.length; i++) {");
    w.indent();

    JType componentType = arrayType.getComponentType();

    w.print("value[i] = (" + ConnectorBundleLoaderFactory.getBoxedTypeName(componentType) + ") "
            + JsonDecoder.class.getName() + ".decodeValue(");
    ConnectorBundleLoaderFactory.writeTypeCreator(w, componentType);
    w.print(", jsonArray.get(i), null, " + connection + ")");

    w.println(";");

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

    w.println("return value;");
}

From source file:com.vaadin.server.widgetsetutils.metadata.ArraySerializer.java

License:Apache License

@Override
protected void printSerializerBody(TreeLogger logger, SourceWriter w, String value,
        String applicationConnection) {
    JType componentType = arrayType.getComponentType();

    w.println(JsonArray.class.getName() + " values = " + Json.class.getName() + ".createArray();");
    // JPrimitiveType primitive = componentType.isPrimitive();
    w.println("for (int i = 0; i < " + value + ".length; i++) {");
    w.indent();/*from  w ww. j  av  a  2  s  .  c o m*/
    w.print("values.set(i, ");
    w.print(JsonEncoder.class.getName() + ".encode(" + value + "[i],");
    ConnectorBundleLoaderFactory.writeTypeCreator(w, componentType);
    w.print(", " + applicationConnection + ")");
    w.println(");");
    w.outdent();
    w.println("}");
    w.println("return values;");
}

From source file:com.vaadin.server.widgetsetutils.metadata.CustomSerializer.java

License:Apache License

@Override
public void writeSerializerInstantiator(TreeLogger logger, SourceWriter w) throws UnableToCompleteException {
    w.print("return ");
    w.print(GWT.class.getCanonicalName());
    w.print(".create(");
    ConnectorBundleLoaderFactory.writeClassLiteral(w, serializerType);
    w.println(");");
}

From source file:com.vaadin.server.widgetsetutils.metadata.FieldProperty.java

License:Apache License

@Override
public void writeGetterBody(TreeLogger logger, SourceWriter w, String beanVariable) {
    String value = String.format("%s.@%s::%s", beanVariable, getBeanType().getQualifiedSourceName(), getName());
    w.print("return ");
    w.print(boxValue(value));//from ww w  . ja v a  2  s.  c o  m
    w.println(";");
}

From source file:com.vaadin.server.widgetsetutils.metadata.JsonSerializer.java

License:Apache License

@Override
public void writeSerializerInstantiator(TreeLogger logger, SourceWriter w) throws UnableToCompleteException {

    w.print("return new ");
    w.print(JSONSerializer.class.getCanonicalName());
    w.print("<");
    w.print(type.getQualifiedSourceName());
    w.println(">() {");
    w.indent();//  w  w w .  ja v  a 2 s .c o m

    writeSerializerBody(logger, w);

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

From source file:com.vaadin.server.widgetsetutils.metadata.MethodProperty.java

License:Apache License

@Override
public void writeGetterBody(TreeLogger logger, SourceWriter w, String beanVariable) {
    String value = String.format("%s.@%s::%s()()", beanVariable, getBeanType().getQualifiedSourceName(),
            getter);/*w  w w.  ja  v  a2s.  c o m*/
    w.print("return ");
    w.print(boxValue(value));
    w.println(";");
}

From source file:com.vaadin.terminal.gwt.widgetsetutils.AcceptCriteriaFactoryGenerator.java

License:Open Source License

private void generateInstantiatorMethod(SourceWriter sourceWriter, GeneratorContext context,
        TreeLogger logger) {//from ww w  .ja  v a  2 s.  c om

    sourceWriter.println("public VAcceptCriterion get(String name) {");
    sourceWriter.indent();

    sourceWriter.println("name = name.intern();");

    Collection<Class<? extends AcceptCriterion>> clientSideVerifiableCriterion = ClassPathExplorer
            .getCriterion();

    for (Class<? extends AcceptCriterion> class1 : clientSideVerifiableCriterion) {
        logger.log(Type.INFO, "creating mapping for " + class1.getCanonicalName());
        String canonicalName = class1.getCanonicalName();
        Class<? extends VAcceptCriterion> clientClass = class1.getAnnotation(ClientCriterion.class).value();
        sourceWriter.print("if (\"");
        sourceWriter.print(canonicalName);
        sourceWriter.print("\" == name) return GWT.create(");
        sourceWriter.print(clientClass.getCanonicalName());
        sourceWriter.println(".class );");
        sourceWriter.print("else ");
    }

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