Package rocket.generator.rebind

Examples of rocket.generator.rebind.GeneratorContext


   */
  protected void overrideReadObjectMethod(final NewConcreteType deserializer, final Type type) {
    Checker.notNull("parameter:deserializer", deserializer);
    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() }));
View Full Code Here


   * @return
   */
  protected NewConcreteType createConcreteType(final String newTypeName, final Type type) {
    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();
    context.debug("Creating new type \"" + type.getName() + "\".");

    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);

    return newType;
  }
View Full Code Here

   */
  protected void overrideWriteFieldsMethods(final NewConcreteType deserializer, final Type type) {
    Checker.notNull("parameter:deserializer", deserializer);
    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.debug("Overriding " + Constants.WRITE_FIELDS_WRITE_METHODS + "() and creating list getters for type \""
        + deserializer.getName() + "\".");

    final NewMethod writeFields = deserializer.newMethod();
    writeFields.setAbstract(false);
    writeFields.setFinal(false);
    writeFields.setName(Constants.WRITE_FIELDS_WRITE_METHODS);
    writeFields.setNative(false);
    writeFields.setReturnType(context.getVoid());
    writeFields.setStatic(false);
    writeFields.setVisibility(Visibility.PROTECTED);

    final NewMethodParameter instanceParameter = writeFields.newParameter();
    instanceParameter.setFinal(true);
    instanceParameter.setName(Constants.WRITE_FIELDS_INSTANCE_PARAMETER);
    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

   */
  protected NewMethod createFieldGetter(final NewConcreteType deserializer, final Field field) {
    Checker.notNull("parameter:deserializer", deserializer);
    Checker.notNull("parameter:list", field);

    final GeneratorContext context = this.getGeneratorContext();

    final NewMethod getter = deserializer.newMethod();
    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);
    instance.setFinal(true);
    instance.setType(field.getEnclosingType());

    final GetFieldTemplatedFile getterBody = new GetFieldTemplatedFile();
    getterBody.setField(field);
    getter.setBody(getterBody);

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

    return getter;
  }
View Full Code Here

   */
  protected void overrideWriteJsonMethod(final NewConcreteType deserializer, final Type type) {
    Checker.notNull("parameter:deserializer", deserializer);
    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 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())) {
        serializer = context.getType(Constants.STRING_SERIALIZER);
        break;
      }

      final String serializerTypeName = this.createNewTypeIfNecessary(type.getName());
      serializer = context.getType(serializerTypeName);
      break;
    }
    return serializer;
  }
View Full Code Here

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

    boolean compatible = false;

    while (true) {
      final GeneratorContext context = this.getGeneratorContext();
      if (type == context.getString()) {
        compatible = isCompatibleWithString();
        break;
      }

      if (type == context.getBoolean()) {
        compatible = isCompatibleWithBoolean();
        break;
      }
      if (type == context.getByte()) {
        compatible = isCompatibleWithByte();
        break;
      }
      if (type == context.getShort()) {
        compatible = isCompatibleWithShort();
        break;
      }
      if (type == context.getInt()) {
        compatible = isCompatibleWithInt();
        break;
      }
      if (type == context.getLong()) {
        compatible = isCompatibleWithLong();
        break;
      }
      if (type == context.getFloat()) {
        compatible = isCompatibleWithFloat();
        break;
      }
      if (type == context.getDouble()) {
        compatible = isCompatibleWithDouble();
        break;
      }
      if (type == context.getChar()) {
        compatible = isCompatibleWithChar();
        break;
      }
      break;
    }
View Full Code Here

    CodeBlock literal = null;

    while (true) {
      final Type type = this.getPropertyType();
      final GeneratorContext context = this.getGeneratorContext();
      if (type == context.getBoolean()) {
        literal = new BooleanLiteral(this.getBooleanValue());
        break;
      }
      if (type == context.getByte()) {
        literal = new ByteLiteral(this.getByteValue());
        break;
      }
      if (type == context.getShort()) {
        literal = new ShortLiteral(this.getShortValue());
        break;
      }
      if (type == context.getInt()) {
        literal = new IntLiteral(this.getIntValue());
        break;
      }
      if (type == context.getLong()) {
        literal = new LongLiteral(this.getLongValue());
        break;
      }
      if (type == context.getFloat()) {
        literal = new FloatLiteral(this.getFloatValue());
        break;
      }
      if (type == context.getDouble()) {
        literal = new DoubleLiteral(this.getDoubleValue());
        break;
      }
      if (type == context.getChar()) {
        literal = new CharLiteral(this.getCharValue());
        break;
      }

      // will default to String for List/Set/Map which wont have set the
View Full Code Here

    // if bean type is a factoryBean read get the bean's actual delivered
    // type from the annotation.
    final Type type = this.getType();
    Type valueType = type;

    final GeneratorContext context = type.getGeneratorContext();
    final Type factoryBean = context.getType(Constants.FACTORY_BEAN);

    if (type.isAssignableTo(factoryBean)) {
      // locate the annotation and get the type from there...
      final List<String> factoryBeanObjectTypes = type.getMetadataValues(Constants.FACTORY_BEAN_OBJECT_TYPE);
      if (null == factoryBeanObjectTypes || factoryBeanObjectTypes.size() != 1) {
        throwFactoryBeanObjectTypeAnnotationMissing();
      }
      final String factoryBeanObjectTypeName = factoryBeanObjectTypes.get(0);
      valueType = context.getType(factoryBeanObjectTypeName);
    }

    return valueType;
  }
View Full Code Here

   * @return
   */
  protected Set<Method> findMethods(final Type type) {
    Checker.notNull("parameter:type", type);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Finding abstract methods which need be implemented");

    final Set<Method> methods = new TreeSet<Method>(MethodComparator.INSTANCE); // sort
    // methods
    // in
    // alphabetical
    // order

    final VirtualMethodVisitor visitor = new VirtualMethodVisitor() {
      protected boolean visit(final Method method) {
        context.debug(method.getName());
        ImageFactoryGenerator.this.checkMethod(method);
        methods.add(method);
        return false; // continue visiting other methods.
      }

      protected boolean skipJavaLangObjectMethods() {
        return true;
      }
    };
    visitor.start(type);

    context.unbranch();
    return methods;
  }
View Full Code Here

TOP

Related Classes of rocket.generator.rebind.GeneratorContext

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.