GROOVY-7737: Provide static methods in GeneralUtils to create ThrowStatement 
and CatchStatement - some additional catchS cases


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c4697438
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c4697438
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c4697438

Branch: refs/heads/GROOVY_2_4_X
Commit: c4697438283db72def16c53dc34671f53b507288
Parents: 667fae9
Author: paulk <pa...@asert.com.au>
Authored: Wed Feb 3 15:12:07 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Wed Feb 3 15:32:17 2016 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java |  7 +++++++
 .../transform/NotYetImplementedASTTransformation.java    | 11 +++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/c4697438/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java 
b/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
index e73c0e3..9f63d16 100644
--- a/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -133,6 +133,13 @@ public class GeneralUtils {
         return block;
     }
 
+    public static BlockStatement block(VariableScope varScope, List<Statement> 
stmts) {
+        BlockStatement block = new BlockStatement();
+        block.setVariableScope(varScope);
+        for (Statement stmt : stmts) block.addStatement(stmt);
+        return block;
+    }
+
     public static BlockStatement block(Statement... stmts) {
         BlockStatement block = new BlockStatement();
         for (Statement stmt : stmts) block.addStatement(stmt);

http://git-wip-us.apache.org/repos/asf/groovy/blob/c4697438/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
----------------------------------------------------------------------
diff --git 
a/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
 
b/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
index 21461d1..5824814 100644
--- 
a/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
+++ 
b/subprojects/groovy-test/src/main/java/org/codehaus/groovy/transform/NotYetImplementedASTTransformation.java
@@ -24,9 +24,7 @@ import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.MethodNode;
-import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
-import org.codehaus.groovy.ast.stmt.CatchStatement;
 import org.codehaus.groovy.ast.stmt.EmptyStatement;
 import org.codehaus.groovy.ast.stmt.ReturnStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
@@ -38,8 +36,11 @@ import java.util.ArrayList;
 import java.util.Arrays;
 
 import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.catchS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.constX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
 
 /**
@@ -90,8 +91,10 @@ public class NotYetImplementedASTTransformation extends 
AbstractASTTransformatio
     }
 
     private TryCatchStatement tryCatchAssertionFailedError(AnnotationNode 
annotationNode, MethodNode methodNode, ArrayList<Statement> statements) {
-        TryCatchStatement tryCatchStatement = new TryCatchStatement(new 
BlockStatement(statements, methodNode.getVariableScope()), 
EmptyStatement.INSTANCE);
-        tryCatchStatement.addCatch(new CatchStatement(new 
Parameter(CATCHED_THROWABLE_TYPE, "ex"), ReturnStatement.RETURN_NULL_OR_VOID));
+        TryCatchStatement tryCatchStatement = new TryCatchStatement(
+                block(methodNode.getVariableScope(), statements),
+                EmptyStatement.INSTANCE);
+        tryCatchStatement.addCatch(catchS(param(CATCHED_THROWABLE_TYPE, "ex"), 
ReturnStatement.RETURN_NULL_OR_VOID));
         return tryCatchStatement;
     }
 

Reply via email to