Esempio n. 1
0
  private String generateByCustomGenerators(
      TreeLogger logger,
      GeneratorContext context,
      String typeName,
      String superClass,
      String actualTypeName,
      List<AbstractGenerator> awaitingGeneratos)
      throws UnableToCompleteException {

    //		AbstractGenerator processedGenerator = null;

    for (AbstractGenerator generator : awaitingGeneratos) {
      if (superClass != null && !("".equals(superClass))) {
        generator.setSuperclassName(superClass);
      } else {
        generator.setSuperclassName(actualTypeName);
      }

      if (generator.isGenerate(logger, context, actualTypeName, generator.getConditions())) {
        superClass = generator.doGenerate(logger, context, actualTypeName);
        //				processedGenerator = generator;
        //				break;
      }
    }

    //		if (processedGenerator != null) {
    //			awaitingGeneratos.remove(processedGenerator);
    //			superClass = generateByCustomGenerators(logger, context, typeName, superClass,
    // actualTypeName, awaitingGeneratos);
    //		}

    return superClass;
  }
Esempio n. 2
0
  /**
   * gets generator chain for typeName, calls every generator from chain with superclass name set to
   * previously generated class
   *
   * @param logger
   * @param context
   * @param typeName
   * @return name of generated class
   * @throws UnableToCompleteException
   */
  public String generate(TreeLogger logger, GeneratorContext context, String typeName)
      throws UnableToCompleteException {
    if (GeneratorChain.customGenerators == null || GeneratorChain.context != context) {
      fillUpGeneratorChainMap(logger, context);
      GeneratorChain.context = context;

      //			new RemoteServiceGinInjectorGenerator().generate(logger, context,
      // RemoteServicePath.class.getCanonicalName());
    }

    //		if (!BeansBindingInit.isInitialized()) {
    //			BeansBindingInit.setInitialized(true);
    //			BeansBindingInitGenerator beansBindingInitGenerator = new BeansBindingInitGenerator();
    //			beansBindingInitGenerator.generate(logger, context,
    // BeansBindingInit.class.getCanonicalName());
    //			//GWT.create(BeansBindingInit.class);
    //		}

    // can be changed by generator
    String superClass = "";
    // can be changed by replacer
    String actualTypeName = typeName;

    // Replace-with rules
    List<AbstractGenerator> replacers = GeneratorChain.getReplaceByChain(context, typeName);
    for (AbstractGenerator replacer : replacers) {
      if (replacer.isGenerate(logger, context, typeName, replacer.getConditions())) {
        actualTypeName = replacer.doGenerate(logger, context, actualTypeName);
      }
    }

    // generators from third party - can get only one (last) generator
    LinkedHashMap<Generator, AbstractGenerator> thirdPartyGens =
        GeneratorChain.getThirdPartyGenerators();
    for (Entry<Generator, AbstractGenerator> entry : thirdPartyGens.entrySet()) {
      Generator gen = (Generator) entry.getKey();
      AbstractGenerator aGen = (AbstractGenerator) entry.getValue();
      if (superClass != null && !("".equals(superClass))) {
        aGen.setSuperclassName(superClass);
      } else {
        aGen.setSuperclassName(actualTypeName);
      }
      if (aGen.isGenerate(logger, context, actualTypeName, aGen.getConditions())) {
        superClass = gen.generate(logger, context, actualTypeName);
      }
    }

    // custom generators
    List<AbstractGenerator> generators = GeneratorChain.getGeneratorChain(context, typeName);

    //		List<AbstractGenerator> awaitingGeneratos = new ArrayList<AbstractGenerator>();
    //		for (AbstractGenerator abstractGenerator : generators) {
    //			awaitingGeneratos.add(abstractGenerator);
    //		}
    //
    superClass =
        generateByCustomGenerators(
            logger, context, typeName, superClass, actualTypeName, generators);

    if (superClass.length() == 0) {
      return actualTypeName;
    }

    return superClass;
  }