Examples of TryStmt


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

  public final void testMaskedExceptionVariablesSame() throws Exception {
    Block outerBlock = js(fromString(
        "try { } catch (e) { try { } catch (e) { var x; } }"));

    TryStmt t0 = (TryStmt) outerBlock.children().get(0);
    CatchStmt c0 = t0.getCatchClause();
    Block b0 = c0.getBody();
    TryStmt t1 = (TryStmt) b0.children().get(0);
    CatchStmt c1 = t1.getCatchClause();

    Scope sn = fromProgram(outerBlock);
    Scope sc0 = Scope.fromCatchStmt(sn, c0);
    Scope.fromCatchStmt(sc0, c1);
View Full Code Here

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

  }

  public final void testStartStatementsForCatchStmt() throws Exception {
    Scope s0 = fromProgram(js(fromString("{}")));
    Block block = js(fromString("try {} catch (e) {}"));
    TryStmt t = (TryStmt)block.children().get(0);
    Scope s1 = Scope.fromCatchStmt(s0, t.getCatchClause());

    assertEquals(0, s0.getStartStatements().size());
    assertEquals(0, s1.getStartStatements().size());

    s1.addStartStatement(js(fromString("{}")));
View Full Code Here

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

    assertEquals(1, s1.getStartStatements().size());
  }

  public final void testUnmaskableIdentifiersInCatch() throws Exception {
    Block b = js(fromString("try {} catch (Object) {}"));
    TryStmt tryStmt = (TryStmt) b.children().get(0);
    Scope top = fromProgram(b);
    Scope.fromCatchStmt(top, tryStmt.getCatchClause());
    assertMessage(
        RewriterMessageType.CANNOT_MASK_IDENTIFIER, MessageLevel.FATAL_ERROR,
        MessagePart.Factory.valueOf("Object"));
  }
View Full Code Here

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

          substitutes="try { @body*; } catch (@ex___) { @handler*; }")
      public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
        Map<String, ParseTreeNode> bindings = this.match(node);
        if (bindings != null) {
          Identifier ex = (Identifier) bindings.get("ex");
          TryStmt ts = (TryStmt) node;
          CatchStmt cs = ts.getCatchClause();
          if (isSynthetic(ex)) {
            return substV(
                "body", rw.expand(bindings.get("body"), scope),
                "ex", rw.noexpand(ex),
                "handler", rw.expand(
                    bindings.get("handler"), Scope.fromCatchStmt(scope, cs)));
          }
        }
        return NONE;
      }
    },

    new Rule() {
      @Override
      @RuleDescription(
          name="syntheticCatches2",
          synopsis="Pass through synthetic variables which are unmentionable.",
          reason="Catching unmentionable exceptions helps maintain invariants.",
          matches=(
               "try { @body*; } catch (/* synthetic */ @ex___) { @handler*; }"
               + " finally { @cleanup*; }"),
          substitutes=(
               "try { @body*; } catch (/* synthetic */ @ex___) { @handler*; }"
               + " finally { @cleanup*; }"))
      public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
        Map<String, ParseTreeNode> bindings = this.match(node);
        if (bindings != null) {
          TryStmt ts = (TryStmt) node;
          CatchStmt cs = ts.getCatchClause();
          Identifier ex = (Identifier) bindings.get("ex");
          if (isSynthetic(ex)) {
            return substV(
                "body", rw.expand(bindings.get("body"), scope),
                "ex", rw.noexpand(ex),
View Full Code Here

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

      if ((lasti & 1) == 0) {  // else clause
        nodes.set(lasti, returnLast(nodes.get(lasti)));
      }
      result = new Conditional(node.getFilePosition(), null, nodes);
    } else if (node instanceof TryStmt) {
      TryStmt tryer = (TryStmt) node;
      result = new TryStmt(
          node.getFilePosition(),
          (Block) returnLast(tryer.getBody()),
          tryer.getCatchClause(),
          tryer.getFinallyClause());
    }
    if (null == result) { return node; }
    result.getAttributes().putAll(node.getAttributes());
    return result;
  }
View Full Code Here

Examples of japa.parser.ast.stmt.TryStmt

        return Boolean.TRUE;
    }

    public Boolean visit(TryStmt n1, Node arg) {
        TryStmt n2 = (TryStmt) arg;

        if (!nodeEquals(n1.getTryBlock(), n2.getTryBlock())) {
            return Boolean.FALSE;
        }

        if (!nodesEquals(n1.getCatchs(), n2.getCatchs())) {
            return Boolean.FALSE;
        }

        if (!nodeEquals(n1.getFinallyBlock(), n2.getFinallyBlock())) {
            return Boolean.FALSE;
        }

        return Boolean.TRUE;
    }
View Full Code Here

Examples of japa.parser.ast.stmt.TryStmt

                jj_consume_token(-1);
                throw new ParseException();
        }
        {
            if (true) {
                return new TryStmt(line, column, token.endLine, token.endColumn, tryBlock, catchs, finallyBlock);
            }
        }
        throw new Error("Missing return statement in function");
    }
View Full Code Here

Examples of japa.parser.ast.stmt.TryStmt

        statement = null;
    }

    @Given("a TryStmt")
    public void givenATryStmt() {
        tryStmt = new TryStmt();
    }
View Full Code Here

Examples of japa.parser.ast.stmt.TryStmt

    BlockStmt tryBlock = cloneNodes(_n.getTryBlock(), _arg);
    List<CatchClause> catchs = visit(_n.getCatchs(), _arg);
    BlockStmt finallyBlock = cloneNodes(_n.getFinallyBlock(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);

    TryStmt r = new TryStmt(
        _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
        resources, tryBlock, catchs, finallyBlock
    );
    r.setComment(comment);
    return r;
  }
View Full Code Here

Examples of japa.parser.ast.stmt.TryStmt

    return Boolean.TRUE;
  }

  @Override public Boolean visit(final TryStmt n1, final Node arg) {
    final TryStmt n2 = (TryStmt) arg;

    if (!nodeEquals(n1.getTryBlock(), n2.getTryBlock())) {
      return Boolean.FALSE;
    }

    if (!nodesEquals(n1.getCatchs(), n2.getCatchs())) {
      return Boolean.FALSE;
    }

    if (!nodeEquals(n1.getFinallyBlock(), n2.getFinallyBlock())) {
      return Boolean.FALSE;
    }

    return Boolean.TRUE;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.