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.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a function method./*from   ww  w  .  java  2  s. c o m*/
 *
 * @param sourceWriter The source writer.
 * @param logger The logger.
 * @param context The context.
 * @param method The method.
 * @param jsonFunctionAnnotation The JSON function annotation.
 * @throws UnableToCompleteException
 */
private void writeFunctionMethod(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context,
        JMethod method, JsonFunction jsonFunctionAnnotation) throws UnableToCompleteException {
    Class<?> functionClass = jsonFunctionAnnotation.klass();
    String functionMethodName = jsonFunctionAnnotation.method();

    StringBuilder typeParametersBuilder = new StringBuilder();

    JTypeParameter[] typeParameters = method.getTypeParameters();
    if (typeParameters.length != 0) {
        typeParametersBuilder.append("<");

        for (int i = 0; i < typeParameters.length; i++) {
            if (i != 0) {
                typeParametersBuilder.append(", ");
            }

            typeParametersBuilder.append(typeParameters[i].getQualifiedSourceName());
        }

        typeParametersBuilder.append("> ");
    }

    String returnTypeName = this.getTypeName(method.getReturnType());

    JClassType functionClassType = this.getType(logger, context, functionClass.getName().replace('$', '.'));

    StringBuilder methodParametersBuilder = new StringBuilder();
    StringBuilder functionArgumentsBuilder = new StringBuilder("this");

    JParameter[] methodParameters = method.getParameters();
    for (int i = 0; i < methodParameters.length; i++) {
        if (i != 0) {
            methodParametersBuilder.append(", ");
        }

        methodParametersBuilder.append(this.getTypeName(methodParameters[i].getType()));
        methodParametersBuilder.append(" arg").append(i);

        functionArgumentsBuilder.append(", arg").append(i);
    }

    sourceWriter.println("@Override");
    sourceWriter.println("public final " + typeParametersBuilder.toString() + returnTypeName + " "
            + method.getName() + "(" + methodParametersBuilder.toString() + ") {");
    sourceWriter.indent();
    sourceWriter.println(
            (!returnTypeName.equals("void") ? "return " : "") + functionClassType.getQualifiedSourceName() + "."
                    + functionMethodName + "(" + functionArgumentsBuilder.toString() + ");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write an exception method./*from   ww w  .  j  av  a 2s  .  c o  m*/
 *
 * @param sourceWriter The source writer.
 * @param logger The logger.
 * @param context The context.
 * @param method The method.
 * @param jsonExceptionAnnotation The JSON exception annotation.
 * @throws UnableToCompleteException
 */
private void writeExceptionMethod(SourceWriter sourceWriter, TreeLogger logger, GeneratorContext context,
        JMethod method, JsonException jsonExceptionAnnotation) throws UnableToCompleteException {
    Class<?> exceptionClass = jsonExceptionAnnotation.klass();
    String message = jsonExceptionAnnotation.message();

    StringBuilder typeParametersBuilder = new StringBuilder();

    JTypeParameter[] typeParameters = method.getTypeParameters();
    if (typeParameters.length != 0) {
        typeParametersBuilder.append("<");

        for (int i = 0; i < typeParameters.length; i++) {
            if (i != 0) {
                typeParametersBuilder.append(", ");
            }

            typeParametersBuilder.append(typeParameters[i].getQualifiedSourceName());
        }

        typeParametersBuilder.append("> ");
    }

    String returnTypeName = this.getTypeName(method.getReturnType());

    StringBuilder methodParametersBuilder = new StringBuilder();

    JParameter[] methodParameters = method.getParameters();
    for (int i = 0; i < methodParameters.length; i++) {
        if (i != 0) {
            methodParametersBuilder.append(", ");
        }

        methodParametersBuilder.append(this.getTypeName(methodParameters[i].getType()));
        methodParametersBuilder.append(" arg").append(i);
    }

    JClassType exceptionClassType = this.getType(logger, context, exceptionClass.getName().replace('$', '.'));

    sourceWriter.println("@Override");
    sourceWriter.println("public final " + typeParametersBuilder.toString() + returnTypeName + " "
            + method.getName() + "(" + methodParametersBuilder.toString() + ") {");
    sourceWriter.indent();
    sourceWriter.println("throw new " + exceptionClassType.getQualifiedSourceName() + "("
            + (!message.isEmpty() ? toQuotedString(message) : "") + ");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a has property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 *//*from   w  ww  .  j  a v  a  2 s .  c  o  m*/
private void writeHasPropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName) {
    sourceWriter.println("@Override");
    sourceWriter.println("public final boolean " + methodName + "() {");
    sourceWriter.indent();
    sourceWriter.println("return this.hasProperty(\"" + propertyName + "\");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write an is null property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 *//* ww  w.  j  a  v a  2s.  co m*/
private void writeIsNullPropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName) {
    sourceWriter.println("@Override");
    sourceWriter.println("public final boolean " + methodName + "() {");
    sourceWriter.indent();
    sourceWriter.println("return this.isNullProperty(\"" + propertyName + "\");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a delete property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 *//*w w  w  .  ja  va2  s .  c  o m*/
private void writeDeletePropertyMethod(SourceWriter sourceWriter, String methodName, String propertyName) {
    sourceWriter.println("@Override");
    sourceWriter.println("public final boolean " + methodName + "() {");
    sourceWriter.indent();
    sourceWriter.println("return this.deleteProperty(\"" + propertyName + "\");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a get JSON primitive property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 * @param primitiveTypeName The name of the JSON primitive type.
 * @param primitiveMethodName The name of the JSON primitive method.
 *//*  w w  w.  j  av  a2  s .co m*/
private void writeGetJsonPrimitivePropertyMethod(SourceWriter sourceWriter, String methodName,
        String propertyName, String primitiveTypeName, String primitiveMethodName) {
    sourceWriter.println("@Override");
    sourceWriter.println("public final " + primitiveTypeName + " " + methodName + "() {");
    sourceWriter.indent();
    sourceWriter.println("return this." + primitiveMethodName + "(\"" + propertyName + "\");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a set JSON primitive property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 * @param primitiveTypeName The name of the JSON primitive type.
 * @param primitiveMethodName The name of the JSON primitive method.
 *///from w  ww . j a  v a2  s  . c  o m
private void writeSetJsonPrimitivePropertyMethod(SourceWriter sourceWriter, String methodName,
        String propertyName, String primitiveTypeName, String primitiveMethodName) {
    sourceWriter.println("@Override");
    sourceWriter
            .println("public final void " + methodName + "(" + primitiveTypeName + " " + propertyName + ") {");
    sourceWriter.indent();
    sourceWriter.println("this." + primitiveMethodName + "(\"" + propertyName + "\", " + propertyName + ");");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a get Java primitive property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 * @param primitiveTypeName The name of the Java primitive type.
 * @param primitiveWrapperTypeName The name of the Java primitive wrapper type.
 * @param jsonPrimitiveMethodName The name of the JSON primitive method.
 * @param defaultPrimitiveValue The default primitive value.
 *//*from w  w w .ja v a 2s  .co  m*/
private void writeGetJavaPrimitivePropertyMethod(SourceWriter sourceWriter, String methodName,
        String propertyName, String primitiveTypeName, String primitiveWrapperTypeName,
        String jsonPrimitiveMethodName, String defaultPrimitiveValue) {
    sourceWriter.println("@Override");
    sourceWriter.println("public final " + primitiveTypeName + " " + methodName + "() {");
    sourceWriter.indent();
    sourceWriter.println(primitiveWrapperTypeName + " _" + propertyName + " = this." + jsonPrimitiveMethodName
            + "(\"" + propertyName + "\");");
    sourceWriter.println();
    sourceWriter.println("return _" + propertyName + " != null ? _" + propertyName + "." + primitiveTypeName
            + "Value() : " + defaultPrimitiveValue + ";");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a set Java primitive property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 * @param primitiveTypeName The name of the Java primitive type.
 * @param primitiveWrapperTypeName The name of the Java primitive wrapper type.
 * @param jsonPrimitiveMethodName The name of the JSON primitive method.
 *//* w  ww. j a  va 2s  .  co  m*/
private void writeSetJavaPrimitivePropertyMethod(SourceWriter sourceWriter, String methodName,
        String propertyName, String primitiveTypeName, String primitiveWrapperTypeName,
        String jsonPrimitiveMethodName) {
    sourceWriter.println("@Override");
    sourceWriter
            .println("public final void " + methodName + "(" + primitiveTypeName + " " + propertyName + ") {");
    sourceWriter.indent();
    sourceWriter.println("this." + jsonPrimitiveMethodName + "(\"" + propertyName + "\", "
            + primitiveWrapperTypeName + ".valueOf(" + propertyName + "));");
    sourceWriter.outdent();
    sourceWriter.println("}");
}

From source file:org.kjots.json.object.gwt.rebind.GwtJsonObjectGenerator.java

License:Apache License

/**
 * Write a get Java character primitive property method for the property with the given name.
 *
 * @param sourceWriter The source writer.
 * @param methodName The name of the method.
 * @param propertyName The name of the property.
 *//*from   w ww . ja v a2 s .co  m*/
private void writeGetJavaCharacterPrimitivePropertyMethod(SourceWriter sourceWriter, String methodName,
        String propertyName) {
    sourceWriter.println("@Override");
    sourceWriter.println("public final char " + methodName + "() {");
    sourceWriter.indent();
    sourceWriter.println(
            "java.lang.String _" + propertyName + " = this.getStringProperty(\"" + propertyName + "\");");
    sourceWriter.println();
    sourceWriter.println("return _" + propertyName + " != null && !_" + propertyName + ".isEmpty() ? _"
            + propertyName + ".charAt(0) : '\\0';");
    sourceWriter.outdent();
    sourceWriter.println("}");
}