Ejemplo n.º 1
0
  private void addSerializeSupport(TreeLogger logger, JType type) throws UnableToCompleteException {
    hasSerializeSupport.add(type);

    JParameterizedType parametrized = type.isParameterized();
    if (parametrized != null) {
      for (JClassType parameterType : parametrized.getTypeArgs()) {
        setNeedsSerialize(parameterType);
      }
    }

    if (serializationHandledByFramework(type)) {
      return;
    }

    JClassType customSerializer = customSerializers.get(type);
    JClassType typeAsClass = type.isClass();
    JEnumType enumType = type.isEnum();
    JArrayType arrayType = type.isArray();

    if (customSerializer != null) {
      logger.log(Type.INFO, "Will serialize " + type + " using " + customSerializer.getName());
      setSerializer(type, new CustomSerializer(customSerializer));
    } else if (arrayType != null) {
      logger.log(Type.INFO, "Will serialize " + type + " as an array");
      setSerializer(type, new ArraySerializer(arrayType));
      setNeedsSerialize(arrayType.getComponentType());
    } else if (enumType != null) {
      logger.log(Type.INFO, "Will serialize " + type + " as an enum");
      setSerializer(type, new EnumSerializer(enumType));
    } else if (typeAsClass != null) {
      // Bean
      checkSerializable(logger, typeAsClass);

      logger.log(Type.INFO, "Will serialize " + type + " as a bean");

      JClassType needsSuperClass = typeAsClass;
      while (needsSuperClass != null) {
        if (needsSuperClass.isPublic()) {
          setNeedsSuperclass(needsSuperClass);
        }
        needsSuperClass = needsSuperClass.getSuperclass();
      }

      setNeedsGwtConstructor(typeAsClass);

      for (Property property : getProperties(typeAsClass)) {
        setNeedsProperty(property);

        JType propertyType = property.getPropertyType();
        setNeedsSerialize(propertyType);
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void visitClientRpc(TreeLogger logger, JClassType type, ConnectorBundle bundle)
      throws UnableToCompleteException {
    checkGenericType(logger, type);
    Set<? extends JClassType> hierarchy = type.getFlattenedSupertypeHierarchy();
    for (JClassType subType : hierarchy) {
      JMethod[] methods = subType.getMethods();
      for (JMethod method : methods) {
        checkReturnType(logger, method);

        bundle.setNeedsInvoker(type, method);
        bundle.setNeedsParamTypes(type, method);
        if (method.getAnnotation(NoLayout.class) != null) {
          bundle.setMethodAttribute(type, method, MethodAttribute.NO_LAYOUT);
        }

        JType[] parameterTypes = method.getParameterTypes();
        for (JType paramType : parameterTypes) {
          bundle.setNeedsSerialize(paramType);
        }
      }
    }
  }