// Path: asteroid-core/src/main/java/asteroid/A.java
// @SuppressWarnings("PMD.ShortClassName")
// public final class A {
// 
//     /**
//      * Entry point to get node builders.
//      *
//      * @since 0.1.0
//      */
//     public static final Nodes NODES = new Nodes();
// 
//     /**
//      * Entry point to access language modifiers
//      *
//      * @since 0.1.0
//      */
//     public static final Modifiers ACC = new Modifiers();
// 
//     /**
//      * Entry point to create statements.
//      *
//      * @since 0.1.0
//      */
//     public static final Statements STMT = new Statements();
// 
//     /**
//      * Entry point to create expressions
//      *
//      * @since 0.1.0
//      */
//     public static final Expressions EXPR = new Expressions();
// 
//     /**
//      * Entry point to get util functions
//      *
//      * @since 0.1.0
//      */
//     public static final Utils UTIL = new Utils();
// 
//     /**
//      * Entry point to get criterias
//      *
//      * @since 0.2.4
//      */
//     public static final Criterias CRITERIA = new Criterias();
// }


import asteroid.A;
import java.util.List;
import java.util.ArrayList;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.ast.stmt.CatchStatement;
import org.codehaus.groovy.ast.stmt.TryCatchStatement;
package asteroid.statements;



/**
 * This builder tries to make it easier to build a try/catch
 * statement.<br/><br/>
 *
 * <strong>AST</strong>
 * <pre><code>TryCatchStatement stmt = A.STMT.tryCatchSBuilder()
 *        .tryStmt(protectedStmt)
 *        .addCatchStmt(Exception, 'ex', handlerOneStmt)
 *        .addCatchStmt(IllegalStatementException, 'ix', handlerTwoStmt)
 *        // ... add as many catch as you need
 *        .finallyStmt(finallyStatement)
 *        .build()</code></pre>
 *
 * <strong>Result</strong>
 * <pre><code>try {
 *    // protectedStmt
 *   } catch(Exception ex) {
 *    // handlerOneStmt
 *   } catch(IllegalStateException ix) {
 *    // handlerTwoStmt
 *   } finally {
 *    // finallyStatement
 *   }</code></pre>
 *
 *
 * @since 0.2.3
 */
public class TryCatchStatementBuilder {

    private final List<CatchStatement> catchStatements = new ArrayList<>();

    private Statement tryStatement;
    private Statement finallyStatement;

    /**
     * Adds the try statement
     *
     * @param stmt the code you want to protect
     * @return the current builder instance
     * @since 0.2.3
     */
    public TryCatchStatementBuilder tryStmt(final Statement stmt) {
        tryStatement = stmt;
        return this;
    }

    /**
     * Adds one catch statement to catch a specific exception giving a
     * specific name for the exception variable.
     *
     * </br></br><b>IMPORTANT: </b>
     * This method uses {@link Class} to specify the class of the {@link Exception}. Don't
     * use it if you are targetting a very early compilation stage. If so use the method
     * using {@link ClassNode}
     *
     * @param exceptionType the {@link Class} of the exception you want to catch
     * @param exceptionVarName the name of the exception variable
     * @param stmt the code handling the exception
     * @return the current builder instance
     * @since 0.2.3
     */
    public TryCatchStatementBuilder addCatchStmt(final Class exceptionType, final String exceptionVarName, final Statement stmt) {
// Path: asteroid-core/src/main/java/asteroid/A.java
// @SuppressWarnings("PMD.ShortClassName")
// public final class A {
// 
//     /**
//      * Entry point to get node builders.
//      *
//      * @since 0.1.0
//      */
//     public static final Nodes NODES = new Nodes();
// 
//     /**
//      * Entry point to access language modifiers
//      *
//      * @since 0.1.0
//      */
//     public static final Modifiers ACC = new Modifiers();
// 
//     /**
//      * Entry point to create statements.
//      *
//      * @since 0.1.0
//      */
//     public static final Statements STMT = new Statements();
// 
//     /**
//      * Entry point to create expressions
//      *
//      * @since 0.1.0
//      */
//     public static final Expressions EXPR = new Expressions();
// 
//     /**
//      * Entry point to get util functions
//      *
//      * @since 0.1.0
//      */
//     public static final Utils UTIL = new Utils();
// 
//     /**
//      * Entry point to get criterias
//      *
//      * @since 0.2.4
//      */
//     public static final Criterias CRITERIA = new Criterias();
// }


// Path: asteroid-core/src/main/java/asteroid/statements/TryCatchStatementBuilder.java
import asteroid.A;
import java.util.List;
import java.util.ArrayList;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.ast.stmt.CatchStatement;
import org.codehaus.groovy.ast.stmt.TryCatchStatement;

package asteroid.statements;



/**
 * This builder tries to make it easier to build a try/catch
 * statement.<br/><br/>
 *
 * <strong>AST</strong>
 * <pre><code>TryCatchStatement stmt = A.STMT.tryCatchSBuilder()
 *        .tryStmt(protectedStmt)
 *        .addCatchStmt(Exception, 'ex', handlerOneStmt)
 *        .addCatchStmt(IllegalStatementException, 'ix', handlerTwoStmt)
 *        // ... add as many catch as you need
 *        .finallyStmt(finallyStatement)
 *        .build()</code></pre>
 *
 * <strong>Result</strong>
 * <pre><code>try {
 *    // protectedStmt
 *   } catch(Exception ex) {
 *    // handlerOneStmt
 *   } catch(IllegalStateException ix) {
 *    // handlerTwoStmt
 *   } finally {
 *    // finallyStatement
 *   }</code></pre>
 *
 *
 * @since 0.2.3
 */
public class TryCatchStatementBuilder {

    private final List<CatchStatement> catchStatements = new ArrayList<>();

    private Statement tryStatement;
    private Statement finallyStatement;

    /**
     * Adds the try statement
     *
     * @param stmt the code you want to protect
     * @return the current builder instance
     * @since 0.2.3
     */
    public TryCatchStatementBuilder tryStmt(final Statement stmt) {
        tryStatement = stmt;
        return this;
    }

    /**
     * Adds one catch statement to catch a specific exception giving a
     * specific name for the exception variable.
     *
     * </br></br><b>IMPORTANT: </b>
     * This method uses {@link Class} to specify the class of the {@link Exception}. Don't
     * use it if you are targetting a very early compilation stage. If so use the method
     * using {@link ClassNode}
     *
     * @param exceptionType the {@link Class} of the exception you want to catch
     * @param exceptionVarName the name of the exception variable
     * @param stmt the code handling the exception
     * @return the current builder instance
     * @since 0.2.3
     */
    public TryCatchStatementBuilder addCatchStmt(final Class exceptionType, final String exceptionVarName, final Statement stmt) {
        return this.addCatchStmt(A.NODES.clazz(exceptionType).build(), exceptionVarName, stmt);