freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: DefaultIteratorAdapter now supports ?api. It was an oversight that it didn't. Also, added ?api support to the recently added DefaultEnumerationAdapter too.
Date Sun, 12 Mar 2017 15:02:43 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 544e9105c -> da310dd91


DefaultIteratorAdapter now supports ?api. It was an oversight that it didn't. Also, added
?api support to the recently added DefaultEnumerationAdapter too.


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

Branch: refs/heads/2.3-gae
Commit: da310dd91bd1d99f1553b04ac2f6934e68ab1994
Parents: 544e910
Author: ddekany <ddekany@apache.org>
Authored: Sun Mar 12 16:02:37 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Sun Mar 12 16:02:37 2017 +0100

----------------------------------------------------------------------
 .../template/DefaultEnumerationAdapter.java     |  7 +++-
 .../template/DefaultIteratorAdapter.java        |  7 +++-
 src/manual/en_US/book.xml                       | 41 +++++++++++---------
 .../template/DefaultObjectWrapperTest.java      | 15 +++++++
 4 files changed, 50 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/da310dd9/src/main/java/freemarker/template/DefaultEnumerationAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/DefaultEnumerationAdapter.java b/src/main/java/freemarker/template/DefaultEnumerationAdapter.java
index 570e0e8..74a58d4 100644
--- a/src/main/java/freemarker/template/DefaultEnumerationAdapter.java
+++ b/src/main/java/freemarker/template/DefaultEnumerationAdapter.java
@@ -6,6 +6,7 @@ import java.util.Iterator;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import freemarker.ext.util.WrapperTemplateModel;
+import freemarker.template.utility.ObjectWrapperWithAPISupport;
 
 /**
  * Adapts an {@link Enumeration} to the corresponding {@link TemplateModel} interface(s),
most importantly to
@@ -16,7 +17,7 @@ import freemarker.ext.util.WrapperTemplateModel;
  */
 @SuppressWarnings("serial")
 public class DefaultEnumerationAdapter extends WrappingTemplateModel implements TemplateCollectionModel,
-        AdapterTemplateModel, WrapperTemplateModel, Serializable {
+        AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport, Serializable
{
 
     @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's Seralizable")
     private final Enumeration<?> enumeration;
@@ -52,6 +53,10 @@ public class DefaultEnumerationAdapter extends WrappingTemplateModel implements
         return new SimpleTemplateModelIterator();
     }
 
+    public TemplateModel getAPI() throws TemplateModelException {
+        return ((ObjectWrapperWithAPISupport) getObjectWrapper()).wrapAsAPI(enumeration);
+    }
+    
     /**
      * Not thread-safe.
      */

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/da310dd9/src/main/java/freemarker/template/DefaultIteratorAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/DefaultIteratorAdapter.java b/src/main/java/freemarker/template/DefaultIteratorAdapter.java
index 4ac1212..150e51f 100644
--- a/src/main/java/freemarker/template/DefaultIteratorAdapter.java
+++ b/src/main/java/freemarker/template/DefaultIteratorAdapter.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import freemarker.ext.util.WrapperTemplateModel;
+import freemarker.template.utility.ObjectWrapperWithAPISupport;
 
 /**
  * Adapts an {@link Iterator} to the corresponding {@link TemplateModel} interface(s), most
importantly to
@@ -43,7 +44,7 @@ import freemarker.ext.util.WrapperTemplateModel;
  * @since 2.3.22
  */
 public class DefaultIteratorAdapter extends WrappingTemplateModel implements TemplateCollectionModel,
-        AdapterTemplateModel, WrapperTemplateModel, Serializable {
+        AdapterTemplateModel, WrapperTemplateModel, TemplateModelWithAPISupport, Serializable
{
 
     @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's Seralizable")
     private final Iterator iterator;
@@ -76,6 +77,10 @@ public class DefaultIteratorAdapter extends WrappingTemplateModel implements
Tem
         return new SimpleTemplateModelIterator();
     }
 
+    public TemplateModel getAPI() throws TemplateModelException {
+        return ((ObjectWrapperWithAPISupport) getObjectWrapper()).wrapAsAPI(iterator);
+    }
+    
     /**
      * Not thread-safe.
      */

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/da310dd9/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index beee581..c98b35e 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -26887,24 +26887,6 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
-              <para><literal>DefaultObjectWrapper</literal>, only with
its
-              <literal>incompatible_improvements</literal> set to 2.3.26
-              (<link linkend="topic.defaultObjectWrapperIcI">see how
-              here...</link>), wraps
-              <literal>java.util.Enumeration</literal>-s into
-              <literal>freemarker.template.DefaultEnumerationAdapter</literal>
-              (a new class) instead of into
-              <literal>freemarker.ext.beans.EnumerationModel</literal> (as far
-              as <literal>useAdaptersForContainers</literal> is
-              <literal>true</literal>, which is the default). This adapter is
-              cleaner than <literal>EnumerationModel</literal> as it only
-              implements the minimally required FTL type, which avoids some
-              ambiguous situations. (Note that Java API methods aren't exposed
-              anymore as subvariables; if you really need them, you can use
-              <literal>?api</literal>).</para>
-            </listitem>
-
-            <listitem>
               <para>Better error messages when someone tries to get an invalid
               <literal>@@<replaceable>...</replaceable></literal>
subvariable
               of an XML DOM node. (Now it's not issued by the XPath
@@ -26959,6 +26941,29 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
+              <para><literal>DefaultObjectWrapper</literal>, only with
its
+              <literal>incompatible_improvements</literal> set to 2.3.26
+              (<link linkend="topic.defaultObjectWrapperIcI">see how
+              here...</link>), wraps
+              <literal>java.util.Enumeration</literal>-s into
+              <literal>freemarker.template.DefaultEnumerationAdapter</literal>
+              (a new class) instead of into
+              <literal>freemarker.ext.beans.EnumerationModel</literal> (as far
+              as <literal>useAdaptersForContainers</literal> is
+              <literal>true</literal>, which is the default). This adapter is
+              cleaner than <literal>EnumerationModel</literal> as it only
+              implements the minimally required FTL type, which avoids some
+              ambiguous situations. (Note that Java API methods aren't exposed
+              anymore as subvariables; if you really need them, you can use
+              <literal>?api</literal>).</para>
+            </listitem>
+
+            <listitem>
+              <para><literal>DefaultIteratorAdapter</literal> now support
+              <literal>?api</literal>.</para>
+            </listitem>
+
+            <listitem>
               <para><literal>Configuration.setSetting(String,
               String)</literal> and <literal>setSettings</literal> now
allows
               <literal>null</literal> value for

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/da310dd9/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/template/DefaultObjectWrapperTest.java b/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
index 4be352a..dcbc659 100644
--- a/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
+++ b/src/test/java/freemarker/template/DefaultObjectWrapperTest.java
@@ -869,6 +869,17 @@ public class DefaultObjectWrapperTest {
         }
     }
     
+    @Test
+    public void testIteratorApiSupport() throws TemplateModelException {
+        TemplateModel wrappedIterator = OW22.wrap(Collections.emptyIterator());
+        assertThat(wrappedIterator, instanceOf(DefaultIteratorAdapter.class));
+        DefaultIteratorAdapter iteratorAdapter = (DefaultIteratorAdapter) wrappedIterator;
+        
+        TemplateHashModel api = (TemplateHashModel) iteratorAdapter.getAPI();
+        assertFalse(((TemplateBooleanModel) ((TemplateMethodModelEx)
+                api.get("hasNext")).exec(Collections.emptyList())).getAsBoolean());
+    }
+    
     @SuppressWarnings("boxing")
     @Test
     public void testCharKeyFallback() throws TemplateModelException {
@@ -982,6 +993,10 @@ public class DefaultObjectWrapperTest {
          } catch (TemplateException e) {
              assertThat(e.getMessage(), containsStringIgnoringCase("only once"));
          }
+         
+         TemplateHashModel api = (TemplateHashModel) enumAdapter.getAPI();
+         assertFalse(((TemplateBooleanModel) ((TemplateMethodModelEx)
+                 api.get("hasMoreElements")).exec(Collections.emptyList())).getAsBoolean());
     }
     
     @Test


Mime
View raw message