Package rocket.generator.rebind

Examples of rocket.generator.rebind.GeneratorContext


      throwIncludedFileCycle(fileName);
    }
    includedFiles.add(fileName);

    final Generator generator = this.getGenerator();
    final GeneratorContext context = generator.getGeneratorContext();
    context.debug(fileName);

    final InputStream inputStream = generator.getResource(fileName);
    final Document document = this.getDocumentBuilder().parse(inputStream);
    this.setDocument(document);
View Full Code Here


  }

  protected NullLiteral visitNullValue(final Element element) {
    final NullLiteral nullValue = new NullLiteral();

    final GeneratorContext context = this.getGenerator().getGeneratorContext();
    nullValue.setGeneratorContext(context);
    nullValue.setType(context.getString());

    return nullValue;
  }
View Full Code Here

  protected StringValue visitValue(final Element element) {
    final StringValue stringValue = new StringValue();
    final String text = this.getPlaceHolderResolver().resolve(element.getTextContent());

    final GeneratorContext context = this.getGenerator().getGeneratorContext();
    stringValue.setFilename(this.getFilename());
    stringValue.setGeneratorContext(context);
    stringValue.setType(context.getString());
    stringValue.setValue(text);

    return stringValue;
  }
View Full Code Here

  protected String getResourceName() {
    String fileName = null;
    while (true) {
      // the return type of the getter is also the field type.
      final Type type = this.getGetter().getReturnType();
      final GeneratorContext context = type.getGeneratorContext();
      if (context.getBoolean().equals(type)) {
        fileName = Constants.WRITE_FIELD_BOOLEAN_FIELD_TEMPLATE;
        break;
      }
      if (context.getByte().equals(type)) {
        fileName = Constants.WRITE_FIELD_BYTE_FIELD_TEMPLATE;
        break;
      }
      if (context.getShort().equals(type)) {
        fileName = Constants.WRITE_FIELD_SHORT_FIELD_TEMPLATE;
        break;
      }
      if (context.getInt().equals(type)) {
        fileName = Constants.WRITE_FIELD_INT_FIELD_TEMPLATE;
        break;
      }
      if (context.getLong().equals(type)) {
        fileName = Constants.WRITE_FIELD_LONG_FIELD_TEMPLATE;
        break;
      }
      if (context.getFloat().equals(type)) {
        fileName = Constants.WRITE_FIELD_FLOAT_FIELD_TEMPLATE;
        break;
      }
      if (context.getDouble().equals(type)) {
        fileName = Constants.WRITE_FIELD_DOUBLE_FIELD_TEMPLATE;
        break;
      }
      if (context.getChar().equals(type)) {
        fileName = Constants.WRITE_FIELD_CHAR_FIELD_TEMPLATE;
        break;
      }
      fileName = Constants.WRITE_FIELD_OBJECT_FIELD_TEMPLATE;
      break;
View Full Code Here

   * @param newTypeName
   *            Its new name
   * @return The new concrete type
   */
  protected NewConcreteType subClassLoggingFactory(final String newTypeName) {
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Creating type that sub classes LoggingFactoryImpl");

    final NewConcreteType newType = context.newConcreteType(newTypeName);
    newType.setAbstract(false);
    newType.setFinal(true);
    newType.setSuperType(this.getLoggerFactoryImpl());
    newType.setVisibility(Visibility.PUBLIC);

    context.unbranch();

    return newType;
  }
View Full Code Here

   *            The type being assembled.
   */
  protected void overrideLoggingFactoryImplFindLogger(final NewConcreteType loggerFactory) {
    Checker.notNull("parameter:loggerFactory", loggerFactory);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Overriding " + Constants.FIND_LOGGER_METHOD);

    final List<Type> findLoggerMethodArguments = Collections.nCopies(1, context.getString());
    final Method method = loggerFactory.findMostDerivedMethod(Constants.FIND_LOGGER_METHOD, findLoggerMethodArguments);

    final NewMethod newMethod = method.copy(loggerFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final FindLoggerTemplatedFile template = new FindLoggerTemplatedFile();
    newMethod.setBody(template);

    final LoggingFactoryConfig config = this.getLoggingFactoryConfig();
    context.debug("Config: " + config);

    final Iterator<String> names = config.getNames();
    while (names.hasNext()) {
      final String name = names.next();
      final String loggerTypeName = config.getTypeName(name);
      final LoggingLevel loggingLevel = config.getLoggingLevel(name);

      context.debug(name + "=" + loggerTypeName + " (" + loggingLevel + ")");

      final Constructor loggingLevelLogger = this.getConstructorForLoggingLevel(loggingLevel);
      final Constructor logger = this.getTargetLoggerConstructor(loggerTypeName);

      template.register(name, loggingLevelLogger, logger);
    }

    // rename parameter to a known name which matches the variable named
    // used in templates.
    final NewMethodParameter parameter = (NewMethodParameter) newMethod.getParameters().get(0);
    parameter.setName(Constants.FIND_LOGGER_NAME_PARAMETER);
    parameter.setFinal(true);

    context.unbranch();
  }
View Full Code Here

   *            The type being assembled.
   */
  protected void overrideLoggingFactoryImplCreateDefaultLogger(final NewConcreteType loggerFactory) {
    Checker.notNull("parameter:loggerFactory", loggerFactory);

    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.info("Overriding " + Constants.CREATE_ROOT_LOGGER_METHOD);

    final List createDefaultLoggerMethodArguments = Collections.nCopies(1, context.getString());
    final Method method = loggerFactory.findMostDerivedMethod(Constants.CREATE_ROOT_LOGGER_METHOD,
        createDefaultLoggerMethodArguments);

    final NewMethod newMethod = method.copy(loggerFactory);
    newMethod.setAbstract(false);
    newMethod.setFinal(true);
    newMethod.setNative(false);

    final String category = LoggingConstants.ROOT_LOGGER_NAME;
    final LoggingFactoryConfig config = this.getLoggingFactoryConfig();

    final CreateRootLoggerTemplatedFile createLogger = new CreateRootLoggerTemplatedFile();
    newMethod.setBody(createLogger);

    final LoggingLevel loggingLevel = config.getLoggingLevel(category);
    createLogger.setLevelLogger(this.getConstructorForLoggingLevel(loggingLevel));

    final String typeName = config.getTypeName(category);
    createLogger.setLogger(this.getTargetLoggerConstructor(typeName));

    context.debug("Type: " + typeName);

    // rename parameter to a known name.
    final NewMethodParameter parameter = (NewMethodParameter) newMethod.getParameters().get(0);
    parameter.setName(Constants.CREATE_ROOT_NAME_PARAMETER);
    parameter.setFinal(true);

    context.unbranch();
  }
View Full Code Here

   * @param typeName
   *            The name of the target logger.
   * @return A Constructor that takes a String parameter.
   */
  protected Constructor getTargetLoggerConstructor(final String typeName) {
    final GeneratorContext context = this.getGeneratorContext();
    context.branch();
    context.debug(typeName);

    final Type type = context.getType(typeName);
    context.debug(type.toString());

    // make sure type is really a Logger.
    final Type logger = this.getLogger();
    if (false == type.isAssignableTo(logger)) {
      throwTargetLoggerIsNotALogger(type);
    }
    if (type.isInterface()) {
      throwTargetLoggerIsAnInterface(type);
    }
    if (type.isAbstract()) {
      throwTargetLoggerIsAbstract(type);
    }

    // find a constructor with a string parameter.
    final List stringParameter = Collections.nCopies(1, context.getString());
    final Constructor constructor = type.getConstructor(stringParameter);
    if (constructor.getVisibility() != Visibility.PUBLIC) {
      throwTargetLoggerConstructorIsNotPublic(constructor);
    }

    context.debug("Found " + constructor);
    context.unbranch();

    return constructor;
  }
View Full Code Here

    NewConcreteType deserializer = null;

    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

   */
  protected void overrideReadFieldsMethods(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.READ_FIELDS_METHOD + "() and creating list setters for type \"" + deserializer.getName()
        + "\".");

    final NewMethod readFields = deserializer.newMethod();
    readFields.setAbstract(false);
    readFields.setFinal(false);
    readFields.setName(Constants.READ_FIELDS_METHOD);
    readFields.setNative(false);
    readFields.setReturnType(context.getVoid());
    readFields.setStatic(false);
    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);
    }

    context.unbranch();
  }
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.