Package rocket.beans.rebind.constructor

Examples of rocket.beans.rebind.constructor.ConstructorTemplatedFile


    final NewMethod newFactoryMethod = this.createCreateInstanceMethod(bean.getFactoryBean());
    newFactoryMethod.setAbstract(false);
    newFactoryMethod.setFinal(true);
    newFactoryMethod.setNative(false);

    final ConstructorTemplatedFile body = new ConstructorTemplatedFile();
    newFactoryMethod.setBody(body);

    final GeneratorContext context = this.getGeneratorContext();
    context.delayedBranch();
    context.debug("Constructor parameter values.");

    final List<Value> arguments = bean.getConstructorValues();
    final Iterator<Value> argumentsIterator = arguments.iterator();
    while (argumentsIterator.hasNext()) {
      final Value value = argumentsIterator.next();
      body.addArgument(value);

      if (context.isDebugEnabled()) {
        context.debug(value.toString());
      }
    }

    context.unbranch();

    context.branch();
    context.debug("Matching constructors.");

    final List<Constructor> matchingConstructors = new ArrayList<Constructor>();
    final TypeConstructorsVisitor visitor = new TypeConstructorsVisitor() {

      protected boolean visit(final Constructor constructor) {
        boolean match = false;

        // skip non public constructors
        if (constructor.getVisibility() == Visibility.PUBLIC) {
          final List<ConstructorParameter> constructorParameters = constructor.getParameters();

          // skip the given constructor with different numbers of
          // parameters.
          if (constructorParameters.size() == arguments.size()) {

            match = true;
            final Iterator<Value> valuesIterator = arguments.iterator();
            final Iterator<ConstructorParameter> parametersIterator = constructorParameters.iterator();

            while (valuesIterator.hasNext()) {
              final ConstructorParameter parameter = parametersIterator.next();
              final Value value0 = valuesIterator.next();
              if (false == value0.isCompatibleWith(parameter.getType())) {
                match = false;
              }
            }
          }
        }

        if (match) {
          matchingConstructors.add(constructor);
          context.debug("" + constructor);
        }
        return false;
      }
    };

    final Type beanType = bean.getType();
    visitor.start(beanType);

    if (matchingConstructors.size() == 0) {
      this.throwUnableToFindConstructor(bean);
    }
    if (matchingConstructors.size() > 1) {
      this.throwTooManyConstructors(bean, matchingConstructors);
    }
    context.unbranch();

    final Constructor constructor = (Constructor) matchingConstructors.get(0);
    body.setBean(constructor);

    final Iterator<ConstructorParameter> constructorParameters = constructor.getParameters().iterator();
    final Iterator<Value> valuesIterator = arguments.iterator();
    while (constructorParameters.hasNext()) {
      final ConstructorParameter constructorParameter = constructorParameters.next();
View Full Code Here

TOP

Related Classes of rocket.beans.rebind.constructor.ConstructorTemplatedFile

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.