Package rocket.generator.rebind.type

Examples of rocket.generator.rebind.type.Type


    final String httpRequestMethod = (String) values.get(0);
    if (null == httpRequestMethod) {
      throwHttpRequestMethodAnnotationException(method);
    }

    Type type = null;
    while (true) {
      if (Tester.isGet(httpRequestMethod)) {
        type = this.getGetJsonRpcServiceInvoker();
        break;
      }
      if (Tester.isPost(httpRequestMethod)) {
        type = this.getPostJsonRpcServiceInvoker();
        break;
      }

      this.throwHttpRequestMethodAnnotationException(method);
    }

    this.getGeneratorContext().debug(
        "After reading annotation the method " + method + " will use the invoker \"" + type.getName() + "\".");
    return type;
  }
View Full Code Here


    this.verifyTypeHasNoArgumentsConstructor(type);

    // check if super type deserializer exists for type...
    final GeneratorContext context = this.getGeneratorContext();
    final Type superType = type.getSuperType();
    final Type objectType = context.getObject();

    // test if type has a superType and potentially create a serializer for
    // that.
    if (false == superType.equals(objectType)) {
      this.createNewTypeIfNecessary(superType.getName());
View Full Code Here

    readFields.setVisibility(Visibility.PROTECTED);

    final NewMethodParameter readFieldsJsonObjectParameter = readFields.newParameter();
    readFieldsJsonObjectParameter.setFinal(true);
    readFieldsJsonObjectParameter.setName("jsonObject");
    final Type jsonObjectType = this.getJsonObject();
    readFieldsJsonObjectParameter.setType(jsonObjectType);

    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);
    }
View Full Code Here

    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();
    context.debug("override " + Constants.READ_COMPLEX_METHOD_NAME + "() for type \"" + type.getName() + "\".");

    final Type jsonSerializer = this.getJsonSerializer();

    final Method readObject = jsonSerializer.getMethod(Constants.READ_COMPLEX_METHOD_NAME, Arrays.asList(new Type[] { this
        .getJsonValue() }));
    final NewMethod newReadObject = readObject.copy(deserializer);
    newReadObject.setAbstract(false);
    newReadObject.setFinal(false);
    newReadObject.setNative(false);
View Full Code Here

    final NewConcreteType newType = context.newConcreteType(newTypeName);
    newType.setAbstract(false);
    newType.setFinal(false);

    // extend either JsonSerializerType or the generated type of type...
    Type superType = type.getSuperType();
    String superTypeName = Constants.JSON_SERIALIZER_TYPE;
    if (false == superType.equals(context.getObject())) {
      superTypeName = this.getGeneratedTypeName(superType.getName());
    }
    superType = context.getType(superTypeName);
    newType.setSuperType(superType);
    newType.setVisibility(Visibility.PUBLIC);
View Full Code Here

    instanceParameter.setType(context.getObject());

    final NewMethodParameter jsonObjectParameter = writeFields.newParameter();
    jsonObjectParameter.setFinal(true);
    jsonObjectParameter.setName(Constants.WRITE_FIELD_JSON_OBJECT_PARAMETER);
    final Type jsonObjectType = this.getJsonObject();
    jsonObjectParameter.setType(jsonObjectType);

    final WriteFieldsTemplatedFile body = new WriteFieldsTemplatedFile();
    body.setInstanceType(type);
    writeFields.setBody(body);

    // find all fields belonging to type
    final Iterator fields = type.getFields().iterator();
    while (fields.hasNext()) {
      final Field field = (Field) fields.next();
      if (field.isStatic() || field.isTransient()) {
        continue;
      }

      final NewMethod fieldGetter = this.createFieldGetter(deserializer, field);
      final String javascriptPropertyName = this.getJavascriptPropertyName(field);
      final Type serializer = this.getSerializer(field);

      body.addField(javascriptPropertyName, fieldGetter, serializer);
    } // while

    context.unbranch();
View Full Code Here

    getter.setAbstract(false);
    getter.setFinal(false);
    getter.setName(Constants.GET_FIELD_METHOD_PREFIX + this.capitalize(field.getName()));
    getter.setNative(true);

    final Type fieldType = field.getType();
    getter.setReturnType(fieldType);

    getter.setStatic(false);
    getter.setVisibility(Visibility.PRIVATE);

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

    final NewMethodParameter instance = getter.newParameter();
    instance.setName(Constants.GET_FIELD_INSTANCE_PARAMETER);
View Full Code Here

    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();
    context.debug("Override " + Constants.WRITE_JSON_METHOD_NAME + "() for type \"" + type.getName() + "\".");

    final Type jsonSerializer = this.getJsonSerializer();

    final Method writeJson = jsonSerializer.getMethod(Constants.WRITE_JSON_METHOD_NAME, Collections.nCopies(1, context.getObject()));
    final NewMethod newWriteJson = writeJson.copy(deserializer);
    newWriteJson.setAbstract(false);
    newWriteJson.setFinal(false);
    newWriteJson.setNative(false);
View Full Code Here

  protected String capitalize(final String propertyName) {
    return Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
  }

  protected Type getSerializer(final Field field) {
    Type serializerType = null;

    while (true) {
      final Type fieldType = field.getType();
      if (fieldType.equals(this.getList())) {
        serializerType = this.getTypeFromAnnotation(field);
        break;
      }
      if (fieldType.equals(this.getSet())) {
        serializerType = this.getTypeFromAnnotation(field);
        break;
      }
      if (fieldType.equals(this.getMap())) {
        serializerType = this.getTypeFromAnnotation(field);
        break;
      }
      serializerType = fieldType;
      break;
View Full Code Here

    }
    return this.getSerializer0(serializerType);
  }

  protected Type getSerializer0(final Type type) {
    Type serializer = null;

    while (true) {
      final GeneratorContext context = this.getGeneratorContext();
      {
        final Type booleanType = context.getBoolean();
        if (type.equals(booleanType) || type.equals(booleanType.getWrapper())) {
          serializer = context.getType(Constants.BOOLEAN_SERIALIZER);
          break;
        }
      }
      {
        final Type byteType = context.getByte();
        if (type.equals(byteType) || type.equals(byteType.getWrapper())) {
          serializer = context.getType(Constants.BYTE_SERIALIZER);
          break;
        }
      }

      {
        final Type shortType = context.getShort();
        if (type.equals(shortType) || type.equals(shortType.getWrapper())) {
          serializer = context.getType(Constants.SHORT_SERIALIZER);
          break;
        }
      }

      {
        final Type intType = context.getInt();
        if (type.equals(intType) || type.equals(intType.getWrapper())) {
          serializer = context.getType(Constants.INT_SERIALIZER);
          break;
        }
      }

      {
        final Type longType = context.getLong();
        if (type.equals(longType) || type.equals(longType.getWrapper())) {
          serializer = context.getType(Constants.LONG_SERIALIZER);
          break;
        }
      }

      {
        final Type floatType = context.getFloat();
        if (type.equals(floatType) || type.equals(floatType.getWrapper())) {
          serializer = context.getType(Constants.FLOAT_SERIALIZER);
          break;
        }
      }

      {
        final Type doubleType = context.getDouble();
        if (type.equals(doubleType) || type.equals(doubleType.getWrapper())) {
          serializer = context.getType(Constants.DOUBLE_SERIALIZER);
          break;
        }
      }

      {
        final Type charType = context.getChar();
        if (type.equals(charType) || type.equals(charType.getWrapper())) {
          serializer = context.getType(Constants.CHAR_SERIALIZER);
          break;
        }
      }
      if (type.equals(context.getString())) {
View Full Code Here

TOP

Related Classes of rocket.generator.rebind.type.Type

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.