Package com.google.gwt.dev.jjs.ast

Examples of com.google.gwt.dev.jjs.ast.JBlock


      lparen();
      JLocalRef localRef = x.getCatchArgs().get(i);
      accept(localRef.getTarget());
      rparen();
      space();
      JBlock block = x.getCatchBlocks().get(i);
      accept(block);
    }
    if (x.getFinallyBlock() != null) {
      print(CHARS_FINALLY);
      accept(x.getFinallyBlock());
View Full Code Here


        return;
      }

      SourceInfo catchInfo = x.getCatchBlocks().get(0).getSourceInfo();
      JLocal exVar = popTempLocal();
      JBlock newCatchBlock = new JBlock(catchInfo);

      {
        // $e = Exceptions.caught($e)
        JMethod caughtMethod = program.getIndexedMethod("Exceptions.caught");
        JMethodCall call = new JMethodCall(catchInfo, null, caughtMethod);
        call.addArg(new JLocalRef(catchInfo, exVar));
        newCatchBlock.addStmt(program.createAssignmentStmt(catchInfo,
            new JLocalRef(catchInfo, exVar), call));
      }

      /*
       * Build up a series of if, else if statements to test the type of the
       * exception object against the type of the user's catch block.
       *
       * Go backwards so we can nest the else statements in the correct order!
       */
      // rethrow the current exception if no one caught it
      JStatement cur = new JThrowStatement(catchInfo, new JLocalRef(catchInfo,
          exVar));
      for (int i = x.getCatchBlocks().size() - 1; i >= 0; --i) {
        JBlock block = x.getCatchBlocks().get(i);
        JLocalRef arg = x.getCatchArgs().get(i);
        catchInfo = block.getSourceInfo();
        JReferenceType argType = (JReferenceType) arg.getType();
        // if ($e instanceof ArgType) { var userVar = $e; <user code> }
        JExpression ifTest = new JInstanceOf(catchInfo, argType, new JLocalRef(
            catchInfo, exVar));
        JDeclarationStatement declaration = new JDeclarationStatement(
            catchInfo, arg, new JLocalRef(catchInfo, exVar));
        if (!block.getStatements().isEmpty()) {
          // Only bother adding the assignment if the block is non-empty
          block.addStmt(0, declaration);
        }
        // nest the previous as an else for me
        cur = new JIfStatement(catchInfo, ifTest, block, cur);
      }

View Full Code Here

    private void removeMe(JStatement stmt, Context ctx) {
      if (ctx.canRemove()) {
        ctx.removeMe();
      } else {
        // empty block statement
        ctx.replaceMe(new JBlock(stmt.getSourceInfo()));
      }
    }
View Full Code Here

      List catchArgs = x.getCatchArgs();
      List catchBlocks = x.getCatchBlocks();
      for (int i = 0, c = catchArgs.size(); i < c; ++i) {
        JLocalRef arg = (JLocalRef) catchArgs.get(i);
        JBlock catchBlock = (JBlock) catchBlocks.get(i);
        JsCatch jsCatch = new JsCatch(peek(), arg.getTarget().getName());
        JsParameter jsParam = jsCatch.getParameter();
        names.put(arg.getTarget(), jsParam.getName());
        catchMap.put(catchBlock, jsCatch);
View Full Code Here

      lparen();
      JLocalRef localRef = (JLocalRef) x.getCatchArgs().get(i);
      accept(localRef.getTarget());
      rparen();
      space();
      JBlock block = (JBlock) x.getCatchBlocks().get(i);
      accept(block);
    }
    if (x.getFinallyBlock() != null) {
      print(CHARS_FINALLY);
      accept(x.getFinallyBlock());
View Full Code Here

      SourceInfo catchInfo = ((JBlock) x.getCatchBlocks().get(0)).getSourceInfo();

      JLocal exObj = popTempLocal();
      JLocalRef exRef = new JLocalRef(program, catchInfo, exObj);
      JBlock newCatchBlock = new JBlock(program, catchInfo);
      // $e = Exceptions.caught($e)
      JMethod caughtMethod = program.getSpecialMethod("Exceptions.caught");
      JMethodCall call = new JMethodCall(program, catchInfo, null, caughtMethod);
      call.getArgs().add(exRef);
      JExpressionStatement asg = program.createAssignmentStmt(catchInfo, exRef,
          call);
      newCatchBlock.statements.add(asg);

      /*
       * Build up a series of if, else if statements to test the type of the
       * exception object against the type of the user's catch block.
       *
       * Go backwards so we can nest the else statements in the correct order!
       */
      // rethrow the current exception if no one caught it
      JStatement cur = new JThrowStatement(program, null, exRef);
      for (int i = x.getCatchBlocks().size() - 1; i >= 0; --i) {
        JBlock block = (JBlock) x.getCatchBlocks().get(i);
        JLocalRef arg = (JLocalRef) x.getCatchArgs().get(i);
        catchInfo = block.getSourceInfo();
        JReferenceType argType = (JReferenceType) arg.getType();
        // if ($e instanceof Argtype) { userVar = $e; <user code> }
        JExpression ifTest = new JInstanceOf(program, catchInfo, argType, exRef);
        asg = program.createAssignmentStmt(catchInfo, arg, exRef);
        if (!block.statements.isEmpty()) {
View Full Code Here

      return new JThrowStatement(program, info, toThrow);
    }

    JStatement processStatement(TryStatement x) {
      SourceInfo info = makeSourceInfo(x);
      JBlock tryBlock = (JBlock) dispProcessStatement(x.tryBlock);
      List/* <JLocalRef> */catchArgs = new ArrayList/* <JLocalRef> */();
      List/* <JBlock> */catchBlocks = new ArrayList/* <JBlock> */();
      if (x.catchBlocks != null) {
        for (int i = 0, c = x.catchArguments.length; i < c; ++i) {
          JLocal local = (JLocal) typeMap.get(x.catchArguments[i].binding);
          catchArgs.add(createVariableRef(info, local));
        }
        for (int i = 0, c = x.catchBlocks.length; i < c; ++i) {
          catchBlocks.add(dispProcessStatement(x.catchBlocks[i]));
        }
      }
      JBlock finallyBlock = (JBlock) dispProcessStatement(x.finallyBlock);
      return new JTryStatement(program, info, tryBlock, catchArgs, catchBlocks,
          finallyBlock);
    }
View Full Code Here

        throw translateException(field, e);
      }
    }

    void processInitializer(Initializer initializer) {
      JBlock block = (JBlock) dispProcessStatement(initializer.block);
      try {
        // will either be init or clinit
        currentMethod.body.statements.add(block);
      } catch (Throwable e) {
        throw translateException(initializer, e);
View Full Code Here

      if (x == null) {
        return null;
      }

      SourceInfo info = makeSourceInfo(x);
      JBlock block = new JBlock(program, info);
      if (x.statements != null) {
        for (int i = 0, n = x.statements.length; i < n; ++i) {
          JStatement jstmt = dispProcessStatement(x.statements[i]);
          if (jstmt != null) {
            block.statements.add(jstmt);
View Full Code Here

    }

    JStatement processStatement(SwitchStatement x) {
      SourceInfo info = makeSourceInfo(x);
      JExpression expression = dispProcessExpression(x.expression);
      JBlock block = new JBlock(program, info);
      block.statements = processStatements(x.statements);
      return new JSwitchStatement(program, info, expression, block);
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JBlock

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.