Package com.google.gwt.autobean.rebind.model

Examples of com.google.gwt.autobean.rebind.model.AutoBeanMethod


    for (AutoBeanMethod method : type.getMethods()) {
      if (!method.getAction().equals(Action.GET)) {
        continue;
      }

      AutoBeanMethod setter = null;
      // If it's not a simple bean type, try to find a real setter method
      if (!type.isSimpleBean()) {
        for (AutoBeanMethod maybeSetter : type.getMethods()) {
          if (maybeSetter.getAction().equals(Action.SET)
              && maybeSetter.getPropertyName().equals(method.getPropertyName())) {
            setter = maybeSetter;
            break;
          }
        }
      }

      // The type of property influences the visitation
      String valueExpression = String.format(
          "%1$s value = (%1$s) %2$s.getAutoBean(as().%3$s());",
          AbstractAutoBean.class.getCanonicalName(),
          AutoBeanUtils.class.getCanonicalName(), method.getMethod().getName());
      String visitMethod;
      Class<?> propertyContextType;
      if (method.isCollection()) {
        propertyContextType = CollectionPropertyContext.class;
        visitMethod = "Collection";
      } else if (method.isMap()) {
        propertyContextType = MapPropertyContext.class;
        visitMethod = "Map";
      } else if (method.isValueType()) {
        propertyContextType = PropertyContext.class;
        valueExpression = String.format("Object value = as().%s();",
            method.getMethod().getName());
        visitMethod = "Value";
      } else {
        visitMethod = "Reference";
        propertyContextType = PropertyContext.class;
      }

      /*
       * Make the PropertyContext that lets us call the setter. We allow
       * multiple methods to be bound to the same property (e.g. to allow JSON
       * payloads to be interpreted as different types). The leading underscore
       * allows purely numeric property names, which are valid JSON map keys.
       */
      String propertyContextName = names.createName("_"
          + method.getPropertyName() + "PropertyContext");
      sw.println("class %s implements %s {", propertyContextName,
          propertyContextType.getCanonicalName());
      sw.indent();
      sw.println("public boolean canSet() { return %s; }", type.isSimpleBean()
          || setter != null);
      if (method.isCollection()) {
        // Will return the collection's element type or null if not a collection
        sw.println(
            "public Class<?> getElementType() { return %s.class; }",
            ModelUtils.ensureBaseType(method.getElementType()).getQualifiedSourceName());
      } else if (method.isMap()) {
        // Will return the map's value type
        sw.println(
            "public Class<?> getValueType() { return %s.class; }",
            ModelUtils.ensureBaseType(method.getValueType()).getQualifiedSourceName());
        // Will return the map's key type
        sw.println(
            "public Class<?> getKeyType() { return %s.class; }",
            ModelUtils.ensureBaseType(method.getKeyType()).getQualifiedSourceName());
      }
      // Return the property type
      sw.println(
          "public Class<?> getType() { return %s.class; }",
          ModelUtils.ensureBaseType(method.getMethod().getReturnType()).getQualifiedSourceName());
      sw.println("public void set(Object obj) { ");
      if (setter != null) {
        // Prefer the setter if one exists
        // as().setFoo((Foo) obj);
        sw.indentln(
            "as().%s((%s) obj);",
            setter.getMethod().getName(),
            ModelUtils.ensureBaseType(
                setter.getMethod().getParameters()[0].getType()).getQualifiedSourceName());
      } else if (type.isSimpleBean()) {
        // Otherwise, fall back to a map assignment
        sw.indentln("values.put(\"%s\", obj);", method.getPropertyName());
      } else {
        sw.indentln("throw new UnsupportedOperationException(\"No setter\");");
View Full Code Here


    for (AutoBeanMethod method : type.getMethods()) {
      if (!method.getAction().equals(JBeanMethod.GET)) {
        continue;
      }

      AutoBeanMethod setter = null;
      // If it's not a simple bean type, try to find a real setter method
      if (!type.isSimpleBean()) {
        for (AutoBeanMethod maybeSetter : type.getMethods()) {
          boolean isASetter = maybeSetter.getAction().equals(JBeanMethod.SET)
              || maybeSetter.getAction().equals(JBeanMethod.SET_BUILDER);
          if (isASetter
              && maybeSetter.getPropertyName().equals(method.getPropertyName())) {
            setter = maybeSetter;
            break;
          }
        }
      }

      // The type of property influences the visitation
      String valueExpression = String.format(
          "bean = (%1$s) %2$s.getAutoBean(as.%3$s());",
          AbstractAutoBean.class.getCanonicalName(),
          AutoBeanUtils.class.getCanonicalName(), method.getMethod().getName());
      String visitMethod;
      String visitVariable = "bean";
      if (method.isCollection()) {
        visitMethod = "Collection";
      } else if (method.isMap()) {
        visitMethod = "Map";
      } else if (method.isValueType()) {
        valueExpression = String.format("value = as.%s();",
            method.getMethod().getName());
        visitMethod = "Value";
        visitVariable = "value";
      } else {
        visitMethod = "Reference";
      }
      sw.println(valueExpression);

      // Map<List<Foo>, Bar> --> Map, List, Foo, Bar
      List<JType> typeList = new ArrayList<JType>();
      createTypeList(typeList, method.getMethod().getReturnType());
      assert typeList.size() > 0;

      /*
       * Make the PropertyContext that lets us call the setter. We allow
       * multiple methods to be bound to the same property (e.g. to allow JSON
       * payloads to be interpreted as different types). The leading underscore
       * allows purely numeric property names, which are valid JSON map keys.
       */
      // propertyContext = new CPContext(.....);
      sw.println("propertyContext = new %s(",
          ClientPropertyContext.class.getCanonicalName());
      sw.indent();
      // The instance on which the context is nominally operating
      sw.println("as,");
      // Produce a JSNI reference to a setter function to call
      {
        if (setter != null) {
          // Call a method that returns a JSNI reference to the method to call
          // setFooMethodReference(),
          sw.println("%sMethodReference(as),", setter.getMethod().getName());
          referencedSetters.add(setter);
        } else {
          // Create a function that will update the values map
          // CPContext.mapSetter(values, "foo");
          sw.println("%s.mapSetter(values, \"%s\"),",
View Full Code Here

TOP

Related Classes of com.google.gwt.autobean.rebind.model.AutoBeanMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.