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

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

Introduction

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

Prototype

void println(String s);

Source Link

Usage

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeGetterWrapperMethod(final SourceWriter sw, final JMethod method) {
    this.writeUnsafeNativeLongIfNeeded(sw, method.getReturnType());

    // private native fieldType _getter(Bean object) /*={
    sw.print("private native ");/*  ww w  .j a  va2 s. c  o m*/
    sw.print(method.getReturnType().getQualifiedSourceName());
    sw.print(" ");
    sw.print(this.toWrapperName(method));
    sw.print("(");
    sw.print(this.beanType.getName());
    sw.println(" object) /*-{");
    sw.indent();

    // return object.@com.examples.Bean::myMethod()();
    sw.print("return object.");
    sw.print(method.getJsniSignature());
    sw.println("();");

    // }-*/;
    sw.outdent();
    sw.println("}-*/;");
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeIfPropertyNameNotFound(final SourceWriter sw) {
    // if (!ALL_PROPERTY_NAMES.contains(propertyName)) {
    sw.println(" if (!ALL_PROPERTY_NAMES.contains(propertyName)) {");
    sw.indent();/*  ww  w .  jav a2s .  c o m*/

    // throw new IllegalArgumentException(propertyName
    // +"is not a valid property of myClass");
    sw.print("throw new ");
    sw.print(IllegalArgumentException.class.getCanonicalName());
    sw.print("( propertyName +\" is not a valid property of ");
    sw.print(this.beanType.getQualifiedSourceName());
    sw.println("\");");

    // }
    sw.outdent();
    sw.println("}");
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeNewAnnotation(final SourceWriter sw,
        final ConstraintDescriptor<? extends Annotation> constraint) throws UnableToCompleteException {
    final Annotation annotation = constraint.getAnnotation();
    final Class<? extends Annotation> annotationType = annotation.annotationType();

    // new MyAnnotation () {
    sw.print("new ");
    sw.print(annotationType.getCanonicalName());
    sw.println("(){");
    sw.indent();//from   w ww. j av  a2  s .c  o m
    sw.indent();

    // public Class<? extends Annotation> annotationType() { return
    // MyAnnotation.class; }
    sw.print("public Class<? extends Annotation> annotationType() {  return ");
    sw.print(annotationType.getCanonicalName());
    sw.println(".class; }");

    for (final Method method : annotationType.getMethods()) {
        // method.isAbstract would be better
        if (method.getDeclaringClass().equals(annotation.annotationType())) {
            // public returnType method() { return value ;}
            sw.print("public ");
            sw.print(method.getReturnType().getCanonicalName()); // TODO handle
                                                                 // generics
            sw.print(" ");
            sw.print(method.getName());
            sw.print("() { return ");

            try {
                final Object value = method.invoke(annotation);
                sw.print(asLiteral(value));
            } catch (final IllegalArgumentException e) {
                throw error(this.logger, e);
            } catch (final IllegalAccessException e) {
                throw error(this.logger, e);
            } catch (final InvocationTargetException e) {
                throw error(this.logger, e);
            }
            sw.println(";}");
        }
    }

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

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeNewViolations(final SourceWriter sw, final String violationName) {
    // Set<ConstraintViolation<T>> violations =
    sw.print("Set<ConstraintViolation<T>> ");
    sw.print(violationName);/*from  ww  w.  j a  v a2 s. co  m*/
    sw.println(" = ");
    sw.indent();
    sw.indent();

    // new HashSet<ConstraintViolation<T>>();
    sw.println("new HashSet<ConstraintViolation<T>>();");
    sw.outdent();
    sw.outdent();
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writePropertyDescriptor(final SourceWriter sw, final PropertyDescriptor ppropertyDescription) {
    // private final PropertyDescriptor myProperty_pd =
    sw.print("private final ");
    sw.print(PropertyDescriptorImpl.class.getCanonicalName());
    sw.print(" ");
    sw.print(ppropertyDescription.getPropertyName());
    sw.println("_pd =");
    sw.indent();/*from w  ww. j  av a  2 s  .  c  o m*/
    sw.indent();

    // new PropertyDescriptorImpl(
    sw.println("new " + PropertyDescriptorImpl.class.getCanonicalName() + "(");
    sw.indent();
    sw.indent();

    // "myProperty",
    sw.println("\"" + ppropertyDescription.getPropertyName() + "\",");

    // MyType.class,
    sw.println(ppropertyDescription.getElementClass().getCanonicalName() + ".class,");

    // isCascaded,
    sw.print(Boolean.toString(ppropertyDescription.isCascaded()) + ",");

    // beanMetadata,
    sw.print("beanMetadata");

    // myProperty_c0,
    // myProperty_c1 );
    int count = 0;
    for (final ConstraintDescriptor<?> constraint : ppropertyDescription.getConstraintDescriptors()) {
        if (this.areConstraintDescriptorGroupsValid(constraint)) {
            sw.println(","); // Print the , for the previous line
            sw.print(this.constraintDescriptorVar(ppropertyDescription.getPropertyName(), count));
            count++;
        }
    }
    sw.println(");");

    sw.outdent();
    sw.outdent();
    sw.outdent();
    sw.outdent();
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeValidateAllNonInheritedProperties(final SourceWriter sw) {
    // private <T> void validateAllNonInheritedProperties(
    sw.println("private <T> void validateAllNonInheritedProperties(");
    sw.indent();//ww  w .j av a 2  s  .  co  m
    sw.indent();

    // GwtValidationContext<T> context, BeanType object,
    // Set<ConstraintViolation<T>> violations, Class<?>... groups) {
    sw.println("GwtValidationContext<T> context,");
    sw.println(this.beanHelper.getTypeCanonicalName() + " object,");
    sw.println("Set<ConstraintViolation<T>> violations,");
    sw.println("Class<?>... groups) {");
    sw.outdent();

    for (final PropertyDescriptor p : this.beanHelper.getBeanDescriptor().getConstrainedProperties()) {
        this.writeValidatePropertyCall(sw, p, false, true);
    }

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

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeValidateClassGroups(final SourceWriter sw) throws UnableToCompleteException {
    // public <T> void validateClassGroups(
    sw.println("public <T> void validateClassGroups(");

    // GwtValidationContext<T> context, BeanType object,
    // Set<ConstraintViolation<T>> violations, Group... groups) {
    sw.indent();/*from   w w  w  .  ja v  a2 s .  c  om*/
    sw.indent();
    sw.println("GwtValidationContext<T> context,");
    sw.println(this.beanHelper.getTypeCanonicalName() + " object,");
    sw.println("Set<ConstraintViolation<T>> violations,");
    sw.println("Class<?>... groups) {");
    sw.outdent();

    // /// For each group

    // TODO(nchalko) handle the sequence in the AbstractValidator

    // See JSR 303 section 3.5
    // all reachable fields
    // all reachable getters (both) at once
    // including all reachable and cascadable associations

    sw.println("validateAllNonInheritedProperties(context, object, violations, groups);");

    // validate super classes and super interfaces
    this.writeValidateInheritance(sw, this.beanHelper.getClazz(), Stage.OBJECT, null, false, "groups");

    this.writeClassLevelConstraintsValidation(sw, "groups");

    // }
    sw.outdent();
    sw.println("}");
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

/**
 * Writes the call to actually validate a constraint, including its composite constraints.
 * <p>/*ww w . j av  a 2 s. c o m*/
 * If the constraint is annotated as {@link javax.validation.ReportAsSingleViolation
 * ReportAsSingleViolation}, then is called recursively and the {@code violationsVar} is changed
 * to match the {@code constraintDescriptorVar}.
 * </p>
 *
 * @param sw the Source Writer
 * @param ppropertyDescription the property
 * @param elementClass The class of the Element
 * @param constraint the constraint to validate.
 * @param constraintDescriptorVar the name of the constraintDescriptor variable.
 * @param violationsVar the name of the variable to hold violations
 * @throws UnableToCompleteException when validation can not be completed
 */
private void writeValidateConstraint(final SourceWriter sw, final PropertyDescriptor ppropertyDescription,
        final Class<?> elementClass, final ConstraintDescriptor<?> constraint,
        final String constraintDescriptorVar, final String violationsVar) throws UnableToCompleteException {
    final boolean isComposite = !constraint.getComposingConstraints().isEmpty();
    final boolean firstReportAsSingleViolation = constraint.isReportAsSingleViolation()
            && violationsVar.equals(DEFAULT_VIOLATION_VAR) && isComposite;
    final boolean reportAsSingleViolation = firstReportAsSingleViolation
            || !violationsVar.equals(DEFAULT_VIOLATION_VAR);
    final boolean hasValidator = !constraint.getConstraintValidatorClasses().isEmpty();
    final String compositeViolationsVar = constraintDescriptorVar + "_violations";

    // Only do this the first time in a constraint composition.
    if (firstReportAsSingleViolation) {
        // Report myConstraint as Single Violation
        sw.print("// Report ");
        sw.print(constraint.getAnnotation().annotationType().getCanonicalName());
        sw.println(" as Single Violation");
        this.writeNewViolations(sw, compositeViolationsVar);
    }

    if (hasValidator) {
        Class<? extends ConstraintValidator<? extends Annotation, ?>> validatorClass;
        try {
            validatorClass = getValidatorForType(constraint, elementClass);
        } catch (final UnexpectedTypeException e) {
            throw error(this.logger, e);
        }

        if (firstReportAsSingleViolation) {
            // if (!
            sw.println("if (!");
            sw.indent();
            sw.indent();
        }

        // validate(myContext, violations object, value, new MyValidator(),
        // constraintDescriptor, groups));
        sw.print("validate(myContext, ");
        sw.print(violationsVar);
        sw.print(", object, value, ");
        sw.print("new ");
        sw.print(validatorClass.getCanonicalName());
        sw.print("(), ");
        sw.print(constraintDescriptorVar);
        sw.print(", groups)");
        if (firstReportAsSingleViolation) {
            // ) {
            sw.println(") {");
            sw.outdent();

        } else if (reportAsSingleViolation) {
            if (isComposite) {
                // ||
                sw.println(" ||");
            }
        } else {
            // ;
            sw.println(";");
        }
    } else if (!isComposite) {
        // TODO(nchalko) What does the spec say to do here.
        this.logger.log(TreeLogger.WARN, "No ConstraintValidator of " + constraint + " for "
                + ppropertyDescription.getPropertyName() + " of type " + elementClass);
    }

    if (firstReportAsSingleViolation) {
        // if (
        sw.print("if (");
        sw.indent();
        sw.indent();
    }
    int count = 0;

    for (final ConstraintDescriptor<?> compositeConstraint : constraint.getComposingConstraints()) {
        final String compositeVar = constraintDescriptorVar + "_" + count++;
        this.writeValidateConstraint(sw, ppropertyDescription, elementClass, compositeConstraint, compositeVar,
                firstReportAsSingleViolation ? compositeViolationsVar : violationsVar);
        if (reportAsSingleViolation) {
            // ||
            sw.println(" ||");
        } else {
            // ;
            sw.println(";");
        }
    }
    if (isComposite && reportAsSingleViolation) {
        // false
        sw.print("false");
    }
    if (firstReportAsSingleViolation) {
        // ) {
        sw.println(" ) {");
        sw.outdent();

        // addSingleViolation(myContext, violations, object, value,
        // constraintDescriptor);
        sw.print("addSingleViolation(myContext, violations, object, value, ");
        sw.print(constraintDescriptorVar);
        sw.println(");");

        // }
        sw.outdent();
        sw.println("}");

        if (hasValidator) {
            // }
            sw.outdent();
            sw.println("}");
        }
    }
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeValidateFieldCall(final SourceWriter sw, final PropertyDescriptor ppropertyDescription,
        final boolean useValue, final boolean honorValid) {
    final String propertyName = ppropertyDescription.getPropertyName();

    // validateProperty_<<field>>(context,
    sw.print(this.validateMethodFieldName(ppropertyDescription));
    sw.print("(context, ");
    sw.print("violations, ");

    // null, (MyType) value,
    // or//  w  w  w.j  av a  2s  .  c o  m
    // object, object.getLastName(),
    if (useValue) {
        sw.print("null, ");
        sw.print("(");
        sw.print(this.getQualifiedSourceNonPrimitiveType(
                this.beanHelper.getElementType(ppropertyDescription, true)));
        sw.print(") value");
    } else {
        sw.print("object, ");
        final JField field = this.beanType.getField(propertyName);
        if (field.isPublic()) {
            sw.print("object.");
            sw.print(propertyName);
        } else {
            this.fieldsToWrap.add(field);
            sw.print(this.toWrapperName(field) + "(object)");
        }
    }
    sw.print(", ");

    // honorValid, groups);
    sw.print(Boolean.toString(honorValid));
    sw.println(", groups);");
}

From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java

License:Apache License

private void writeValidateGetterCall(final SourceWriter sw, final PropertyDescriptor ppropertyDescription,
        final boolean useValue, final boolean honorValid) {
    // validateProperty_get<<field>>(context, violations,
    sw.print(this.validateMethodGetterName(ppropertyDescription));
    sw.print("(context, ");
    sw.print("violations, ");

    // object, object.getMyProp(),
    // or/*from w  ww .  ja va 2  s .c  o  m*/
    // null, (MyType) value,
    if (useValue) {
        sw.print("null, ");
        sw.print("(");
        sw.print(this.getQualifiedSourceNonPrimitiveType(
                this.beanHelper.getElementType(ppropertyDescription, false)));
        sw.print(") value");
    } else {
        sw.print("object, ");
        final JMethod method = this.beanType.findMethod(asGetter(ppropertyDescription), NO_ARGS);
        if (method.isPublic()) {
            sw.print("object.");
            sw.print(asGetter(ppropertyDescription));
            sw.print("()");
        } else {
            this.gettersToWrap.add(method);
            sw.print(this.toWrapperName(method) + "(object)");
        }
    }
    sw.print(", ");

    // honorValid, groups);
    sw.print(Boolean.toString(honorValid));
    sw.println(", groups);");
}