groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Revert immutable empty expression and statement changes further
Date Sat, 24 Jun 2017 11:12:33 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 3ce5e79af -> 89b5b072a


Revert immutable empty expression and statement changes further


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

Branch: refs/heads/master
Commit: 89b5b072a9947bb55292c1d2010d1c67e57d68c9
Parents: 3ce5e79
Author: sunlan <sunlan@apache.org>
Authored: Sat Jun 24 19:12:24 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Sat Jun 24 19:12:24 2017 +0800

----------------------------------------------------------------------
 .../groovy/ast/expr/EmptyExpression.java        | 95 +-------------------
 .../groovy/ast/stmt/EmptyStatement.java         | 72 +--------------
 .../groovy/ast/CodeVisitorSupportTest.groovy    |  4 +-
 .../groovy/ast/builder/AstAssert.groovy         | 25 +-----
 4 files changed, 8 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/89b5b072/src/main/org/codehaus/groovy/ast/expr/EmptyExpression.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/expr/EmptyExpression.java b/src/main/org/codehaus/groovy/ast/expr/EmptyExpression.java
index b673b25..ae957a6 100644
--- a/src/main/org/codehaus/groovy/ast/expr/EmptyExpression.java
+++ b/src/main/org/codehaus/groovy/ast/expr/EmptyExpression.java
@@ -18,14 +18,7 @@
  */
 package org.codehaus.groovy.ast.expr;
 
-import org.codehaus.groovy.ast.ASTNode;
-import org.codehaus.groovy.ast.AnnotationNode;
-import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.GroovyCodeVisitor;
-import org.codehaus.groovy.ast.NodeMetaDataHandler;
-
-import java.util.List;
-import java.util.Map;
 
 /**
  * This class is a place holder for an empty expression. 
@@ -38,7 +31,7 @@ import java.util.Map;
  */
 
 public class EmptyExpression extends Expression {
-    public static final EmptyExpression INSTANCE = new ImmutableEmptyExpression() ;
+    public static final EmptyExpression INSTANCE = new EmptyExpression();
 
     public Expression transformExpression(ExpressionTransformer transformer) {
         return this;
@@ -47,90 +40,4 @@ public class EmptyExpression extends Expression {
     public void visit(GroovyCodeVisitor visitor) {
         return;
     }
-
-    private static class ImmutableEmptyExpression extends EmptyExpression {
-        @Override
-        public void setType(ClassNode t) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void addAnnotation(AnnotationNode value) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void addAnnotations(List<AnnotationNode> annotations) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setSynthetic(boolean synthetic) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setDeclaringClass(ClassNode declaringClass) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setHasNoRealSourcePosition(boolean value) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setLineNumber(int lineNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setColumnNumber(int columnNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setLastLineNumber(int lastLineNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setLastColumnNumber(int lastColumnNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setSourcePosition(ASTNode node) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void copyNodeMetaData(NodeMetaDataHandler other) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setNodeMetaData(Object key, Object value) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public Object putNodeMetaData(Object key, Object value) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void removeNodeMetaData(Object key) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setMetaDataMap(Map<?, ?> metaDataMap) {
-            throw createUnsupportedOperationException();
-        }
-
-        private UnsupportedOperationException createUnsupportedOperationException() {
-            return new UnsupportedOperationException("EmptyExpression.INSTANCE is immutable");
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/89b5b072/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java b/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java
index 82ebff4..6f44b1f 100644
--- a/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java
+++ b/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java
@@ -18,11 +18,7 @@
  */
 package org.codehaus.groovy.ast.stmt;
 
-import org.codehaus.groovy.ast.ASTNode;
 import org.codehaus.groovy.ast.GroovyCodeVisitor;
-import org.codehaus.groovy.ast.NodeMetaDataHandler;
-
-import java.util.Map;
 
 /**
  * Represents an empty statement
@@ -31,7 +27,7 @@ import java.util.Map;
  */
 
 public class EmptyStatement extends Statement {
-    public static final EmptyStatement INSTANCE = new ImmutableEmptyStatement();
+    public static final EmptyStatement INSTANCE = new EmptyStatement();
     
     public void visit(GroovyCodeVisitor visitor) {
     }
@@ -39,70 +35,4 @@ public class EmptyStatement extends Statement {
     public boolean isEmpty() {
         return true;
     }
-
-    private static class ImmutableEmptyStatement extends EmptyStatement {
-        @Override
-        public void setStatementLabel(String label) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void addStatementLabel(String label) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setLineNumber(int lineNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setColumnNumber(int columnNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setLastLineNumber(int lastLineNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setLastColumnNumber(int lastColumnNumber) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setSourcePosition(ASTNode node) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void copyNodeMetaData(NodeMetaDataHandler other) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setNodeMetaData(Object key, Object value) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public Object putNodeMetaData(Object key, Object value) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void removeNodeMetaData(Object key) {
-            throw createUnsupportedOperationException();
-        }
-
-        @Override
-        public void setMetaDataMap(Map<?, ?> metaDataMap) {
-            throw createUnsupportedOperationException();
-        }
-
-        private UnsupportedOperationException createUnsupportedOperationException() {
-            return new UnsupportedOperationException("EmptyStatement.INSTANCE is immutable");
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/89b5b072/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy b/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
index cef9ee9..6d8e973 100644
--- a/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/CodeVisitorSupportTest.groovy
@@ -56,7 +56,7 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
         assert visitor.history[1] == IfStatement
         assert visitor.history[2] == BooleanExpression
         assert visitor.history[3] == BlockStatement
-        assert visitor.history[4] instanceof EmptyStatement
+        assert visitor.history[4] == EmptyStatement
         assert visitor.history.size == 5
     }
 
@@ -98,7 +98,7 @@ public class CodeVisitorSupportTest extends GroovyTestCase {
         assert visitor.history[2] == BlockStatement
         assert visitor.history[3] == CatchStatement
         assert visitor.history[4] == BlockStatement
-        assert visitor.history[5] instanceof EmptyStatement
+        assert visitor.history[5] == EmptyStatement
     }
 }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/89b5b072/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy b/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
index 055d05b..3fc0611 100644
--- a/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
+++ b/src/test/org/codehaus/groovy/ast/builder/AstAssert.groovy
@@ -20,8 +20,6 @@ package org.codehaus.groovy.ast.builder
 
 import org.codehaus.groovy.ast.ASTNode
 import org.codehaus.groovy.ast.ClassNode
-import org.codehaus.groovy.ast.expr.EmptyExpression
-import org.codehaus.groovy.ast.stmt.EmptyStatement
 import org.junit.Assert
 import org.codehaus.groovy.ast.stmt.BlockStatement
 import org.codehaus.groovy.ast.stmt.ExpressionStatement
@@ -224,14 +222,9 @@ class AstAssert {
                 assertSyntaxTree([expected.expression], [actual.expression])
                 assertSyntaxTree([expected.code], [actual.code])
             },
-
             EmptyStatement : { expected, actual ->
                 // always successful
             },
-            ImmutableEmptyStatement : { expected, actual ->
-                // always successful
-            },
-
             BreakStatement : { expected, actual ->
                 Assert.assertEquals("Wrong label", expected.label, actual.label)
             },
@@ -382,25 +375,15 @@ class AstAssert {
         if (actual == null || expected == null || expected.size() != actual?.size()) {
             Assert.fail("AST comparison failure. \nExpected $expected \nReceived $actual")
         }
-
         expected.eachWithIndex { item, index ->
-            def actualNode = actual[index]
-
-            if (item.getClass().isArray() && actualNode.getClass().isArray()) {
-                assertSyntaxTree(item, actualNode)
+            if (item.getClass().isArray() && actual[index].getClass().isArray())
{
+                assertSyntaxTree(item, actual[index])
             } else {
-                try {
-                    Assert.assertEquals("Wrong type in AST Node", item.getClass(), actualNode.getClass())
-                } catch (AssertionError e) {
-                    if (!(item instanceof EmptyStatement && actualNode instanceof
EmptyStatement)
-                        || !(item instanceof EmptyExpression && actualNode instanceof
EmptyExpression)) {
-                        throw e;
-                    }
-                }
+                Assert.assertEquals("Wrong type in AST Node", item.getClass(), actual[index].getClass())
 
                 if (ASSERTION_MAP.containsKey(item.getClass().getSimpleName())) {
                     Closure assertion = ASSERTION_MAP.get(item.getClass().getSimpleName())
-                    assertion(item, actualNode)
+                    assertion(item, actual[index])
                 } else {
                     Assert.fail("Unexpected type: ${item.getClass()} Update the unit test!")
                 }


Mime
View raw message