示例#1
0
  private void emitMenu(SourceWriter writer, Element el) throws UnableToCompleteException {
    for (Node n = el.getFirstChild(); n != null; n = n.getNextSibling()) {
      if (n.getNodeType() != Node.ELEMENT_NODE) continue;

      Element child = (Element) n;

      if (child.getTagName().equals("cmd")) {
        String cmdId = child.getAttribute("refid");
        writer.print("callback.addCommand(");
        writer.print("\"" + Generator.escape(cmdId) + "\", ");
        writer.println("this.cmds." + cmdId + "());");
      } else if (child.getTagName().equals("separator")) {
        writer.println("callback.addSeparator();");
      } else if (child.getTagName().equals("menu")) {
        String label = child.getAttribute("label");
        writer.println("callback.beginMenu(\"" + Generator.escape(label) + "\");");
        emitMenu(writer, child);
        writer.println("callback.endMenu();");
      } else if (child.getTagName().equals("dynamic")) {
        String dynamicClass = child.getAttribute("class");
        writer.println("new " + dynamicClass + "().execute(callback);");
      } else {
        logger_.log(TreeLogger.Type.ERROR, "Unexpected tag " + el.getTagName() + " in menu");
        throw new UnableToCompleteException();
      }
    }
  }
示例#2
0
  public static String resolveExpression(
      String instance, String path, String prefix, String suffix) {
    String expression = path.replace(".", "().") + "()";

    if (!Strings.isNullOrEmpty(instance)) {
      expression = instance + "." + expression;
    }

    if (!Strings.isNullOrEmpty(prefix)) {
      expression = "\"" + Generator.escape(prefix) + "\" + " + expression;
    }

    if (!Strings.isNullOrEmpty(suffix)) {
      expression += " + \"" + Generator.escape(suffix) + "\"";
    }

    return expression;
  }
示例#3
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;
  }
示例#4
0
 /**
  * Helper method used to wrap a string constant with quotes. Must use to enable string escaping.
  *
  * @param wrapMe String to wrap
  * @return wrapped String
  */
 protected static String wrap(String wrapMe) {
   return "\"" + Generator.escape(wrapMe) + "\"";
 }