groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [5/5] groovy git commit: Make EmptyStatement.INSTANCE immutable
Date Sat, 24 Jun 2017 08:41:44 GMT
Make EmptyStatement.INSTANCE immutable

(cherry picked from commit 014273f)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 59c261fb977716be8ca0cb68bfd49ee5d21af282
Parents: 60be70a
Author: sunlan <sunlan@apache.org>
Authored: Sat Jun 24 16:27:27 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Sat Jun 24 16:41:13 2017 +0800

----------------------------------------------------------------------
 .../groovy/ast/stmt/EmptyStatement.java         | 70 +++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/59c261fb/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 3b9800d..740cb55 100644
--- a/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java
+++ b/src/main/org/codehaus/groovy/ast/stmt/EmptyStatement.java
@@ -18,7 +18,11 @@
  */
 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
@@ -27,7 +31,71 @@ import org.codehaus.groovy.ast.GroovyCodeVisitor;
  */
 public class EmptyStatement extends Statement {
 
-    public static final EmptyStatement INSTANCE = new EmptyStatement();
+    public static final EmptyStatement INSTANCE = new 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");
+        }
+    };
     
     public void visit(GroovyCodeVisitor visitor) {
     }


Mime
View raw message