freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/9] incubator-freemarker git commit: (Some internal code cleanup)
Date Sun, 17 Sep 2017 10:56:39 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3 b25782910 -> dd60aef18


(Some internal code cleanup)


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

Branch: refs/heads/2.3
Commit: b185b98001b10281f6c0d1e8df759cdd265714ef
Parents: a4a406a
Author: ddekany <ddekany@apache.org>
Authored: Wed Aug 30 21:40:23 2017 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Wed Aug 30 21:40:23 2017 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/core/Macro.java        |  3 +-
 .../java/freemarker/ext/dom/NodeListModel.java  |  5 +-
 .../template/DefaultIterableAdapter.java        |  2 +-
 .../freemarker/template/DefaultListAdapter.java |  2 +-
 .../DefaultNonListCollectionAdapter.java        |  2 +-
 .../DefaultUnassignableIteratorAdapter.java     | 52 --------------------
 .../IteratorToTemplateModelIteratorAdapter.java | 50 +++++++++++++++++++
 7 files changed, 58 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/core/Macro.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Macro.java b/src/main/java/freemarker/core/Macro.java
index ef657ac..fdce23b 100644
--- a/src/main/java/freemarker/core/Macro.java
+++ b/src/main/java/freemarker/core/Macro.java
@@ -29,6 +29,7 @@ import freemarker.template.TemplateException;
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateModelIterator;
+import freemarker.template.TemplateScalarModel;
 
 /**
  * An element representing a macro declaration.
@@ -263,7 +264,7 @@ public final class Macro extends TemplateElement implements TemplateModel
{
         public Collection getLocalVariableNames() throws TemplateModelException {
             HashSet result = new HashSet();
             for (TemplateModelIterator it = localVars.keys().iterator(); it.hasNext(); )
{
-                result.add(it.next().toString());
+                result.add(((TemplateScalarModel) it.next()).getAsString());
             }
             return result;
         }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/ext/dom/NodeListModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/NodeListModel.java b/src/main/java/freemarker/ext/dom/NodeListModel.java
index a6a7534..46644d9 100644
--- a/src/main/java/freemarker/ext/dom/NodeListModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeListModel.java
@@ -216,11 +216,12 @@ class NodeListModel extends SimpleSequence implements TemplateHashModel,
_Unexpe
     }
 
     private Object[] newTypeErrorExplanation(String type) {
+        int size = size();
         return new Object[] {
                 "This XML query result can't be used as ", type, " because for that it had
to contain exactly "
-                + "1 XML node, but it contains ", Integer.valueOf(size()), " nodes. "
+                + "1 XML node, but it contains ", Integer.valueOf(size), " nodes. "
                 + "That is, the constructing XML query has found ",
-                isEmpty()
+                size == 0
                     ? "no matches."
                     : "multiple matches."
                 };

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/template/DefaultIterableAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/DefaultIterableAdapter.java b/src/main/java/freemarker/template/DefaultIterableAdapter.java
index 14aa6d1..824e2d7 100644
--- a/src/main/java/freemarker/template/DefaultIterableAdapter.java
+++ b/src/main/java/freemarker/template/DefaultIterableAdapter.java
@@ -68,7 +68,7 @@ public class DefaultIterableAdapter extends WrappingTemplateModel implements
Tem
     }
 
     public TemplateModelIterator iterator() throws TemplateModelException {
-        return new DefaultUnassignableIteratorAdapter(iterable.iterator(), getObjectWrapper());
+        return new IteratorToTemplateModelIteratorAdapter(iterable.iterator(), getObjectWrapper());
     }
 
     public Object getWrappedObject() {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/template/DefaultListAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/DefaultListAdapter.java b/src/main/java/freemarker/template/DefaultListAdapter.java
index 62e7f18..3585ed8 100644
--- a/src/main/java/freemarker/template/DefaultListAdapter.java
+++ b/src/main/java/freemarker/template/DefaultListAdapter.java
@@ -96,7 +96,7 @@ public class DefaultListAdapter extends WrappingTemplateModel implements
Templat
         }
 
         public TemplateModelIterator iterator() throws TemplateModelException {
-            return new DefaultUnassignableIteratorAdapter(list.iterator(), getObjectWrapper());
+            return new IteratorToTemplateModelIteratorAdapter(list.iterator(), getObjectWrapper());
         }
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java b/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java
index 2ee9ca2..ab87cc6 100644
--- a/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java
+++ b/src/main/java/freemarker/template/DefaultNonListCollectionAdapter.java
@@ -70,7 +70,7 @@ public class DefaultNonListCollectionAdapter extends WrappingTemplateModel
imple
     }
 
     public TemplateModelIterator iterator() throws TemplateModelException {
-        return new DefaultUnassignableIteratorAdapter(collection.iterator(), getObjectWrapper());
+        return new IteratorToTemplateModelIteratorAdapter(collection.iterator(), getObjectWrapper());
     }
 
     public int size() {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java b/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java
deleted file mode 100644
index 80c4bc5..0000000
--- a/src/main/java/freemarker/template/DefaultUnassignableIteratorAdapter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 freemarker.template;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * As opposed to {@link DefaultIteratorAdapter}, this simpler {@link Iterator} adapter is
used in situations where the
- * {@link TemplateModelIterator} won't be assigned to FreeMarker template variables, only
used internally by
- * {@code #list} or custom Java code. Because of that, it doesn't have to handle the situation
where the user tries to
- * iterate over the same value twice.
- */
-class DefaultUnassignableIteratorAdapter implements TemplateModelIterator {
-
-    private final Iterator<?> it;
-    private final ObjectWrapper wrapper;
-
-    DefaultUnassignableIteratorAdapter(Iterator<?> it, ObjectWrapper wrapper) {
-        this.it = it;
-        this.wrapper = wrapper;
-    }
-
-    public TemplateModel next() throws TemplateModelException {
-        try {
-            return wrapper.wrap(it.next());
-        } catch (NoSuchElementException e) {
-            throw new TemplateModelException("The collection has no more items.", e);
-        }
-    }
-
-    public boolean hasNext() throws TemplateModelException {
-        return it.hasNext();
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b185b980/src/main/java/freemarker/template/IteratorToTemplateModelIteratorAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/IteratorToTemplateModelIteratorAdapter.java
b/src/main/java/freemarker/template/IteratorToTemplateModelIteratorAdapter.java
new file mode 100644
index 0000000..6b49237
--- /dev/null
+++ b/src/main/java/freemarker/template/IteratorToTemplateModelIteratorAdapter.java
@@ -0,0 +1,50 @@
+/*
+ * 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 freemarker.template;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * Unlike {@link DefaultIteratorAdapter}, this doesn't adapt to some {@link TemplateModel},
but to {@link
+ * TemplateModelIterator}.
+ */
+class IteratorToTemplateModelIteratorAdapter implements TemplateModelIterator {
+
+    private final Iterator<?> it;
+    private final ObjectWrapper wrapper;
+
+    IteratorToTemplateModelIteratorAdapter(Iterator<?> it, ObjectWrapper wrapper) {
+        this.it = it;
+        this.wrapper = wrapper;
+    }
+
+    public TemplateModel next() throws TemplateModelException {
+        try {
+            return wrapper.wrap(it.next());
+        } catch (NoSuchElementException e) {
+            throw new TemplateModelException("The collection has no more items.", e);
+        }
+    }
+
+    public boolean hasNext() throws TemplateModelException {
+        return it.hasNext();
+    }
+
+}
\ No newline at end of file


Mime
View raw message