Examples of TryCatchStatement


Examples of org.allspice.structured.statement.TryCatchStatement

public class TestTryCatch extends MyTestCase {
  public static interface TryFinally {
    public int meth(Exception arg0) ;
  }
  public void test1() throws Exception {
    TryFinally obj = makeObject(TryFinally.class,new TryCatchStatement(
        new FIFO<Statement>(new ThrowStatement(ARG0,null)),
        new FIFO<CatchBlock>(new CatchBlock(
            new VarDecl("java.lang.Exception","ex"),
            new FIFO<Statement>(
                new ReturnStatement(new ConstExpr(Integer.valueOf(1),null),null)
View Full Code Here

Examples of org.allspice.structured.statement.TryCatchStatement

  private static final VarExpr X = new VarExpr("x",null);
  public static interface MethTest {
    public int meth() ;
  }
  public void test0() throws Exception {
    MethTest obj = makeObject(MethTest.class,new TryCatchStatement(
            new FIFO<Statement>(new ReturnStatement(new ConstExpr(Integer.valueOf(0),null),null)),
            new FIFO<CatchBlock>(),
            new FIFO<Statement>(new ExprStatement(new ConstExpr(Integer.valueOf(5),null),null)),
            null
          ),
View Full Code Here

Examples of org.allspice.structured.statement.TryCatchStatement

    assertEquals(obj.meth(),0) ;
  }
  public void test1() throws Exception {
    MethTest obj = makeObject(MethTest.class,new DeclareStatement(
        new FIFO<VarDecl>(new VarDecl("int","x")),
        new FIFO<Statement>(new TryCatchStatement(
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new ConstExpr(Integer.valueOf(7),null),null),null)),
            new FIFO<CatchBlock>(),
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new PlusExpr(X,new ConstExpr(Integer.valueOf(1),null),null),null),null)),
            null
          ),
View Full Code Here

Examples of org.allspice.structured.statement.TryCatchStatement

  }
  public void test2() throws Exception {
    MethTest obj = makeObject(MethTest.class,new DeclareStatement(
        new FIFO<VarDecl>(new VarDecl("int","x")),
        new FIFO<Statement>(
          new TryCatchStatement(
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new ConstExpr(Integer.valueOf(7),null),null),null),new ReturnStatement(X,null)),
            new FIFO<CatchBlock>(),
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new PlusExpr(X,new ConstExpr(Integer.valueOf(1),null),null),null),null)),
            null
          ),
View Full Code Here

Examples of org.codehaus.groovy.ast.stmt.TryCatchStatement

        BlockStatement tryBlock = new BlockStatement();
        BlockStatement codeToHandleAllowedMethods = getCodeToHandleAllowedMethods(controllerClassNode, methodNode.getName());
        tryBlock.addStatement(codeToHandleAllowedMethods);
        tryBlock.addStatement(methodBody);

        final TryCatchStatement tryCatchStatement = new TryCatchStatement(tryBlock, new EmptyStatement());
        tryCatchStatement.addCatch(catchStatement);

        final ArgumentListExpression argumentListExpression = new ArgumentListExpression();
        argumentListExpression.addExpression(new ConstantExpression(ALLOWED_METHODS_HANDLED_ATTRIBUTE_NAME));
       
        final PropertyExpression requestPropertyExpression = new PropertyExpression(new VariableExpression("this"), "request");
        final Expression removeAttributeMethodCall = new MethodCallExpression(requestPropertyExpression, "removeAttribute", argumentListExpression);
       
        final Expression getAttributeMethodCall = new MethodCallExpression(requestPropertyExpression, "getAttribute", new ArgumentListExpression(new ConstantExpression(ALLOWED_METHODS_HANDLED_ATTRIBUTE_NAME)));
        final VariableExpression attributeValueExpression = new VariableExpression("$allowed_methods_attribute_value", ClassHelper.make(Object.class));
        final Expression initializeAttributeValue = new DeclarationExpression(
                attributeValueExpression, Token.newSymbol(Types.EQUALS, 0, 0), getAttributeMethodCall);
        final Expression attributeValueMatchesMethodNameExpression = new BinaryExpression(new ConstantExpression(methodNode.getName()),
                                                  Token.newSymbol(Types.COMPARE_EQUAL, 0, 0),
                                                  attributeValueExpression);
        final Statement ifAttributeValueMatchesMethodName =
                new IfStatement(new BooleanExpression(attributeValueMatchesMethodNameExpression),
                                new ExpressionStatement(removeAttributeMethodCall), new EmptyStatement());

        final BlockStatement blockToRemoveAttribute = new BlockStatement();
        blockToRemoveAttribute.addStatement(new ExpressionStatement(initializeAttributeValue));
        blockToRemoveAttribute.addStatement(ifAttributeValueMatchesMethodName);
       
        final TryCatchStatement tryCatchToRemoveAttribute = new TryCatchStatement(blockToRemoveAttribute, new EmptyStatement());
        tryCatchToRemoveAttribute.addCatch(new CatchStatement(new Parameter(ClassHelper.make(Exception.class), "$exceptionRemovingAttribute"), new EmptyStatement()));

        tryCatchStatement.setFinallyStatement(tryCatchToRemoveAttribute);

        methodNode.setCode(tryCatchStatement);
    }
View Full Code Here

Examples of org.codehaus.groovy.ast.stmt.TryCatchStatement

     * @param methodNode The method node
     */
    public static void wrapMethodBodyInTryCatchDebugStatements(MethodNode methodNode) {
        BlockStatement code = (BlockStatement) methodNode.getCode();
        BlockStatement newCode = new BlockStatement();
        TryCatchStatement tryCatchStatement = new TryCatchStatement(code, new BlockStatement());
        newCode.addStatement(tryCatchStatement);
        methodNode.setCode(newCode);
        BlockStatement catchBlock = new BlockStatement();
        ArgumentListExpression logArguments = new ArgumentListExpression();
        logArguments.addExpression(new BinaryExpression(new ConstantExpression("Error initializing class: "),Token.newSymbol(Types.PLUS, 0, 0),new VariableExpression("e")));
        logArguments.addExpression(new VariableExpression("e"));
        catchBlock.addStatement(new ExpressionStatement(new MethodCallExpression(new VariableExpression("log"), "error", logArguments)));
        tryCatchStatement.addCatch(new CatchStatement(new Parameter(new ClassNode(Throwable.class), "e"),catchBlock));
    }
View Full Code Here

Examples of org.codehaus.groovy.ast.stmt.TryCatchStatement

            Expression releaseLock = callX(lockType, "unlock");
            Statement originalCode = mNode.getCode();

            mNode.setCode(block(
                    stmt(acquireLock),
                    new TryCatchStatement(originalCode, stmt(releaseLock))));
        }
    }
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.