Package rocket.generator.rebind.codeblock

Examples of rocket.generator.rebind.codeblock.CodeBlockList


    final NewMethodParameter readFieldsInstanceParameter = readFields.newParameter();
    readFieldsInstanceParameter.setFinal(true);
    readFieldsInstanceParameter.setName("instance");
    readFieldsInstanceParameter.setType(type);

    final CodeBlockList body = new CodeBlockList();
    readFields.setBody(body);

    final Type stringType = context.getString();

    final Iterator fields = type.getFields().iterator();
    while (fields.hasNext()) {
      final Field field = (Field) fields.next();
      if (field.isStatic() || field.isTransient()) {
        continue;
      }
      if (field.isFinal()) {
        throwFinalFieldsCannotBeDeserialized(field);
      }

      final SetFieldTemplatedFile writeMethodBody = new SetFieldTemplatedFile();
      writeMethodBody.setField(field);

      // create the setter method itself.
      final NewMethod setter = deserializer.newMethod();
      setter.setAbstract(false);
      setter.setFinal(false);
      setter.setName(GeneratorHelper.buildSetterName(field.getName()));
      setter.setNative(true);
      setter.setReturnType(context.getVoid());
      setter.setStatic(false);
      setter.setVisibility(Visibility.PRIVATE);
      setter.setBody(writeMethodBody);

      // add its instance parameter
      final NewMethodParameter setterInstanceParameter = setter.newParameter();
      setterInstanceParameter.setFinal(true);
      setterInstanceParameter.setName(Constants.SET_FIELD_INSTANCE_PARAMETER);
      setterInstanceParameter.setType(type);

      // add the value parameter
      final NewMethodParameter setterValueParameter = setter.newParameter();
      setterValueParameter.setFinal(true);
      setterValueParameter.setName(Constants.SET_FIELD_VALUE_PARAMETER);
      setterValueParameter.setType(field.getType());

      final Type fieldType = field.getType();

      if (fieldType.equals(context.getLong())) {
        setter.addMetaData("com.google.gwt.core.client.UnsafeNativeLong", "");
      }

      context.debug("Created setter for field " + field + " setter method " + setter);

      // simple type ?
      if (fieldType.isPrimitive() || fieldType.equals(stringType)) {
        final SetSimpleTemplatedFile template = new SetSimpleTemplatedFile();

        template.setFieldSetter(setter);
        template.setJavascriptPropertyName(this.getJavascriptPropertyName(field));
        template.setSerializer(this.getSerializer(field));

        body.add(template);
        continue;
      }

      final SetComplexTemplatedFile template = new SetComplexTemplatedFile();
      template.setFieldSetter(setter);
      template.setJavascriptPropertyName(this.getJavascriptPropertyName(field));
      template.setFieldType(fieldType);

      final Type serializer = this.getSerializer(field);
      template.setSerializer(serializer);

      final String readMethodName = this.selectReadMethod(fieldType);
      final Method readMethod = serializer.getMostDerivedMethod(readMethodName, Collections.nCopies(1, this.getJsonValue()));
      template.setReadMethod(readMethod);

      body.add(template);
    }

    context.unbranch();
  }
View Full Code Here

TOP

Related Classes of rocket.generator.rebind.codeblock.CodeBlockList

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.