freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [3/3] incubator-freemarker git commit: Hash literals now implement TemplateHashModelEx2. This is necessary to be consistent with pre-IcI-2.3.21 ?keys/?values behavior, which supports duplicate keys.
Date Wed, 01 Jun 2016 21:14:40 GMT
Hash literals now implement TemplateHashModelEx2. This is necessary to be consistent with pre-IcI-2.3.21
?keys/?values behavior, which supports duplicate keys.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/7195f178
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/7195f178
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/7195f178

Branch: refs/heads/2.3-gae
Commit: 7195f178abb562291c652dfdfd00b7b1177feabd
Parents: 9010b28
Author: ddekany <ddekany@apache.org>
Authored: Wed Jun 1 23:14:25 2016 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Wed Jun 1 23:14:25 2016 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/core/HashLiteral.java  | 33 +++++++++++++++++++-
 .../expected/listhashliteral-ici-2.3.20.txt     | 21 +++++++++++++
 .../expected/listhashliteral-ici-2.3.21.txt     | 18 +++++++++++
 .../templatesuite/templates/listhashliteral.ftl | 17 ++++++++++
 .../freemarker/test/templatesuite/testcases.xml |  6 ++++
 5 files changed, 94 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7195f178/src/main/java/freemarker/core/HashLiteral.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/HashLiteral.java b/src/main/java/freemarker/core/HashLiteral.java
index dcf5f4a..794ade0 100644
--- a/src/main/java/freemarker/core/HashLiteral.java
+++ b/src/main/java/freemarker/core/HashLiteral.java
@@ -28,7 +28,10 @@ import freemarker.template.SimpleSequence;
 import freemarker.template.TemplateCollectionModel;
 import freemarker.template.TemplateException;
 import freemarker.template.TemplateHashModelEx;
+import freemarker.template.TemplateHashModelEx2;
 import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateModelIterator;
 import freemarker.template._TemplateAPI;
 
 final class HashLiteral extends Expression {
@@ -103,7 +106,7 @@ final class HashLiteral extends Expression {
     	return new HashLiteral(clonedKeys, clonedValues);
     }
 
-    private class SequenceHash implements TemplateHashModelEx {
+    private class SequenceHash implements TemplateHashModelEx2 {
 
         private HashMap map; // maps keys to integer offset
         private TemplateCollectionModel keyCollection, valueCollection; // ordered lists
of keys and values
@@ -176,6 +179,34 @@ final class HashLiteral extends Expression {
         public String toString() {
             return getCanonicalForm();
         }
+
+        public KeyValuePairIterator keyValuePairIterator() throws TemplateModelException
{
+            return new KeyValuePairIterator() {
+                private final TemplateModelIterator keyIterator = keys().iterator();
+                private final TemplateModelIterator valueIterator = values().iterator();
+
+                public boolean hasNext() throws TemplateModelException {
+                    return keyIterator.hasNext();
+                }
+
+                public KeyValuePair next() throws TemplateModelException {
+                    return new KeyValuePair() {
+                        private final TemplateModel key = keyIterator.next();
+                        private final TemplateModel value = valueIterator.next();
+
+                        public TemplateModel getKey() throws TemplateModelException {
+                            return key;
+                        }
+
+                        public TemplateModel getValue() throws TemplateModelException {
+                            return value;
+                        }
+                        
+                    };
+                }
+                
+            };
+        }
         
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7195f178/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.20.txt
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.20.txt
b/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.20.txt
new file mode 100644
index 0000000..4f3873b
--- /dev/null
+++ b/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.20.txt
@@ -0,0 +1,21 @@
+  KVPs:
+    a = 1
+    b = 2
+    a = 3
+  
+  Keys:
+    a
+    b
+    a
+  
+  Values:
+    1
+    2
+    3
+
+  KVPs:
+  
+  Keys:
+  
+  Values:
+

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7195f178/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.21.txt
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.21.txt
b/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.21.txt
new file mode 100644
index 0000000..698ebe4
--- /dev/null
+++ b/src/test/resources/freemarker/test/templatesuite/expected/listhashliteral-ici-2.3.21.txt
@@ -0,0 +1,18 @@
+  KVPs:
+    a = 3
+    b = 2
+  
+  Keys:
+    a
+    b
+  
+  Values:
+    3
+    2
+
+  KVPs:
+  
+  Keys:
+  
+  Values:
+

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7195f178/src/test/resources/freemarker/test/templatesuite/templates/listhashliteral.ftl
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/test/templatesuite/templates/listhashliteral.ftl
b/src/test/resources/freemarker/test/templatesuite/templates/listhashliteral.ftl
new file mode 100644
index 0000000..f56fc84
--- /dev/null
+++ b/src/test/resources/freemarker/test/templatesuite/templates/listhashliteral.ftl
@@ -0,0 +1,17 @@
+<#list [ { "a": 1, "b": 2, "a": 3 }, { } ] as h>
+  KVPs:
+  <#list h as k, v>
+    ${k} = ${v}
+  </#list>
+  
+  Keys:
+  <#list h?keys as k>
+    ${k}
+  </#list>
+  
+  Values:
+  <#list h?values as v>
+    ${v}
+  </#list>
+
+</#list>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7195f178/src/test/resources/freemarker/test/templatesuite/testcases.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/test/templatesuite/testcases.xml b/src/test/resources/freemarker/test/templatesuite/testcases.xml
index 8df64bd..25a54e7 100644
--- a/src/test/resources/freemarker/test/templatesuite/testcases.xml
+++ b/src/test/resources/freemarker/test/templatesuite/testcases.xml
@@ -134,6 +134,12 @@
       <setting object_wrapper="DefaultObjectWrapper(2.3.22, forceLegacyNonListCollections=false)"
/>
    </testCase>
    <testCase name="listhash" />
+   <testCase name="listhashliteral[#endTN]-ici-2.3.20">
+      <setting incompatible_improvements="min, 2.3.20" /> 
+   </testCase>
+   <testCase name="listhashliteral[#endTN]-ici-2.3.21">
+      <setting incompatible_improvements="2.3.21, max" /> 
+   </testCase>
    <testCase name="listliteral" />
    <testCase name="localization" >
       <setting locale="en_AU"/>


Mime
View raw message