Package com.google.caja.parser.js

Examples of com.google.caja.parser.js.ObjectConstructor


    //      literals: ["foo", "bar"],
    //      properties: [
    //      fns: [],
    //    }
    final FilePosition unk = FilePosition.UNKNOWN;
    ObjectConstructor obj = new ObjectConstructor(unk);
    appendIfNotEmptyOrIgnored(
        obj, "lits",
        mapToJsArray(
            Sets.newTreeSet(data.literals),
            new Function<String, Expression>() {
View Full Code Here


    } catch (IOException ex) {
      mq.addMessage(
          MessageType.IO_ERROR, MessagePart.Factory.valueOf(ex.toString()));
      return;
    }
    ObjectConstructor envJson;
    try {
      Parser p = parser(cp, mq);
      Expression e = p.parseExpression(true); // TODO(mikesamuel): limit to JSON
      p.getTokenQueue().expectEmpty();
      if (!(e instanceof ObjectConstructor)) {
View Full Code Here

    for (int propIndex = 0, n = propData.size(); propIndex < n; ++propIndex) {
      Pair<CssSchema.CssPropertyInfo, CssPropertyData> d
          = propData.get(propIndex);
      CssPropertyData data = d.b;

      ObjectConstructor dataObj = new ObjectConstructor(unk);

      int propBits = 0;
      for (CssPropBit b : data.properties) {
        propBits |= b.jsValue;
      }

      dataObj.appendChild(
          new ValueProperty(propbitsObjKey, new IntegerLiteral(unk, propBits)));

      List<Expression> litGroups = Lists.newArrayList();
      for (int groupIndex : litPartition.unions[propIndex]) {
        litGroups.add((Expression) QuasiBuilder.substV(
            "L[@i]", "i", new IntegerLiteral(unk, groupIndex)));
      }
      if (!litGroups.isEmpty()) {
        dataObj.appendChild(new ValueProperty(
            litgroupObjKey, new ArrayConstructor(unk, litGroups)));
      }

      List<Expression> fnKeyStrs = Lists.newArrayList();
      for (CssPropertySignature.CallSignature fn : data.fns) {
        String fnKey = fnSigToData.get(fn).key;
        fnKeyStrs.add(StringLiteral.valueOf(unk, fnKey));
      }
      ArrayConstructor fnKeyArray = new ArrayConstructor(unk, fnKeyStrs);
      dataObj.appendChild(new ValueProperty(fnsObjKey, fnKeyArray));

      String dataJs;
      {
        StringBuilder js = new StringBuilder();
        JsMinimalPrinter tokenConsumer = new JsMinimalPrinter(js);
        dataObj.render(new RenderContext(tokenConsumer));
        tokenConsumer.noMoreTokens();
        dataJs = js.toString();
      }

      String equivKey = dataJsToKey.get(dataJs);
      Expression value = dataObj;
      if (equivKey == null) {
        dataJsToKey.put(dataJs, data.key);
      } else {
        value = StringLiteral.valueOf(unk, equivKey);
        hasAliases = true;
      }
      cssSchemaProps.add(new ValueProperty(
          unk, StringLiteral.valueOf(unk, data.key), value));
    }

    ObjectConstructor cssSchema = new ObjectConstructor(unk, cssSchemaProps);

    ParseTreeNode js = QuasiBuilder.substV(
        ""
        + "var cssSchema = (function () {"
        + "  @poolDecls?;"
View Full Code Here

  public static void main(String... args) throws IOException {
    MessageQueue mq = new SimpleMessageQueue();
    MessageContext mc = new MessageContext();
    JsOptimizer opt = new JsOptimizer(mq);
    opt.setRename(true);
    opt.setEnvJson(new ObjectConstructor(FilePosition.UNKNOWN));
    try {
      for (int i = 0, n = args.length; i < n; ++i) {
        String arg = args[i];
        if ("--norename".equals(arg)) {
          opt.setRename(false);
View Full Code Here

  protected boolean consumeSpecimens(
      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    if (specimens.isEmpty()) { return false; }
    ParseTreeNode specimen = specimens.get(0);
    if (!(specimen instanceof ObjectConstructor)) { return false; }
    ObjectConstructor obj = (ObjectConstructor) specimen;
    List<ParseTreeNode> parts = Lists.<ParseTreeNode>newLinkedList(
        obj.children());
    MultiPropertyQuasi hole = null;
    for (QuasiNode q : getChildren()) {
      if (q instanceof MultiPropertyQuasi) {
        hole = (MultiPropertyQuasi) q;
      } else {
View Full Code Here

    for (QuasiNode q : getChildren()) {
      if (!q.createSubstitutes(props, bindings)) { return false; }
    }
    ObjProperty[] propArr = new ObjProperty[props.size()];
    props.toArray(propArr);
    substitutes.add(new ObjectConstructor(
        FilePosition.UNKNOWN, Arrays.asList(propArr)));
    return true;
  }
View Full Code Here

    } catch (IOException ex) {
      mq.addMessage(
          MessageType.IO_ERROR, MessagePart.Factory.valueOf(ex.toString()));
      return;
    }
    ObjectConstructor envJson;
    try {
      Parser p = parser(cp, mq);
      Expression e = p.parseExpression(true); // TODO(mikesamuel): limit to JSON
      p.getTokenQueue().expectEmpty();
      if (!(e instanceof ObjectConstructor)) {
View Full Code Here

  private static ArrayConstructor arr(List<? extends Expression> items) {
    return new ArrayConstructor(FilePosition.UNKNOWN, items);
  }

  private static ObjectConstructor obj(List<? extends ValueProperty> props) {
    return new ObjectConstructor(FilePosition.UNKNOWN, props);
  }
View Full Code Here

      moduleInvocations = moduleInvocations != null
          ? Operation.createInfix(Operator.COMMA, moduleInvocations, invocation)
          : invocation;
    }

    ObjectConstructor oc = (ObjectConstructor) QuasiBuilder.substV(
        ""
        + "({"
        + "  instantiate: function (___, IMPORTS___) {"
        + "    return @moduleInvocations?;"
        + "  },"
View Full Code Here

        Long.valueOf(new TestBuildInfo().getCurrentTime()),
        bindings.get("cajoledDate").getValue());
  }

  private CajoledModule makeTestCajoledModule() {
    ObjectConstructor oc = (ObjectConstructor) QuasiBuilder.substV(
        "  ({"
        + "  instantiate: function() {},"
        + "  foo: 42"
        + "})");
    return new CajoledModule(
View Full Code Here

TOP

Related Classes of com.google.caja.parser.js.ObjectConstructor

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.