Package com.google.caja.parser.js

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


  private static void appendIfNotEmptyOrIgnored(
      ObjectConstructor obj, String key, ArrayConstructor value,
      String... ignoreKeys) {
    if (!value.children().isEmpty()
        && !Arrays.asList(ignoreKeys).contains(key)) {
      obj.appendChild(new ValueProperty(
          StringLiteral.valueOf(FilePosition.UNKNOWN, key), value));
    }
  }
View Full Code Here


      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);
View Full Code Here

  public JsOptimizer setEnvJson(ObjectConstructor envJson) {
    if (optimizer == null) { optimizer = new ParseTreeKB(); }
    List<? extends ObjProperty> props = envJson.children();
    for (ObjProperty prop : props) {
      // JSON had better not have getters
      ValueProperty vprop = (ValueProperty) prop;
      Expression value = vprop.getValueExpr().fold(false); // fold negative nums
      if (!(value instanceof Literal)) {
        // True for "*useragent*" property inserted by JSKB.
        continue;
      }
      StringLiteral sl = vprop.getPropertyNameNode();
      String rawExpr = sl.getValue();
      rawExpr = " " + rawExpr.substring(1, rawExpr.length() - 1) + " ";
      CharProducer valueCp = CharProducer.Factory.fromJsString(
          CharProducer.Factory.fromString(rawExpr, sl.getFilePosition()));
      try {
View Full Code Here

    QuasiNode value = getValue();
    Iterator<ParseTreeNode> it = specimens.iterator();
    while (it.hasNext()) {
      ParseTreeNode candidate = it.next();
      if (!(candidate instanceof ValueProperty)) { continue; }
      ValueProperty prop = (ValueProperty) candidate;
      List<ParseTreeNode> keyCandidate = Lists.<ParseTreeNode>newArrayList(
          prop.getPropertyNameNode());
      if (key.consumeSpecimens(keyCandidate, bindings)
          && keyCandidate.isEmpty()) {
        List<ParseTreeNode> valueCandidate = Lists.<ParseTreeNode>newArrayList(
            prop.getValueExpr());
        if (value.consumeSpecimens(valueCandidate, bindings)) {
          if (valueCandidate.isEmpty()) { it.remove(); }
          return true;
        }
      }
View Full Code Here

          int subsSizeValue = substitutes.size();
          if (subsSizeValue == subsSizeKey + 1) {
            StringLiteral key = (StringLiteral) substitutes.get(subsSize);
            Expression value = (Expression) substitutes.get(subsSize + 1);
            substitutes.subList(subsSize, substitutes.size()).clear();
            substitutes.add(new ValueProperty(key, value));
            return true;
          }
        }
      }
    }
View Full Code Here

      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    List<ParseTreeNode> keyList = Lists.newArrayList();
    List<ParseTreeNode> valueList = Lists.newArrayList();
    for (ParseTreeNode quasi : specimens) {
      if (!(quasi instanceof ValueProperty)) { return false; }
      ValueProperty prop = (ValueProperty) quasi;
      keyList.add(prop.getPropertyNameNode());
      valueList.add(prop.getValueExpr());
    }
    if (putIfDeepEquals(
            bindings, keyIdentifier, new ParseTreeNodeContainer(keyList))
        && putIfDeepEquals(
              bindings, valueIdentifier,
View Full Code Here

      ParseTreeNode valueNode = bindings.get(valueIdentifier);
      assert keyNode.children().size() == valueNode.children().size();
      List<ObjProperty> children = Lists.newArrayList();
      for (int i = 0; i < keyNode.children().size(); i++) {
        children.add(
            new ValueProperty(
                (StringLiteral) keyNode.children().get(i),
                (Expression) valueNode.children().get(i)));
      }
      substitutes.addAll(children);
      return true;
View Full Code Here

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

  private static ValueProperty prop(String key, Expression e) {
    return new ValueProperty(FilePosition.UNKNOWN, lit(key), e);
  }
View Full Code Here

  public JsOptimizer setEnvJson(ObjectConstructor envJson) {
    if (optimizer == null) { optimizer = new ParseTreeKB(); }
    List<? extends ObjProperty> props = envJson.children();
    for (ObjProperty prop : props) {
      // JSON had better not have getters
      ValueProperty vprop = (ValueProperty) prop;
      Expression value = vprop.getValueExpr().fold(false); // fold negative nums
      if (!(value instanceof Literal)) {
        // True for "*useragent*" property inserted by JSKB.
        continue;
      }
      StringLiteral sl = vprop.getPropertyNameNode();
      String rawExpr = sl.getValue();
      rawExpr = " " + rawExpr.substring(1, rawExpr.length() - 1) + " ";
      CharProducer valueCp = CharProducer.Factory.fromJsString(
          CharProducer.Factory.fromString(rawExpr, sl.getFilePosition()));
      try {
View Full Code Here

      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    List<ParseTreeNode> keyList = Lists.newArrayList();
    List<ParseTreeNode> valueList = Lists.newArrayList();
    for (ParseTreeNode quasi : specimens) {
      if (!(quasi instanceof ValueProperty)) { return false; }
      ValueProperty prop = (ValueProperty) quasi;
      keyList.add(prop.getPropertyNameNode());
      valueList.add(prop.getValueExpr());
    }
    if (putIfDeepEquals(
            bindings, keyIdentifier, new ParseTreeNodeContainer(keyList))
        && putIfDeepEquals(
              bindings, valueIdentifier,
View Full Code Here

TOP

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

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.