groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: port f227b26 for JDK7
Date Tue, 13 Jun 2017 10:31:47 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 6c5258bf1 -> 9df1bb767


port f227b26 for JDK7


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 9df1bb767519229e23ad493a51e0d24d71ac9f7f
Parents: 6c5258b
Author: paulk <paulk@asert.com.au>
Authored: Tue Jun 13 20:31:22 2017 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Tue Jun 13 20:31:22 2017 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/ASTNode.java   |  31 +++++
 .../groovy/ast/NodeMetaDataHandler.java         |  67 +--------
 .../groovy/ast/NodeMetaDataHandlerHelper.java   | 138 +++++++++++++++++++
 .../apache/groovy/parser/antlr4/GroovyParser.g4 |  40 ++++++
 4 files changed, 215 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9df1bb76/src/main/org/codehaus/groovy/ast/ASTNode.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ASTNode.java b/src/main/org/codehaus/groovy/ast/ASTNode.java
index a192e68..b5b7200 100644
--- a/src/main/org/codehaus/groovy/ast/ASTNode.java
+++ b/src/main/org/codehaus/groovy/ast/ASTNode.java
@@ -51,6 +51,7 @@ public class ASTNode implements NodeMetaDataHandler {
     private int lastLineNumber = -1;
     private int lastColumnNumber = -1;
     private Map metaDataMap = null;
+    private NodeMetaDataHandlerHelper helper = new NodeMetaDataHandlerHelper(this);
 
     public void visit(GroovyCodeVisitor visitor) {
         throw new RuntimeException("No visit() method implemented for class: " + getClass().getName());
@@ -116,6 +117,36 @@ public class ASTNode implements NodeMetaDataHandler {
     }
 
     @Override
+    public <T> T getNodeMetaData(Object key) {
+        return helper.getNodeMetaData(key);
+    }
+
+    @Override
+    public void copyNodeMetaData(NodeMetaDataHandler other) {
+        helper.copyNodeMetaData(other);
+    }
+
+    @Override
+    public void setNodeMetaData(Object key, Object value) {
+        helper.setNodeMetaData(key, value);
+    }
+
+    @Override
+    public Object putNodeMetaData(Object key, Object value) {
+        return helper.putNodeMetaData(key, value);
+    }
+
+    @Override
+    public void removeNodeMetaData(Object key) {
+        helper.removeNodeMetaData(key);
+    }
+
+    @Override
+    public Map<?, ?> getNodeMetaData() {
+        return helper.getNodeMetaData();
+    }
+
+    @Override
     public ListHashMap getMetaDataMap() {
         return (ListHashMap) metaDataMap;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9df1bb76/src/main/org/codehaus/groovy/ast/NodeMetaDataHandler.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/NodeMetaDataHandler.java b/src/main/org/codehaus/groovy/ast/NodeMetaDataHandler.java
index 280cd6b..74197a9 100644
--- a/src/main/org/codehaus/groovy/ast/NodeMetaDataHandler.java
+++ b/src/main/org/codehaus/groovy/ast/NodeMetaDataHandler.java
@@ -19,9 +19,7 @@
 package org.codehaus.groovy.ast;
 
 import org.codehaus.groovy.GroovyBugError;
-import org.codehaus.groovy.util.ListHashMap;
 
-import java.util.Collections;
 import java.util.Map;
 
 /**
@@ -34,33 +32,14 @@ public interface NodeMetaDataHandler {
      * @param key - the meta data key
      * @return the node meta data value for this key
      */
-    default <T> T getNodeMetaData(Object key) {
-        Map<?, ?> metaDataMap = this.getMetaDataMap();
-
-        if (metaDataMap == null) {
-            return (T) null;
-        }
-        return (T) metaDataMap.get(key);
-    }
+    <T> T getNodeMetaData(Object key);
 
     /**
      * Copies all node meta data from the other node to this one
      *
      * @param other - the other node
      */
-    default void copyNodeMetaData(NodeMetaDataHandler other) {
-        Map otherMetaDataMap = other.getMetaDataMap();
-        if (otherMetaDataMap == null) {
-            return;
-        }
-        Map metaDataMap = this.getMetaDataMap();
-        if (metaDataMap == null) {
-            metaDataMap = new ListHashMap();
-            this.setMetaDataMap(metaDataMap);
-        }
-
-        metaDataMap.putAll(otherMetaDataMap);
-    }
+    void copyNodeMetaData(NodeMetaDataHandler other);
 
     /**
      * Sets the node meta data.
@@ -70,17 +49,7 @@ public interface NodeMetaDataHandler {
      * @throws GroovyBugError if key is null or there is already meta
      *                        data under that key
      */
-    default void setNodeMetaData(Object key, Object value) {
-        if (key == null) throw new GroovyBugError("Tried to set meta data with null key on
" + this + ".");
-
-        Map metaDataMap = this.getMetaDataMap();
-        if (metaDataMap == null) {
-            metaDataMap = new ListHashMap();
-            this.setMetaDataMap(metaDataMap);
-        }
-        Object old = metaDataMap.put(key, value);
-        if (old != null) throw new GroovyBugError("Tried to overwrite existing meta data
" + this + ".");
-    }
+    void setNodeMetaData(Object key, Object value);
 
     /**
      * Sets the node meta data but allows overwriting values.
@@ -90,16 +59,7 @@ public interface NodeMetaDataHandler {
      * @return the old node meta data value for this key
      * @throws GroovyBugError if key is null
      */
-    default Object putNodeMetaData(Object key, Object value) {
-        if (key == null) throw new GroovyBugError("Tried to set meta data with null key on
" + this + ".");
-
-        Map metaDataMap = this.getMetaDataMap();
-        if (metaDataMap == null) {
-            metaDataMap = new ListHashMap();
-            this.setMetaDataMap(metaDataMap);
-        }
-        return metaDataMap.put(key, value);
-    }
+    Object putNodeMetaData(Object key, Object value);
 
     /**
      * Removes a node meta data entry.
@@ -107,29 +67,14 @@ public interface NodeMetaDataHandler {
      * @param key - the meta data key
      * @throws GroovyBugError if the key is null
      */
-    default void removeNodeMetaData(Object key) {
-        if (key == null) throw new GroovyBugError("Tried to remove meta data with null key
" + this + ".");
-
-        Map metaDataMap = this.getMetaDataMap();
-        if (metaDataMap == null) {
-            return;
-        }
-        metaDataMap.remove(key);
-    }
+    void removeNodeMetaData(Object key);
 
     /**
      * Returns an unmodifiable view of the current node metadata.
      *
      * @return the node metadata. Always not null.
      */
-    default Map<?, ?> getNodeMetaData() {
-        Map metaDataMap = this.getMetaDataMap();
-
-        if (metaDataMap == null) {
-            return Collections.emptyMap();
-        }
-        return Collections.unmodifiableMap(metaDataMap);
-    }
+    Map<?, ?> getNodeMetaData();
 
     Map<?, ?> getMetaDataMap();
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/9df1bb76/src/main/org/codehaus/groovy/ast/NodeMetaDataHandlerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/NodeMetaDataHandlerHelper.java b/src/main/org/codehaus/groovy/ast/NodeMetaDataHandlerHelper.java
new file mode 100644
index 0000000..6543a21
--- /dev/null
+++ b/src/main/org/codehaus/groovy/ast/NodeMetaDataHandlerHelper.java
@@ -0,0 +1,138 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.codehaus.groovy.ast;
+
+import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.util.ListHashMap;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class NodeMetaDataHandlerHelper {
+
+    private NodeMetaDataHandler delegate;
+
+    public NodeMetaDataHandlerHelper(ASTNode delegate) {
+        this.delegate = delegate;
+    }
+
+    /**
+     * Gets the node meta data.
+     *
+     * @param key - the meta data key
+     * @return the node meta data value for this key
+     */
+    public <T> T getNodeMetaData(Object key) {
+        Map<?, ?> metaDataMap = delegate.getMetaDataMap();
+
+        if (metaDataMap == null) {
+            return null;
+        }
+        return (T) metaDataMap.get(key);
+    }
+
+    /**
+     * Copies all node meta data from the other node to this one
+     *
+     * @param other - the other node
+     */
+    public void copyNodeMetaData(NodeMetaDataHandler other) {
+        Map otherMetaDataMap = other.getMetaDataMap();
+        if (otherMetaDataMap == null) {
+            return;
+        }
+        Map metaDataMap = delegate.getMetaDataMap();
+        if (metaDataMap == null) {
+            metaDataMap = new ListHashMap();
+            delegate.setMetaDataMap(metaDataMap);
+        }
+
+        metaDataMap.putAll(otherMetaDataMap);
+    }
+
+    /**
+     * Sets the node meta data.
+     *
+     * @param key   - the meta data key
+     * @param value - the meta data value
+     * @throws GroovyBugError if key is null or there is already meta
+     *                        data under that key
+     */
+    public void setNodeMetaData(Object key, Object value) {
+        if (key == null) throw new GroovyBugError("Tried to set meta data with null key on
" + this + ".");
+
+        Map metaDataMap = delegate.getMetaDataMap();
+        if (metaDataMap == null) {
+            metaDataMap = new ListHashMap();
+            delegate.setMetaDataMap(metaDataMap);
+        }
+        Object old = metaDataMap.put(key, value);
+        if (old != null) throw new GroovyBugError("Tried to overwrite existing meta data
" + this + ".");
+    }
+
+    /**
+     * Sets the node meta data but allows overwriting values.
+     *
+     * @param key   - the meta data key
+     * @param value - the meta data value
+     * @return the old node meta data value for this key
+     * @throws GroovyBugError if key is null
+     */
+    public Object putNodeMetaData(Object key, Object value) {
+        if (key == null) throw new GroovyBugError("Tried to set meta data with null key on
" + this + ".");
+
+        Map metaDataMap = delegate.getMetaDataMap();
+        if (metaDataMap == null) {
+            metaDataMap = new ListHashMap();
+            delegate.setMetaDataMap(metaDataMap);
+        }
+        return metaDataMap.put(key, value);
+    }
+
+    /**
+     * Removes a node meta data entry.
+     *
+     * @param key - the meta data key
+     * @throws GroovyBugError if the key is null
+     */
+    public void removeNodeMetaData(Object key) {
+        if (key == null) throw new GroovyBugError("Tried to remove meta data with null key
" + this + ".");
+
+        Map metaDataMap = delegate.getMetaDataMap();
+        if (metaDataMap == null) {
+            return;
+        }
+        metaDataMap.remove(key);
+    }
+
+    /**
+     * Returns an unmodifiable view of the current node metadata.
+     *
+     * @return the node metadata. Always not null.
+     */
+    public Map<?, ?> getNodeMetaData() {
+        Map metaDataMap = delegate.getMetaDataMap();
+
+        if (metaDataMap == null) {
+            return Collections.emptyMap();
+        }
+        return Collections.unmodifiableMap(metaDataMap);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/9df1bb76/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
----------------------------------------------------------------------
diff --git a/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
b/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
index 1fb2c97..d08f4ad 100644
--- a/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
+++ b/subprojects/parser-antlr4/src/main/antlr4/org/apache/groovy/parser/antlr4/GroovyParser.g4
@@ -49,6 +49,7 @@ options {
 
     public static class GroovyParserRuleContext extends ParserRuleContext implements NodeMetaDataHandler
{
         private Map metaDataMap = null;
+        private NodeMetaDataHandlerHelper helper = new NodeMetaDataHandlerHelper(this);
 
         public GroovyParserRuleContext() {}
 
@@ -65,6 +66,45 @@ options {
         public void setMetaDataMap(Map<?, ?> metaDataMap) {
             this.metaDataMap = metaDataMap;
         }
+
+        public <T> T getNodeMetaData(Object key) {
+            return helper.getNodeMetaData(key);
+        }
+
+        @Override
+        public void copyNodeMetaData(NodeMetaDataHandler other) {
+            helper.copyNodeMetaData(other);
+        }
+
+        @Override
+        public void setNodeMetaData(Object key, Object value) {
+            helper.setNodeMetaData(key, value);
+        }
+
+        @Override
+        public Object putNodeMetaData(Object key, Object value) {
+            return helper.putNodeMetaData(key, value);
+        }
+
+        @Override
+        public void removeNodeMetaData(Object key) {
+            helper.removeNodeMetaData(key);
+        }
+
+        @Override
+        public Map<?, ?> getNodeMetaData() {
+            return helper.getNodeMetaData();
+        }
+
+        @Override
+        public ListHashMap getMetaDataMap() {
+            return (ListHashMap) metaDataMap;
+        }
+
+        @Override
+        public void setMetaDataMap(Map<?, ?> metaDataMap) {
+            this.metaDataMap = metaDataMap;
+        }
     }
 
     @Override


Mime
View raw message