Package com.google.caja.parser.js

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


        needed.remove(id);
      }
      for (Identifier name : needed) {
        decls.add(new Declaration(name.getFilePosition(), name, null));
      }
      Statement decl;
      if (decls.size() == 1) {
        decl = decls.get(0);
      } else {
        decl = new MultiDeclaration(
            FilePosition.startOf(body.getFilePosition()), decls);
      }
      Statement declFollower = null;
      List<? extends Statement> bodyChildren = body.children();
      if (!bodyChildren.isEmpty()) { declFollower = bodyChildren.get(0); }
      if (declFollower instanceof DirectivePrologue) {
        declFollower = bodyChildren.size() == 1 ? null : bodyChildren.get(1);
      }
View Full Code Here


          if (chain.parent.node instanceof CatchStmt) { return true; }
          Declaration decl = (Declaration) node;
          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);
View Full Code Here

  private static List<Operation> extractAssignments(
      Block body, Set<Identifier> unassigned) {
    List<Operation> extracted = Lists.newArrayList();
    while (!body.children().isEmpty()) {
      Statement first = body.children().get(0);
      if (first instanceof Noop) {
        body.removeChild(first);
        continue;
      }
      if (first instanceof Block) {
        extracted.addAll(extractAssignments((Block) first, unassigned));
        if (first.children().isEmpty()) {
          body.removeChild(first);
        } else {
          break;
        }
      }
View Full Code Here

          if (b == null || b.children().isEmpty()) { return noResult(attr); }

          String handlerIndexName = meta.generateUniqueName("c");
          Identifier handlerIndex = SyntheticNodes.s(new Identifier(
              FilePosition.UNKNOWN, handlerIndexName));
          Statement handler = (Statement) QuasiBuilder.substV(
              ""
              + "var @handlerIndex = IMPORTS___.handlers___.push("
              + "    ___./*@synthetic*/markFuncFreeze("
              // There is no node or event object available to code in
              // javascript: URIs.
View Full Code Here

    InputSource is = new InputSource(new URI("file:///no/input/source"));
    CharProducer cp = CharProducer.Factory.create(new StringReader(src), is);
    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, is, JsTokenQueue.NO_COMMENT);
    Parser p = new Parser(tq, mq);
    Statement stmt = p.parse();
    p.getTokenQueue().expectEmpty();
    return stmt;
  }
View Full Code Here

                      source));
              if (sanitized.isSafe) {
                FilePosition pos = Nodes.getFilePositionForValue(classAttr);
                Expression e = sanitized.result;
                if (e == null) { e = StringLiteral.valueOf(pos, identifiers); }
                Statement s = new ExpressionStmt(
                    (Expression) QuasiBuilder.substV(
                         ""
                        + "IMPORTS___.htmlEmitter___"
                        + "    ./*@synthetic*/addBodyClasses(@idents);",
                        "idents", e));
View Full Code Here

        needed.remove(id);
      }
      for (Identifier name : needed) {
        decls.add(new Declaration(name.getFilePosition(), name, null));
      }
      Statement decl;
      if (decls.size() == 1) {
        decl = decls.get(0);
      } else {
        decl = new MultiDeclaration(
            FilePosition.startOf(body.getFilePosition()), decls);
      }
      Statement declFollower = null;
      List<? extends Statement> bodyChildren = body.children();
      if (!bodyChildren.isEmpty()) { declFollower = bodyChildren.get(0); }
      if (declFollower instanceof DirectivePrologue) {
        declFollower = bodyChildren.size() == 1 ? null : bodyChildren.get(1);
      }
View Full Code Here

          if (chain.parent.node instanceof CatchStmt) { return true; }
          Declaration decl = (Declaration) node;
          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);
View Full Code Here

  private static List<Operation> extractAssignments(
      Block body, Set<Identifier> unassigned) {
    List<Operation> extracted = Lists.newArrayList();
    while (!body.children().isEmpty()) {
      Statement first = body.children().get(0);
      if (first instanceof Noop) {
        body.removeChild(first);
        continue;
      }
      if (first instanceof Block) {
        extracted.addAll(extractAssignments((Block) first, unassigned));
        if (first.children().isEmpty()) {
          body.removeChild(first);
        } else {
          break;
        }
      }
View Full Code Here

          if (b == null || b.children().isEmpty()) { return noResult(attr); }

          String handlerIndexName = meta.generateUniqueName("c");
          Identifier handlerIndex = SyntheticNodes.s(new Identifier(
              FilePosition.UNKNOWN, handlerIndexName));
          Statement handler = (Statement) QuasiBuilder.substV(
              ""
              + "var @handlerIndex = IMPORTS___.handlers___.push("
              + "    ___./*@synthetic*/markFuncFreeze("
              // There is no node or event object available to code in
              // javascript: URIs.
View Full Code Here

TOP

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

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.