freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/2] freemarker git commit: (Minor code cleanup)
Date Wed, 12 Sep 2018 07:53:48 GMT
(Minor code cleanup)


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

Branch: refs/heads/2.3-gae
Commit: 390fe65c61cbda058c5c5785eb9520137bdfee04
Parents: 5442e2d
Author: ddekany <ddekany@apache.org>
Authored: Wed Sep 12 09:51:11 2018 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Wed Sep 12 09:51:11 2018 +0200

----------------------------------------------------------------------
 .../freemarker/core/AddConcatExpression.java    |  4 +---
 .../template/utility/TemplateModelUtils.java    |  4 +---
 .../template/utility/TemplateModelUtilTest.java | 20 ++++++++------------
 3 files changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/freemarker/blob/390fe65c/src/main/java/freemarker/core/AddConcatExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/AddConcatExpression.java b/src/main/java/freemarker/core/AddConcatExpression.java
index c337296..40d0bb6 100644
--- a/src/main/java/freemarker/core/AddConcatExpression.java
+++ b/src/main/java/freemarker/core/AddConcatExpression.java
@@ -240,7 +240,6 @@ final class AddConcatExpression extends Expression {
     implements TemplateHashModelEx {
         private CollectionAndSequence keys;
         private CollectionAndSequence values;
-        private int size;
 
         ConcatenatedHashEx(TemplateHashModelEx left, TemplateHashModelEx right) {
             super(left, right);
@@ -248,7 +247,7 @@ final class AddConcatExpression extends Expression {
         
         public int size() throws TemplateModelException {
             initKeys();
-            return size;
+            return keys.size();
         }
 
         public TemplateCollectionModel keys()
@@ -270,7 +269,6 @@ final class AddConcatExpression extends Expression {
                 SimpleSequence keySeq = new SimpleSequence(32);
                 addKeys(keySet, keySeq, (TemplateHashModelEx) this.left);
                 addKeys(keySet, keySeq, (TemplateHashModelEx) this.right);
-                size = keySet.size();
                 keys = new CollectionAndSequence(keySeq);
             }
         }

http://git-wip-us.apache.org/repos/asf/freemarker/blob/390fe65c/src/main/java/freemarker/template/utility/TemplateModelUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/utility/TemplateModelUtils.java b/src/main/java/freemarker/template/utility/TemplateModelUtils.java
index c721a11..be38312 100644
--- a/src/main/java/freemarker/template/utility/TemplateModelUtils.java
+++ b/src/main/java/freemarker/template/utility/TemplateModelUtils.java
@@ -225,7 +225,6 @@ public final class TemplateModelUtils {
             implements TemplateHashModelEx {
         private CollectionAndSequence keys;
         private CollectionAndSequence values;
-        private int size;
 
         private HashExUnionModel(List<? extends TemplateHashModelEx> hashes) {
             super(hashes);
@@ -233,7 +232,7 @@ public final class TemplateModelUtils {
         
         public int size() throws TemplateModelException {
             initKeys();
-            return size;
+            return keys.size();
         }
 
         public TemplateCollectionModel keys() throws TemplateModelException {
@@ -253,7 +252,6 @@ public final class TemplateModelUtils {
                 for (TemplateHashModelEx hash : hashes) {
                     addKeys(keySet, keySeq, hash);
                 }
-                size = keySet.size();
                 keys = new CollectionAndSequence(keySeq);
             }
         }

http://git-wip-us.apache.org/repos/asf/freemarker/blob/390fe65c/src/test/java/freemarker/template/utility/TemplateModelUtilTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/utility/TemplateModelUtilTest.java b/src/test/java/freemarker/template/utility/TemplateModelUtilTest.java
index 47d7bc2..6122532 100644
--- a/src/test/java/freemarker/template/utility/TemplateModelUtilTest.java
+++ b/src/test/java/freemarker/template/utility/TemplateModelUtilTest.java
@@ -38,7 +38,6 @@ import freemarker.template.DefaultMapAdapter;
 import freemarker.template.DefaultNonListCollectionAdapter;
 import freemarker.template.DefaultObjectWrapper;
 import freemarker.template.DefaultObjectWrapperBuilder;
-import freemarker.template.ObjectWrapper;
 import freemarker.template.TemplateCollectionModel;
 import freemarker.template.TemplateHashModel;
 import freemarker.template.TemplateHashModelEx;
@@ -134,7 +133,7 @@ public class TemplateModelUtilTest {
     }
 
     @Test
-    public void wrapAsHashUnion1() throws TemplateModelException {
+    public void wrapAsHashUnionBasics() throws TemplateModelException {
         TemplateHashModelEx thEx1 = new TemplateHashModelExOnly(ImmutableMap.of("a", 1, "b",
2));
         TemplateHashModelEx thEx2 = new TemplateHashModelExOnly(ImmutableMap.of("c", 3, "d",
4));
         TemplateHashModelEx thEx3 = new TemplateHashModelExOnly(ImmutableMap.of("b", 22,
"c", 33));
@@ -185,6 +184,7 @@ public class TemplateModelUtilTest {
         assertEquals(((TemplateNumberModel) h.get("b")).getAsNumber(), 2);
         assertEquals(((TemplateNumberModel) h.get("c")).getAsNumber(), 3);
         assertNotNull(h.get("class"));
+        assertNull(h.get("noSuchVariable"));
         
         try {
             TemplateModelUtils.wrapAsHashUnion(ow, "x");
@@ -241,18 +241,16 @@ public class TemplateModelUtilTest {
     /**
      * Deliberately doesn't implement {@link TemplateHashModelEx2}, only {@link TemplateHashModelEx}.

      */
-    private static class TemplateHashModelExOnly implements TemplateHashModelEx {
+    private class TemplateHashModelExOnly implements TemplateHashModelEx {
         
         private final Map<?, ?> map;
-        private final ObjectWrapperWithAPISupport objectWrapper;
         
         public TemplateHashModelExOnly(Map<?, ?> map) {
             this.map = map;
-            objectWrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_27).build();
         }
 
         public TemplateModel get(String key) throws TemplateModelException {
-            return objectWrapper.wrap(map.get(key));
+            return ow.wrap(map.get(key));
         }
 
         public boolean isEmpty() throws TemplateModelException {
@@ -264,27 +262,25 @@ public class TemplateModelUtilTest {
         }
 
         public TemplateCollectionModel keys() throws TemplateModelException {
-            return DefaultNonListCollectionAdapter.adapt(map.keySet(), objectWrapper);
+            return DefaultNonListCollectionAdapter.adapt(map.keySet(), ow);
         }
 
         public TemplateCollectionModel values() throws TemplateModelException {
-            return DefaultNonListCollectionAdapter.adapt(map.values(), objectWrapper);
+            return DefaultNonListCollectionAdapter.adapt(map.values(), ow);
         } 
         
     }
     
-    private static class TemplateHashModelOnly implements TemplateHashModel {
+    private class TemplateHashModelOnly implements TemplateHashModel {
 
         private final Map<?, ?> map;
-        private final ObjectWrapper objectWrapper;
         
         public TemplateHashModelOnly(Map<?, ?> map) {
             this.map = map;
-            objectWrapper = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_27).build();
         }
 
         public TemplateModel get(String key) throws TemplateModelException {
-            return objectWrapper.wrap(map.get(key));
+            return ow.wrap(map.get(key));
         }
 
         public boolean isEmpty() throws TemplateModelException {


Mime
View raw message