Examples of CatchClause


Examples of com.bacoder.parser.java.api.CatchClause

    tryStatement.setCatchClauses(transform(context, CatchClauseContext.class,
        new Function<CatchClauseContext, CatchClause>() {
          @Override
          public CatchClause apply(CatchClauseContext context) {
            CatchClause catchClause = createNode(context, CatchClause.class);

            setModifiers(context, catchClause);

            CatchTypeContext catchTypeContext = getChild(context, CatchTypeContext.class);
            if (catchTypeContext != null) {
              catchClause.setExceptions(transform(catchTypeContext, QualifiedNameContext.class,
                  new Function<QualifiedNameContext, QualifiedName>() {
                    @Override
                    public QualifiedName apply(QualifiedNameContext context) {
                      return getAdapter(QualifiedNameAdapter.class).adapt(context);
                    }
                  }));
            }

            TerminalNode identifierNode = getTerminalNode(context, JavaParser.Identifier);
            if (identifierNode != null) {
              catchClause.setVariable(getAdapter(IdentifierAdapter.class).adapt(identifierNode));
            }

            BlockContext blockContext = getChild(context, BlockContext.class);
            if (blockContext != null) {
              catchClause.setBody(getAdapter(BlockAdapter.class).adapt(blockContext));
            }

            return catchClause;
          }
        }));
View Full Code Here

Examples of com.dragome.compiler.ast.CatchClause

  {
    println("try {");
    visit_(tryStmt.getTryBlock());
    indent("} ");
    Block clauses= tryStmt.getCatchStatements();
    CatchClause clause= (CatchClause) clauses.getFirstChild();

    String ex= null;
    if (clause != null)
    {
      ex= clause.getException().getName();
    }

    //  if (clauses.getChildCount() == 1)
    //  {
    //      print("catch(" + ex + ") ");
    //      clause.visit(this);
    //  }
    if (clauses.getChildCount() > 0)
    {
      println("catch(" + ex + ") {");
      depth++;
      indent();
      while (clause != null)
      {
        if (clause.getException().getType() != null)
          print("if (dragomeJs.isInstanceof(" + ex + ", " + normalizeExpression(Utils.getSignature(clause.getException().getType())) + ")) ");
        else
          print("if (true)");

        clause.visit(this);
        clause= (CatchClause) clause.getNextSibling();
        if (clause == null)
          break;
        print(" else ");
      }
View Full Code Here

Examples of com.dragome.compiler.ast.CatchClause

    {
      stmt.setFinallyBlock(new Block());
      graph.rollOut(finallyNode, stmt.getFinallyBlock());
    }

    CatchClause cc= (CatchClause) stmt.getCatchStatements().getFirstChild();
    Iterator iter= catchNodes.iterator();
    while (iter.hasNext())
    {
      Node catchNode= (Node) iter.next();
      graph.rollOut(catchNode, cc);
      cc= (CatchClause) cc.getNextSibling();
    }
  }
View Full Code Here

Examples of com.dragome.compiler.ast.CatchClause

    loopFound= false;
  }

  private CatchClause createCatchClause(TryStatement tryStmt, ExceptionHandler handle)
  {
    CatchClause cStmt= new CatchClause(handle.getHandlerPC());
    VariableDeclaration decl= new VariableDeclaration(VariableDeclaration.LOCAL_PARAMETER);
    decl.setName("_EX_");
    decl.setType(handle.getCatchType(constantPool));
    cStmt.setException(decl);
    tryStmt.addCatchStatement(cStmt);
    return cStmt;
  }
View Full Code Here

Examples of com.dragome.compiler.ast.CatchClause

    Node tryNode= graph.getOrCreateNode(stmt.getBeginIndex());
    tryNode.stack= new ASTNodeStack();
    header.setTryBody(tryNode);

    CatchClause clause= (CatchClause) stmt.getCatchStatements().getFirstChild();
    while (clause != null)
    {
      // Push implicit exception.
      Node catchNode= graph.createNode(clause.getBeginIndex());
      // catchNode.type = NodeType.CATCH;
      catchNode.stack= new ASTNodeStack(new VariableBinding(clause.getException()));
      header.addCatchNode(catchNode);

      clause= (CatchClause) clause.getNextSibling();
    }
  }
View Full Code Here

Examples of com.dragome.compiler.ast.CatchClause

      // tryStmt.setBeginIndex(start);

      tryStatements.add(tryStmt);

      CatchClause cStmt= null;

      // Collect all non-default handlers. The range of each handler is
      // from the 'store'-instruction to the beginning of the next
      // handler.
      while (handle != null && !handle.isDefault() && handle.getStartPC() == start && handle.getEndPC() == end)
      {
        if (cStmt != null)
        {
          cStmt.setEndIndex(handle.getHandlerPC() - 1);
        }
        cStmt= createCatchClause(tryStmt, handle);
        handle= handleIterator.hasNext() ? handleIterator.next() : null;
      }

      int foo= -1;
      if (handle != null && handle.isDefault() && handle.getStartPC() == start)
      {
        // Collect first default handler.
        hasFinally= true;
        if (cStmt != null)
        {
          cStmt.setEndIndex(handle.getHandlerPC() - 1);
          tryStmt.setEndIndex(handle.getHandlerPC() - 1);
          // Warning: We only set a lower bound for the end index. The
          // correct index is set later
          // when the finally statement is analysed.
        }
        cStmt= createCatchClause(tryStmt, handle);
        foo= handle.getHandlerPC();
        handle= handleIterator.hasNext() ? handleIterator.next() : null;
      }

      // Last catch stmt has no endIndex, yet!

      while (handle != null && handle.isDefault() && (handle.getHandlerPC() == foo))
      {
        // Skip all remaining default handlers.
        throw new RuntimeException("remaining default handlers");
        // handle = handleIterator.hasNext()?handleIterator.next():null;
      }

      Block catches= tryStmt.getCatchStatements();
      if (catches.getChildCount() == 0)
      {
        throw new ParseException("A try clause must have at least one (possibly default) catch clause", tryStmt);
      }
      cStmt= (CatchClause) catches.getChildAt(0);
      tryBlock.setEndIndex(cStmt.getBeginIndex() - 1);
      cStmt= (CatchClause) catches.getLastChild();
      if (cStmt.getEndIndex() == Integer.MIN_VALUE)
      {
        cStmt.setEndIndex(cStmt.getBeginIndex() + 1);
      }
      tryStmt.setEndIndex(cStmt.getEndIndex());

      if (hasFinally)
      {
        // Can't say yet where finally block is located.
      }
View Full Code Here

Examples of com.google.dart.engine.ast.CatchClause

    safelyVisit(node.getFinallyBlock());
    NodeList<CatchClause> catchClauses = node.getCatchClauses();
    int numOfCatchClauses = catchClauses.size();
    ArrayList<Type> visitedTypes = new ArrayList<Type>(numOfCatchClauses);
    for (int i = 0; i < numOfCatchClauses; i++) {
      CatchClause catchClause = catchClauses.get(i);
      if (catchClause.getOnKeyword() != null) {
        // on-catch clause found, verify that the exception type is not a subtype of a previous
        // on-catch exception type
        TypeName typeName = catchClause.getExceptionType();
        if (typeName != null && typeName.getType() != null) {
          Type currentType = typeName.getType();
          if (currentType.isObject()) {
            // Found catch clause clause that has Object as an exception type, this is equivalent to
            // having a catch clause that doesn't have an exception type, visit the block, but
            // generate an error on any following catch clauses (and don't visit them).
            safelyVisit(catchClause);
            if (i + 1 != numOfCatchClauses) {
              // this catch clause is not the last in the try statement
              CatchClause nextCatchClause = catchClauses.get(i + 1);
              CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
              int offset = nextCatchClause.getOffset();
              int length = lastCatchClause.getEnd() - offset;
              errorReporter.reportErrorForOffset(
                  HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
                  offset,
                  length);
              return null;
            }
          }
          for (Type type : visitedTypes) {
            if (currentType.isSubtypeOf(type)) {
              CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
              int offset = catchClause.getOffset();
              int length = lastCatchClause.getEnd() - offset;
              errorReporter.reportErrorForOffset(
                  HintCode.DEAD_CODE_ON_CATCH_SUBTYPE,
                  offset,
                  length,
                  currentType.getDisplayName(),
                  type.getDisplayName());
              return null;
            }
          }
          visitedTypes.add(currentType);
        }
        safelyVisit(catchClause);
      } else {
        // Found catch clause clause that doesn't have an exception type, visit the block, but
        // generate an error on any following catch clauses (and don't visit them).
        safelyVisit(catchClause);
        if (i + 1 != numOfCatchClauses) {
          // this catch clause is not the last in the try statement
          CatchClause nextCatchClause = catchClauses.get(i + 1);
          CatchClause lastCatchClause = catchClauses.get(numOfCatchClauses - 1);
          int offset = nextCatchClause.getOffset();
          int length = lastCatchClause.getEnd() - offset;
          errorReporter.reportErrorForOffset(
              HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH,
              offset,
              length);
          return null;
View Full Code Here

Examples of com.google.dart.engine.ast.CatchClause

   * @return {@code true} if the given type name is used as the exception type in a catch clause
   */
  private boolean isTypeNameInCatchClause(TypeName typeName) {
    AstNode parent = typeName.getParent();
    if (parent instanceof CatchClause) {
      CatchClause catchClause = (CatchClause) parent;
      return catchClause.getExceptionType() == typeName;
    }
    return false;
  }
View Full Code Here

Examples of dtool.ast.statements.CatchClause

      body = parse.checkResult(parseStatement_toMissing());
      if(parse.ruleBroken) break parsing;
     
      catches = new ArrayList<>();
      while(true) {
        CatchClause catchClause = parse.checkResult(parseCatchClause());
        if(catchClause == null) {
          break;
        }
        catches.add(catchClause);
        if(parse.ruleBroken) break parsing;
View Full Code Here

Examples of dtool.ast.statements.CatchClause

   
    if(parse.ruleBroken == false && catchParam == null && lookAhead() == DeeTokens.KW_CATCH) {
      parse.storeError(createError(ParserErrorTypes.LAST_CATCH, catchKeyword, null));
    }
   
    return parse.resultConclude(new CatchClause(catchParam, body));
  }
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.