Package com.google.caja.parser.js

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


    //   12;
    // }

    ExpressionStmt[] b = new ExpressionStmt[13];
    for (int i = b.length; --i >= 0;) {
      b[i] = new ExpressionStmt(unk, new IntegerLiteral(unk, i));
    }

    LabeledStmtWrapper b1 = new LabeledStmtWrapper(
        unk, "$1", new Block(unk, Arrays.asList(b[2], b[3], b[4])));
View Full Code Here


  // setComments causes a warning about generic array for varargs
  public final void testImmutability() throws Exception {
    Block n = new Block(
        FilePosition.UNKNOWN,
        Arrays.asList(
            new ExpressionStmt(new IntegerLiteral(FilePosition.UNKNOWN, 42)),
            new ExpressionStmt(new IntegerLiteral(FilePosition.UNKNOWN, 13))));
    assertTrue(n.makeImmutable());
    assertTrue(n.isImmutable());
    assertTrue(n.children().get(0).isImmutable());
    assertTrue(n.children().get(0).children().get(0).isImmutable());
    assertTrue(n.children().get(1).isImmutable());
View Full Code Here

  public final void testIncompleteImmutability() throws Exception {
    // Immutability should be best-effort, stopping at a node that refuses
    Block n = new Block(
        FilePosition.UNKNOWN,
        Arrays.asList(
            new ExpressionStmt(new IntegerLiteral(FilePosition.UNKNOWN, 42)),
            new ExpressionStmt(new AlwaysMutable())));
    assertFalse(n.makeImmutable());
    assertFalse(n.isImmutable());
    assertTrue(n.children().get(0).isImmutable());
    assertTrue(n.children().get(0).children().get(0).isImmutable());
    assertFalse(n.children().get(1).isImmutable());
View Full Code Here

          if (toRemove.contains(num.longValue())) {
            p.removeChild(sibling);
          }
        }
        for (int i = 0; i < toAdd.length; ++i) {
          p.appendChild(new ExpressionStmt(
              FilePosition.UNKNOWN,
              new IntegerLiteral(FilePosition.UNKNOWN, toAdd[i])));
        }
      }
      return true;
View Full Code Here

              // if (foo() && 0) { ... } else { baz(); }  =>  { foo(); baz(); }
            } else {
              optimizeConditional(s, c, i + 2, out);
            }
            List<Statement> stmts = Lists.newArrayList();
            stmts.add(new ExpressionStmt(sideEffect));
            if (out.node instanceof Block) {
              stmts.addAll(((Block) out.node).children());
            } else if (!(out.node instanceof Noop)) {
              stmts.add((Statement) out.node);
            }
View Full Code Here

            if (s instanceof ReturnStmt) {
              newChild = new ReturnStmt(exprPos, joined);
            } else if (s instanceof ThrowStmt) {
              newChild = new ThrowStmt(exprPos, joined);
            } else {
              newChild = new ExpressionStmt(exprPos, joined);
            }
            stmts.subList(start, end).clear();
            stmts.add(start, newChild);
            n -= end - start;
            i = start;
View Full Code Here

          Identifier id = decl.getIdentifier();
          removedIdents.add(id);
          Expression init = decl.getInitializer();
          Statement replacement;
          if (init != null) {
            replacement = new ExpressionStmt(toAssignment(decl));
          } else if (chain.parent.node instanceof ForEachLoop) {
            replacement = new ExpressionStmt(new Reference(id));
          } else {
            replacement = new Noop(decl.getFilePosition());
          }
          changes.add(Pair.pair(chain.cast(Statement.class), replacement));
          return true;
        } else if (node instanceof MultiDeclaration) {
          List<Expression> replacements = Lists.newArrayList();
          for (Declaration decl : ((MultiDeclaration) node).children()) {
            removedIdents.add(decl.getIdentifier());
            if (decl.getInitializer() == null) { continue; }
            visit(chain.child(decl).child(decl.getInitializer()));
            Expression assign = toAssignment(decl);
            replacements.add(assign);
          }
          Statement replacement;
          if (replacements.isEmpty()) {
            replacement = new Noop(node.getFilePosition());
          } else if (replacements.size() == 1) {
            Expression e = replacements.get(0);
            replacement = new ExpressionStmt(e.getFilePosition(), e);
          } else if (chain.parent.node instanceof Block) {
            List<Statement> stmts = Lists.newArrayList();
            for (Expression e : replacements) {
              stmts.add(new ExpressionStmt(e));
            }
            replacement = new Block(node.getFilePosition(), stmts);
          } else {
            Expression combo = null;
            for (Expression e : replacements) {
              combo = combo == null
                  ? e : Operation.createInfix(Operator.COMMA, combo, e);
            }
            replacement = new ExpressionStmt(node.getFilePosition(), combo);
          }
          changes.add(Pair.pair(chain.cast(Statement.class), replacement));
          return false;
        } else if (node instanceof FunctionConstructor) {
          inners.add((FunctionConstructor) node);
View Full Code Here

      // to rewrite them, so we need quoted keys.
      String quoted = StringLiteral.toQuotedValue(keyMaker.apply(e));
      keys.add(new StringLiteral(unk, quoted));
      values.add(new IntegerLiteral(unk, valueMaker.apply(e)));
    }
    return new ExpressionStmt(unk,
        (Expression) QuasiBuilder.substV(
            "html4.@i = { @k*: @v* };",
            "i", new Reference(new Identifier(unk, key)),
            "k", new ParseTreeNodeContainer(keys),
            "v", new ParseTreeNodeContainer(values)));
View Full Code Here

            || SCRIPT_SRC.equals(key)) {
          keys.add(StringLiteral.valueOf(unk, key.toString()));
          values.add(new IntegerLiteral(unk, A_TYPE_MAP.get(e.getValue())));
        }
      }
      definitions.appendChild(new ExpressionStmt(unk, (Expression)
          QuasiBuilder.substV(
              "html4.ATTRIBS = { @k*: @v* };",
              "k", new ParseTreeNodeContainer(keys),
              "v", new ParseTreeNodeContainer(values))));
    }

    definitions.appendChild(mapFromEnum(
        EnumSet.allOf(EFlag.class),
        "eflags",
        new Function<EFlag, String>() {
          public String apply(EFlag f) {
            return f.name();
          }
        },
        new Function<EFlag, Integer>() {
          public Integer apply(EFlag f) {
            return f.bitMask;
          }
        })
    );

    {
      List<StringLiteral> keys = new ArrayList<StringLiteral>();
      List<IntegerLiteral> values = new ArrayList<IntegerLiteral>();
      for (Map.Entry<ElKey, EnumSet<EFlag>> e : eflags.entrySet()) {
        ElKey key = e.getKey();
        int value = 0;
        for (EFlag f : e.getValue()) { value |= f.bitMask; }
        keys.add(StringLiteral.valueOf(unk, key.toString()));
        values.add(new IntegerLiteral(unk, value));
      }
      definitions.appendChild(new ExpressionStmt(unk, (Expression)
          QuasiBuilder.substV(
              "html4.ELEMENTS = { @k*: @v* };",
              "k", new ParseTreeNodeContainer(keys),
              "v", new ParseTreeNodeContainer(values))));
    }
View Full Code Here

    ParseTreeNode result = null;
    // Code translated from another language should not be used as the module
    // result.
    if (isForSideEffect(node)) { return node; }
    if (node instanceof ExpressionStmt) {
      result = new ExpressionStmt(
          node.getFilePosition(),
          (Expression) QuasiBuilder.substV(
              "moduleResult___ = @result;",
              "result", ((ExpressionStmt) node).getExpression()));
    } else if (node instanceof ParseTreeNodeContainer) {
View Full Code Here

TOP

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

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.