Ejemplo n.º 1
0
  @Override
  public TryStmtToken getToken(Token current, ListIterator<Token> iterator) {
    if (current instanceof TryStmtToken) {
      TryStmtToken result = (TryStmtToken) current;

      analyzer.addScope(false);
      BodyStmtToken body =
          analyzer.generator(BodyGenerator.class).getToken(nextToken(iterator), iterator);
      result.setBody(body);

      Token next = nextToken(iterator);
      result.setCatches(new ArrayList<CatchStmtToken>());

      if (next instanceof CatchStmtToken) {
        processCatches(result, next, iterator);
      } else if (next instanceof FinallyStmtToken) {
        analyzer.getScope().setLevelForGoto(true);
        processFinally(result, next, iterator);
        analyzer.getScope().setLevelForGoto(false);
      } else unexpectedToken(next, TokenType.T_CATCH);

      result.setLocal(analyzer.removeScope().getVariables());
      return result;
    }
    return null;
  }
Ejemplo n.º 2
0
  protected void processFinally(TryStmtToken result, Token current, ListIterator<Token> iterator) {
    if (result.getFinally() != null) unexpectedToken(current);

    result.setFinally(
        analyzer.generator(BodyGenerator.class).getToken(nextToken(iterator), iterator));
    if (!iterator.hasNext()) return;

    current = iterator.next();
    if (current instanceof CatchStmtToken) processCatches(result, current, iterator);
    else iterator.previous();
  }
Ejemplo n.º 3
0
  protected void processCatches(TryStmtToken result, Token current, ListIterator<Token> iterator) {
    List<CatchStmtToken> catches = result.getCatches();

    do {
      CatchStmtToken _catch = (CatchStmtToken) current;
      processCatch(_catch, iterator);
      catches.add(_catch);

      if (!iterator.hasNext()) break;

      current = iterator.next();
      if (!(current instanceof CatchStmtToken)) {
        if (current instanceof FinallyStmtToken) {
          processFinally(result, current, iterator);
          break;
        }

        iterator.previous();
        break;
      }
    } while (true);
  }