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:org.sprintapi.hyperdata.gwt.ArrayAdapterGenerator.java

License:Apache License

private void composeCreateInstanceMethod(SourceWriter sourceWriter, JArrayType parameterizedType) {
    sourceWriter.print("public java.lang.Object createInstance(int length, int dimension) {");

    sourceWriter.print("   if (dimension == 0) {");

    String suffix = "";
    for (int i = 0; i < parameterizedType.getRank(); i++) {
        sourceWriter.print("   } else if (dimension == " + (i + 1) + ") {");
        sourceWriter.print("      return new " + parameterizedType.getLeafType().getQualifiedSourceName()
                + "[length]" + suffix + ";");
        suffix += "[]";
    }/*from ww  w .j a v a 2  s.  co  m*/

    sourceWriter.print("   }");
    sourceWriter.print("  return null;");
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.ArrayAdapterGenerator.java

License:Apache License

private void composeDimesionMethod(SourceWriter sourceWriter, JArrayType parameterizedType) {
    sourceWriter.print("public int maxDimension() {");
    sourceWriter.print("  return " + parameterizedType.getRank() + ";");
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private void composeSetPropertyValueMethod(SourceWriter sourceWriter, JClassType parameterizedType) {
    sourceWriter.print("public void setPropertyValue(" + parameterizedType.getQualifiedSourceName()
            + " object, String name, java.lang.Object value) throws org.sprintapi.hyperdata.gwt.client.AdapterException {");
    if (parameterizedType.getInheritableMethods() != null) {
        int count = 0;
        for (JMethod method : parameterizedType.getInheritableMethods()) {
            if (method.isAnnotationPresent(HyperdataIgnore.class)) {
                continue;
            }//from ww  w.ja v a 2s .c  om
            if (method.isPublic() && method.getName().startsWith("set")) {
                if (count > 0) {
                    sourceWriter.print(" else ");
                }
                sourceWriter
                        .print("name = java.lang.Character.toUpperCase(name.charAt(0)) + name.substring(1);");
                sourceWriter
                        .print("if (\"" + method.getName().substring("get".length()) + "\".equals(name)) {");
                //TODO check value type
                //TODO isPrimitive
                sourceWriter.print("  object." + method.getName() + "(("
                        + method.getParameterTypes()[0].getQualifiedSourceName() + ")value);");
                sourceWriter.print("  return;");
                sourceWriter.print("}");
                count += 1;
            }
        }
    }
    //        sourceWriter.print("  throw new org.sprintapi.gwt.converter.client.ConverterException(\"There is no getter for '\" + name  + \"'.\");");
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private void composeGetPropertyValueMethod(SourceWriter sourceWriter, JClassType parameterizedType) {
    sourceWriter.print("public java.lang.Object getPropertyValue(" + parameterizedType.getQualifiedSourceName()
            + " object, String name) throws org.sprintapi.hyperdata.gwt.client.AdapterException {");

    if (parameterizedType.getInheritableMethods() != null) {
        int count = 0;
        for (JMethod method : parameterizedType.getInheritableMethods()) {
            if (method.isAnnotationPresent(HyperdataIgnore.class)) {
                continue;
            }/*from ww  w. j a v a  2 s  . c o  m*/
            if (method.isPublic() && method.getName().startsWith("get")) {
                if (count > 0) {
                    sourceWriter.print(" else ");
                }
                sourceWriter
                        .print("name = java.lang.Character.toUpperCase(name.charAt(0)) + name.substring(1);");
                sourceWriter
                        .print("if (\"" + method.getName().substring("get".length()) + "\".equals(name)) {");
                //TODO check the return type
                //TODO isPrimitive
                sourceWriter.print("  return object." + method.getName() + "();");
                sourceWriter.print("}");
                count += 1;
            }
        }
    }
    sourceWriter.print(" return null;");
    //sourceWriter.print("  throw new org.sprintapi.gwt.converter.client.ConverterException(\"There is no getter for '\" + name  + \"'.\");");
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private void composeGetPropertiesMethod(SourceWriter sourceWriter, JClassType parameterizedType) {
    sourceWriter
            .print("public org.sprintapi.hyperdata.gwt.client.bean.BeanPropertyDescriptor[] getProperties() {");
    sourceWriter.print("  return new org.sprintapi.hyperdata.gwt.client.bean.BeanPropertyDescriptor[]{");

    int count = 0;
    if (parameterizedType.getInheritableMethods() != null) {
        for (JMethod method : parameterizedType.getInheritableMethods()) {
            count = doComposeGetPropertiesMethod(sourceWriter, method, count);
        }//from   ww  w  .  j  a va 2  s .  co m
    }

    sourceWriter.print("  };");
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private int doComposeGetPropertiesMethod(SourceWriter sourceWriter, JMethod method, int count) {
    if (method.isAnnotationPresent(HyperdataIgnore.class) || method.getName().equals("getClass")) {
        return count;
    }//from   w ww .j a  va 2 s  .c o  m
    if (method.isPublic() && method.getName().startsWith("get")) {
        if (count > 0) {
            sourceWriter.print(",");
        }
        String methodName = method.getName().substring("get".length());
        if (methodName.trim().isEmpty()) {
            return count;
        }
        methodName = Character.toLowerCase(methodName.charAt(0)) + methodName.substring(1);

        sourceWriter.print("new org.sprintapi.hyperdata.gwt.client.bean.BeanPropertyDescriptorImpl(" + "\""
                + methodName + "\", " + method.getReturnType().getQualifiedSourceName() + ".class" + ", null"); //TODO kind

        MetadataContainer meta = method.getAnnotation(MetadataContainer.class);
        if (meta != null) {

            sourceWriter.print(", new org.sprintapi.hyperdata.gwt.client.bean.HyperBeanPropertyAttributes(");
            sourceWriter.print(")");
        } else {
            sourceWriter.print(", null");
        }

        sourceWriter.print(")");
        count += 1;
    }
    return count;
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private void composeGetBeanClassMethod(SourceWriter sourceWriter, JClassType parameterizedType) {
    sourceWriter.print("public Class<" + parameterizedType.getQualifiedSourceName() + "> getBeanClass() {");
    sourceWriter.print("  return " + parameterizedType.getQualifiedSourceName() + ".class;");
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private void composeGetBeanAttributesMethod(SourceWriter sourceWriter, JClassType parameterizedType) {
    sourceWriter.print("public org.sprintapi.hyperdata.gwt.client.bean.HyperBeanAttributes getAttributes() {");

    HyperdataContainer hyperbean = parameterizedType.getAnnotation(HyperdataContainer.class);
    if (hyperbean != null) {
        sourceWriter.print("  return new org.sprintapi.hyperdata.gwt.client.bean.HyperBeanAttributes(");
        if (hyperbean.profile() != null) {
            sourceWriter.print("new String[]{");
            boolean next = false;
            for (String profile : hyperbean.profile()) {
                if (next) {
                    sourceWriter.print(",");
                }//from w ww  . ja v  a2  s.  co m
                sourceWriter.print("\"" + profile + "\"");
                next = true;
            }
            sourceWriter.print("}");
        }
        sourceWriter.print(");");
    } else {
        sourceWriter.print("  return null;");
    }
    sourceWriter.print("}");
}

From source file:org.sprintapi.hyperdata.gwt.BeanAdapterGenerator.java

License:Apache License

private void composeCreateInstanceMethod(SourceWriter sourceWriter, JClassType parameterizedType) {
    sourceWriter.print("public " + parameterizedType.getQualifiedSourceName() + " createInstance() {");
    sourceWriter.print("  return new " + parameterizedType.getQualifiedSourceName() + "();");
    sourceWriter.print("}");
}

From source file:org.tiwonk.gwt.rest.generator.ClientResourceGenerator.java

License:Apache License

private void addMethod(GeneratorInfo info, SourceWriter writer, JClassType interfaceType, JMethod method)
        throws UnableToCompleteException {

    String returnType = method.getReturnType().getSimpleSourceName();
    String methodName = method.getName();
    writer.print("public " + returnType + " " + methodName + "(");
    analyzeHttpMethod(info, method);//from  w ww .j av a  2s  . c  om
    addParameters(info, writer, method.getParameters());
    writer.println(") {");
    addMethodBody(info, writer, method);
    writer.println("}");

}