groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [2/3] groovy git commit: GROOVY-7737: Provide static methods in GeneralUtils to create ThrowStatement and CatchStatement - some additional throwS cases
Date Wed, 03 Feb 2016 05:32:47 GMT
GROOVY-7737: Provide static methods in GeneralUtils to create ThrowStatement and CatchStatement
- some additional throwS cases


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 667fae97f6eaeeccab9b95647c20b279308c2eca
Parents: 3c5542b
Author: paulk <paulk@asert.com.au>
Authored: Wed Feb 3 15:06:04 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Wed Feb 3 15:32:00 2016 +1000

----------------------------------------------------------------------
 .../AbstractInterruptibleASTTransformation.java | 41 ++++++++++++++------
 .../transform/ImmutableASTTransformation.java   |  3 +-
 .../transform/SingletonASTTransformation.java   |  6 +--
 .../TimedInterruptibleASTTransformation.groovy  |  4 +-
 .../TupleConstructorASTTransformation.java      |  5 +--
 .../NotYetImplementedASTTransformation.java     | 31 ++++++++++-----
 6 files changed, 58 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/667fae97/src/main/org/codehaus/groovy/transform/AbstractInterruptibleASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/AbstractInterruptibleASTTransformation.java
b/src/main/org/codehaus/groovy/transform/AbstractInterruptibleASTTransformation.java
index efb69be..f512975 100644
--- a/src/main/org/codehaus/groovy/transform/AbstractInterruptibleASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/AbstractInterruptibleASTTransformation.java
@@ -19,9 +19,25 @@
 package org.codehaus.groovy.transform;
 
 import org.codehaus.groovy.GroovyBugError;
-import org.codehaus.groovy.ast.*;
-import org.codehaus.groovy.ast.expr.*;
-import org.codehaus.groovy.ast.stmt.*;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.AnnotatedNode;
+import org.codehaus.groovy.ast.AnnotationNode;
+import org.codehaus.groovy.ast.ClassCodeVisitorSupport;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.FieldNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.ModuleNode;
+import org.codehaus.groovy.ast.expr.ClassExpression;
+import org.codehaus.groovy.ast.expr.ConstantExpression;
+import org.codehaus.groovy.ast.expr.DeclarationExpression;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.stmt.BlockStatement;
+import org.codehaus.groovy.ast.stmt.DoWhileStatement;
+import org.codehaus.groovy.ast.stmt.ForStatement;
+import org.codehaus.groovy.ast.stmt.LoopingStatement;
+import org.codehaus.groovy.ast.stmt.Statement;
+import org.codehaus.groovy.ast.stmt.WhileStatement;
 import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.runtime.DefaultGroovyMethods;
 import org.objectweb.asm.Opcodes;
@@ -29,6 +45,12 @@ import org.objectweb.asm.Opcodes;
 import java.util.Arrays;
 import java.util.List;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
+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.ifS;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
+
 /**
  * Base class for AST Transformations which will automatically throw an {@link InterruptedException}
when
  * some conditions are met.
@@ -163,15 +185,10 @@ public abstract class AbstractInterruptibleASTTransformation extends
ClassCodeVi
      * @return Returns the interruption check statement.
      */
     protected Statement createInterruptStatement() {
-        return new IfStatement(
-                new BooleanExpression(
-                        createCondition()
-                ),
-                new ThrowStatement(
-                        new ConstructorCallExpression(thrownExceptionType,
-                                new ArgumentListExpression(new ConstantExpression(getErrorMessage())))
-                ),
-                EmptyStatement.INSTANCE
+        return ifS(createCondition(),
+                throwS(
+                        ctorX(thrownExceptionType, args(constX(getErrorMessage())))
+                )
         );
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/667fae97/src/main/org/codehaus/groovy/transform/ImmutableASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/ImmutableASTTransformation.java b/src/main/org/codehaus/groovy/transform/ImmutableASTTransformation.java
index 9b0a9d7..7cfcf3e 100644
--- a/src/main/org/codehaus/groovy/transform/ImmutableASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/ImmutableASTTransformation.java
@@ -43,7 +43,6 @@ import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.EmptyStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
-import org.codehaus.groovy.ast.stmt.ThrowStatement;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.runtime.DefaultGroovyMethods;
@@ -364,7 +363,7 @@ public class ImmutableASTTransformation extends AbstractASTTransformation
{
         Expression value = findArg(name);
         return ifS(
                 notX(equalsNullX(value)),
-                new ThrowStatement(ctorX(READONLYEXCEPTION_TYPE,
+                throwS(ctorX(READONLYEXCEPTION_TYPE,
                         args(constX(name), constX(cNode.getName()))
                 )));
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/667fae97/src/main/org/codehaus/groovy/transform/SingletonASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/SingletonASTTransformation.java b/src/main/org/codehaus/groovy/transform/SingletonASTTransformation.java
index e51bc87..ce20ddc 100644
--- a/src/main/org/codehaus/groovy/transform/SingletonASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/SingletonASTTransformation.java
@@ -29,7 +29,6 @@ import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
 import org.codehaus.groovy.ast.stmt.SynchronizedStatement;
-import org.codehaus.groovy.ast.stmt.ThrowStatement;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 
@@ -45,6 +44,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.ifElseS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.notNullX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
 import static org.codehaus.groovy.ast.tools.GenericsUtils.newClass;
 
@@ -116,7 +116,7 @@ public class SingletonASTTransformation extends AbstractASTTransformation
{
             }
         }
 
-        if (isStrict && !cNodes.isEmpty()) {
+        if (isStrict && !cNodes.isEmpty()) {
             for (ConstructorNode cNode : cNodes) {
                 addError("@Singleton didn't expect to find one or more additional constructors:
remove constructor(s) or set strict=false", cNode);
             }
@@ -126,7 +126,7 @@ public class SingletonASTTransformation extends AbstractASTTransformation
{
             final BlockStatement body = new BlockStatement();
             body.addStatement(ifS(
                     notNullX(varX(field)),
-                    new ThrowStatement(
+                    throwS(
                             ctorX(make(RuntimeException.class),
                                     args(constX("Can't instantiate singleton " + classNode.getName()
+ ". Use " + classNode.getName() + "." + propertyName))))
             ));

http://git-wip-us.apache.org/repos/asf/groovy/blob/667fae97/src/main/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
b/src/main/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
index 0481685..6ad4898 100644
--- a/src/main/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
+++ b/src/main/org/codehaus/groovy/transform/TimedInterruptibleASTTransformation.groovy
@@ -35,7 +35,6 @@ import org.codehaus.groovy.ast.expr.Expression
 import org.codehaus.groovy.ast.stmt.BlockStatement
 import org.codehaus.groovy.ast.stmt.DoWhileStatement
 import org.codehaus.groovy.ast.stmt.ForStatement
-import org.codehaus.groovy.ast.stmt.ThrowStatement
 import org.codehaus.groovy.ast.stmt.WhileStatement
 import org.codehaus.groovy.control.CompilePhase
 import org.codehaus.groovy.control.SourceUnit
@@ -53,6 +52,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS
 import static org.codehaus.groovy.ast.tools.GeneralUtils.ltX
 import static org.codehaus.groovy.ast.tools.GeneralUtils.plusX
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX
+import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS
 import static org.codehaus.groovy.ast.tools.GeneralUtils.varX
 
 /**
@@ -183,7 +183,7 @@ public class TimedInterruptibleASTTransformation extends AbstractASTTransformati
                             propX(varX("this"), basename + '$expireTime'),
                             callX(make(System), 'nanoTime')
                     ),
-                    new ThrowStatement(
+                    throwS(
                             ctorX(thrown,
                                     args(
                                             plusX(

http://git-wip-us.apache.org/repos/asf/groovy/blob/667fae97/src/main/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
b/src/main/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index e88d4ad..f9c89a0 100644
--- a/src/main/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ b/src/main/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -33,7 +33,6 @@ import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
-import org.codehaus.groovy.ast.stmt.ThrowStatement;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 
@@ -61,6 +60,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.ifS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.params;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
 
 /**
@@ -225,8 +225,7 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
     }
 
     private static BlockStatement illegalArgumentBlock(String message) {
-        return block(
-                new ThrowStatement(ctorX(make(IllegalArgumentException.class), args(constX(message)))));
+        return block(throwS(ctorX(make(IllegalArgumentException.class), args(constX(message)))));
     }
 
     private static BlockStatement processArgsBlock(ClassNode cNode, VariableExpression namedArgs)
{

http://git-wip-us.apache.org/repos/asf/groovy/blob/667fae97/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 2a8affe..21461d1 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
@@ -18,17 +18,30 @@
  */
 package org.codehaus.groovy.transform;
 
-import org.codehaus.groovy.ast.*;
-import org.codehaus.groovy.ast.expr.ArgumentListExpression;
-import org.codehaus.groovy.ast.expr.ConstantExpression;
-import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
-import org.codehaus.groovy.ast.stmt.*;
+import org.codehaus.groovy.ast.ASTNode;
+import org.codehaus.groovy.ast.AnnotatedNode;
+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;
+import org.codehaus.groovy.ast.stmt.TryCatchStatement;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 
 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.constX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.throwS;
+
 /**
  * Handles generation of code for the {@code @NotYetImplemented} annotation.
  * 
@@ -83,11 +96,9 @@ public class NotYetImplementedASTTransformation extends AbstractASTTransformatio
     }
 
     private Statement throwAssertionFailedError(AnnotationNode annotationNode) {
-        ThrowStatement throwStatement = new ThrowStatement(
-                new ConstructorCallExpression(ASSERTION_FAILED_ERROR_TYPE,
-                        new ArgumentListExpression(
-                                new ConstantExpression("Method is marked with @NotYetImplemented
but passes unexpectedly"))));
-
+        Statement throwStatement = throwS(
+                ctorX(ASSERTION_FAILED_ERROR_TYPE,
+                        args(constX("Method is marked with @NotYetImplemented but passes
unexpectedly"))));
         throwStatement.setSourcePosition(annotationNode);
 
         return throwStatement;


Mime
View raw message