Package com.google.caja.parser.js

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


        obj, "props",
        mapToJsArray(
            data.properties,
            new Function<CssPropBit, Expression>() {
              public Expression apply(CssPropBit bit) {
                return new Reference(new Identifier(unk, bit.name()));
              }
            }),
        ignoreKeys);
    appendIfNotEmptyOrIgnored(
        obj, "fns",
View Full Code Here


  private static BreakStmt b(String label) {
    return new BreakStmt(FilePosition.UNKNOWN, label);
  }
  private static Declaration decl(String name) {
    return new Declaration(
        FilePosition.UNKNOWN, new Identifier(FilePosition.UNKNOWN, name), null);
  }
View Full Code Here

    root.visitPreOrder(new ParseTreeNodeVisitor() {
      public boolean visit(ParseTreeNode node) {
        if (clazz.isAssignableFrom(node.getClass()) &&
            node.children().size() > 0 &&
            node.children().get(0) instanceof Identifier) {
          Identifier id = (Identifier)node.children().get(0);
          if ((identifierValue == null && id.getValue() == null) ||
              (identifierValue != null && identifierValue.equals(id.getValue()))) {
            assertNull(result.value);
            result.value = (T)node;
            return false;
          }
        }
View Full Code Here

  public final void testIdsWithUnderscores() throws Exception {
    String[] underscoreIds = {"x__", "x\u005f\u005f", "__", "\u005f\u005f" };
    for (String id : underscoreIds) {
      ParseTreeNode specimen = QuasiBuilder.substV(
          "{ var @idWithUnderscore = 1; }",
          "idWithUnderscore", new Identifier(FilePosition.UNKNOWN, id)
      );
      assertTrue("Valid id failed to parse: " + id,
          QuasiBuilder.match("{ var @x__ = 1; }", specimen));
    }
  }
View Full Code Here

    Map<String, ParseTreeNode> bindings = Maps.newHashMap();
    if (!QuasiBuilder.match("{ var @p; }", node, bindings)) { return false; }
    if (bindings.size() != 1) { return false; }
    if (bindings.get("p") == null) { return false; }
    if (!(bindings.get("p") instanceof Identifier)) { return false; }
    Identifier p = (Identifier) bindings.get("p");
    if (!candidate.equals(p.getName())) { return false; }
    return true;
  }
View Full Code Here

  private static Statement export(String key, Expression e) {
    FilePosition unk = FilePosition.UNKNOWN;
    // The html4[@k] assignment is an explicit export for Closure Compiler
    return (Statement) QuasiBuilder.substV(
            "{ html4.@i = @e; html4[@k] = html4.@i; }",
            "i", new Reference(new Identifier(unk, key)),
            "k", new StringLiteral(unk, key),
            "e", e);
  }
View Full Code Here

      keys.add(new StringLiteral(unk, quoted));
      values.add(new IntegerLiteral(unk, valueMaker.apply(e)));
    }
    return export(key, (Expression) QuasiBuilder.substV(
        "({ @k*: @v* })",
        "i", new Reference(new Identifier(unk, key)),
        "k", new ParseTreeNodeContainer(keys),
        "v", new ParseTreeNodeContainer(values)));
  }
View Full Code Here

    Statement poolDecls = null;
    if (!stringPool.isEmpty()) {
      poolDecls = joinDeclarations(
          poolDecls,
          new Declaration(unk, new Identifier(unk, "s"),
              new ArrayConstructor(unk, stringPool)));
    }
    if (!regexPool.isEmpty()) {
      poolDecls = joinDeclarations(
          poolDecls,
          new Declaration(unk, new Identifier(unk, "c"),
              new ArrayConstructor(unk, regexPool)));
    }

    // Given keyword sets like
    // [['red','blue','green','transparent','inherit',;none'],
    //  ['red','blue','green'],
    //  ['inherit','none','bold','bolder']]
    // recognize that ['red','blue','green'] probably occurs frequently and
    // create a partition like
    // [['red','blue','green'],['bold','bolder'],['inherit',none'],
    //  ['transparent']]
    // and then store indices into the array of partition elements with
    // CSS property names so they can be unioned as needed.
    List<Set<String>> literalSets = Lists.newArrayList();
    for (Pair<CssSchema.CssPropertyInfo, CssPropertyData> p : propData) {
      literalSets.add(p.b.literals);
    }
    Partitions.Partition<String> litPartition = Partitions.partition(
        literalSets, String.class, null);
    List<ArrayConstructor> literalSetArrs = Lists.newArrayList();
    for (int[] literalIndices : litPartition.partition) {
      List<StringLiteral> literalArr = Lists.newArrayList();
      for (int litIndex : literalIndices) {
        literalArr.add(StringLiteral.valueOf(
            unk, litPartition.universe[litIndex]));
      }
      literalSetArrs.add(new ArrayConstructor(unk, literalArr));
    }
    if (!literalSetArrs.isEmpty()) {
      poolDecls = joinDeclarations(
          poolDecls,
          new Declaration(unk, new Identifier(unk, "L"),
              new ArrayConstructor(unk, literalSetArrs)));
    }

    List<ValueProperty> cssSchemaProps = Lists.newArrayList();
    StringLiteral propbitsObjKey = new StringLiteral(unk, "cssPropBits");
View Full Code Here

      int nUses = v.uses.size();
      if (canonLen * nUses > 8 + canonLen + 2 * nUses + requiredSavings) {
        // TODO(mikesamuel): choose a guaranteed non-interfering name.
        String name = "$_$__litpool__" + decls.size() + "$_$";
        decls.add(new Declaration(
            pos, new Identifier(pos, name), v.uses.get(0).node));
        for (AncestorChain<Literal> use : v.uses) {
          Reference ref = new Reference(
              new Identifier(use.node.getFilePosition(), name));
          use.parent.cast(MutableParseTreeNode.class).node
              .replaceChild(ref, use.node);
        }
      }
    }
View Full Code Here

  private int longestKeyLength = 0;

  private static final FilePosition UNK = FilePosition.UNKNOWN;

  public ParseTreeKB() {
    addFactInt(new Reference(new Identifier(UNK, "undefined")), Fact.UNDEFINED);
    addFactInt(new Reference(new Identifier(UNK, "this")), Fact.GLOBAL);
  }
View Full Code Here

TOP

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

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.