Package asteroid.statements
Class TryCatchStatementBuilder
- java.lang.Object
-
- asteroid.statements.TryCatchStatementBuilder
-
public class TryCatchStatementBuilder extends Object
This builder tries to make it easier to build a try/catch statement.
AST
ResultTryCatchStatement stmt = A.STMT.tryCatchSBuilder() .tryStmt(protectedStmt) .addCatchStmt(Exception, 'ex', handlerOneStmt) .addCatchStmt(IllegalStatementException, 'ix', handlerTwoStmt) // ... add as many catch as you need .finallyStmt(finallyStatement) .build()try { // protectedStmt } catch(Exception ex) { // handlerOneStmt } catch(IllegalStateException ix) { // handlerTwoStmt } finally { // finallyStatement }- Since:
- 0.2.3
-
-
Constructor Summary
Constructors Constructor Description TryCatchStatementBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TryCatchStatementBuilderaddCatchStmt(Class exceptionType, String exceptionVarName, Statement stmt)Adds one catch statement to catch a specific exception giving a specific name for the exception variable.TryCatchStatementBuilderaddCatchStmt(ClassNode exceptionType, String exceptionVarName, Statement stmt)Adds one catch statement to catch a specific exception giving a specific name for the exception variable.TryCatchStatementbuild()Returns the createdTryCatchStatementinstance.TryCatchStatementBuilderfinallyStmt(Statement stmt)Adds the statement that will be placed inside the finally blockTryCatchStatementBuildertryStmt(Statement stmt)Adds the try statement
-
-
-
Method Detail
-
tryStmt
public TryCatchStatementBuilder tryStmt(Statement stmt)
Adds the try statement- Parameters:
stmt- the code you want to protect- Returns:
- the current builder instance
- Since:
- 0.2.3
-
addCatchStmt
public TryCatchStatementBuilder addCatchStmt(Class exceptionType, String exceptionVarName, Statement stmt)
Adds one catch statement to catch a specific exception giving a specific name for the exception variable. IMPORTANT: This method usesClassto specify the class of theException. Don't use it if you are targetting a very early compilation stage. If so use the method usingClassNode- Parameters:
exceptionType- theClassof the exception you want to catchexceptionVarName- the name of the exception variablestmt- the code handling the exception- Returns:
- the current builder instance
- Since:
- 0.2.3
-
addCatchStmt
public TryCatchStatementBuilder addCatchStmt(ClassNode exceptionType, String exceptionVarName, Statement stmt)
Adds one catch statement to catch a specific exception giving a specific name for the exception variable.- Parameters:
exceptionType- theClassNodeof the exception you want to catchexceptionVarName- the name of the exception variablestmt- the code handling the exception- Returns:
- the current builder instance
- Since:
- 0.2.3
-
finallyStmt
public TryCatchStatementBuilder finallyStmt(Statement stmt)
Adds the statement that will be placed inside the finally block- Parameters:
stmt- the code executed in the finally block- Returns:
- the current builder instance
- Since:
- 0.2.3
-
build
public TryCatchStatement build()
Returns the createdTryCatchStatementinstance. At least the "try" statement and the "finally" statement must be provided. Otherwise it will throw aIllegalStateException- Returns:
- a
TryCatchStatementinstance - Throws:
IllegalStateException- if neither try nor finally statements are provided- Since:
- 0.2.3
-
-