You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2016/06/12 16:54:14 UTC

[33/50] incubator-freemarker git commit: Refined recent autoInclude and autoImport changes: they should be always "isAutoXxxSet" on the Configuration level

Refined recent autoInclude and autoImport changes: they should be always "isAutoXxxSet" on the Configuration level


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

Branch: refs/heads/2.3
Commit: 428b3744c00cb0d0ba3015e8c287923d429a4d18
Parents: 2b56488
Author: ddekany <dd...@apache.org>
Authored: Wed Jun 8 01:11:41 2016 +0200
Committer: ddekany <dd...@apache.org>
Committed: Wed Jun 8 01:11:41 2016 +0200

----------------------------------------------------------------------
 src/main/java/freemarker/core/Configurable.java | 47 +++++++++++---------
 .../java/freemarker/template/Configuration.java | 20 +++------
 2 files changed, 34 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/428b3744/src/main/java/freemarker/core/Configurable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Configurable.java b/src/main/java/freemarker/core/Configurable.java
index f5776cc..fbee5a6 100644
--- a/src/main/java/freemarker/core/Configurable.java
+++ b/src/main/java/freemarker/core/Configurable.java
@@ -425,6 +425,9 @@ public class Configurable {
         
         customDateFormats = Collections.emptyMap();
         customNumberFormats = Collections.emptyMap();
+        
+        initAutoImportsMap();
+        initAutoIncludesList();
     }
 
     /**
@@ -1641,7 +1644,7 @@ public class Configurable {
         // "synchronized" is removed from the API as it's not safe to set anything after publishing the Configuration
         synchronized (this) {
             if (autoImports == null) {
-                autoImports = new LinkedHashMap<String, String>(4);
+                initAutoImportsMap();
             } else {
                 // This was a List earlier, so re-inserted items must go to the end, hence we remove() before put().
                 autoImports.remove(namespaceVarName);
@@ -1649,6 +1652,10 @@ public class Configurable {
             autoImports.put(namespaceVarName, templateName);
         }
     }
+
+    private void initAutoImportsMap() {
+        autoImports = new LinkedHashMap<String, String>(4);
+    }
     
     /**
      * Removes an auto-import from this {@link Configurable} level (not from the parents or children);
@@ -1716,9 +1723,7 @@ public class Configurable {
      * @since 2.3.25
      */
     public Map<String, String> getAutoImports() {
-        return autoImports != null ? autoImports
-                : parent != null ? parent.getAutoImports()
-                : Collections.<String, String>emptyMap();
+        return autoImports != null ? autoImports : parent.getAutoImports();
     }
     
     /**
@@ -1731,8 +1736,8 @@ public class Configurable {
     }
 
     /**
-     * Like {@link #getAutoImports()}, but doesn't fall back to the parent {@link Configurable}, nor does it provide
-     * a non-{@code null} default when called as the method of a {@link Configuration}.
+     * Like {@link #getAutoImports()}, but doesn't fall back to the parent {@link Configurable} (and so it can be
+     * {@code null}).
      *  
      * @since 2.3.25
      */
@@ -1778,7 +1783,7 @@ public class Configurable {
         // "synchronized" is removed from the API as it's not safe to set anything after publishing the Configuration
         synchronized (this) {
             if (autoIncludes == null) {
-                autoIncludes = new ArrayList<String>(4);
+                initAutoIncludesList();
             } else {
                 if (removeDuplicate) {
                     autoIncludes.remove(templateName);
@@ -1787,6 +1792,10 @@ public class Configurable {
             autoIncludes.add(templateName);
         }
     }
+
+    private void initAutoIncludesList() {
+        autoIncludes = new ArrayList<String>(4);
+    }
     
     /**
      * Removes all auto-includes, then calls {@link #addAutoInclude(String)} for each {@link List} items.
@@ -1808,14 +1817,14 @@ public class Configurable {
     }
     
     /**
-     * Getter pair of {@link #setAutoIncludes(List)}; do not modify the returned {@link List}! To be consistent with other
-     * setting getters, if this setting was set directly on this {@link Configurable} object, this simply returns that
-     * value, otherwise it returns the value from the parent {@link Configurable}. So beware, the returned value doesn't
-     * reflect the {@link List} concatenation logic that FreeMarker actually uses for this setting. The
-     * returned value is not the same {@link List} object that was set with {@link #setAutoIncludes(List)}, only its
-     * content is the same (except that duplicate are removed). The returned value isn't a snapshot; it may or may not shows the changes later made to this
-     * setting on this {@link Configurable} level (but usually it's well defined if until what point settings are
-     * possibly modified).
+     * Getter pair of {@link #setAutoIncludes(List)}; do not modify the returned {@link List}! To be consistent with
+     * other setting getters, if this setting was set directly on this {@link Configurable} object, this simply returns
+     * that value, otherwise it returns the value from the parent {@link Configurable}. So beware, the returned value
+     * doesn't reflect the {@link List} concatenation logic that FreeMarker actually uses for this setting. The returned
+     * value is not the same {@link List} object that was set with {@link #setAutoIncludes(List)}, only its content is
+     * the same (except that duplicate are removed). The returned value isn't a snapshot; it may or may not shows the
+     * changes later made to this setting on this {@link Configurable} level (but usually it's well defined if until
+     * what point settings are possibly modified).
      * 
      * <p>
      * The return value is never {@code null}; called on the {@link Configuration} (top) level, it defaults to an empty
@@ -1826,9 +1835,7 @@ public class Configurable {
      * @since 2.3.25
      */
     public List<String> getAutoIncludes() {
-        return autoIncludes != null ? autoIncludes
-                : parent != null ? parent.getAutoIncludes()
-                : Collections.<String>emptyList();
+        return autoIncludes != null ? autoIncludes : parent.getAutoIncludes();
     }
     
     /**
@@ -1841,8 +1848,8 @@ public class Configurable {
     }
     
     /**
-     * Like {@link #getAutoIncludes()}, but doesn't fall back to the parent {@link Configurable}, nor does it provide
-     * a non-{@code null} default when called as the method of a {@link Configuration}.
+     * Like {@link #getAutoIncludes()}, but doesn't fall back to the parent {@link Configurable} (and so it can be
+     * {@code null}).
      *  
      * @since 2.3.25
      */

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/428b3744/src/main/java/freemarker/template/Configuration.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/Configuration.java b/src/main/java/freemarker/template/Configuration.java
index 1a7381a..07f921a 100644
--- a/src/main/java/freemarker/template/Configuration.java
+++ b/src/main/java/freemarker/template/Configuration.java
@@ -3067,17 +3067,14 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
     private void doAutoImports(Environment env, Template t) throws IOException, TemplateException {
         Map<String, String> envAutoImports = env.getAutoImportsWithoutFallback();
         Map<String, String> tAutoImports = t.getAutoImportsWithoutFallback();
-        Map<String, String> cfgAutoImports = getAutoImportsWithoutFallback();
         
         boolean lazyAutoImports = getLazyAutoImports() != null ? getLazyAutoImports().booleanValue() : getLazyImports();
         
-        if (cfgAutoImports != null) {
-            for (Map.Entry<String, String> autoImport : cfgAutoImports.entrySet()) {
-                String nsVarName = autoImport.getKey();
-                if ((tAutoImports == null || !tAutoImports.containsKey(nsVarName))
-                        && (envAutoImports == null || !envAutoImports.containsKey(nsVarName))) {
-                    env.importLib(autoImport.getValue(), nsVarName, lazyAutoImports);
-                }
+        for (Map.Entry<String, String> autoImport : getAutoImportsWithoutFallback().entrySet()) {
+            String nsVarName = autoImport.getKey();
+            if ((tAutoImports == null || !tAutoImports.containsKey(nsVarName))
+                    && (envAutoImports == null || !envAutoImports.containsKey(nsVarName))) {
+                env.importLib(autoImport.getValue(), nsVarName, lazyAutoImports);
             }
         }
         if (tAutoImports != null) {
@@ -3098,11 +3095,8 @@ public class Configuration extends Configurable implements Cloneable, ParserConf
     
     private void doAutoIncludes(Environment env, Template t) throws TemplateException, IOException,
             TemplateNotFoundException, MalformedTemplateNameException, ParseException {
-        List<String> cfgAutoIncludes = getAutoIncludesWithoutFallback();
-        if (cfgAutoIncludes != null) {
-            for (String templateName : cfgAutoIncludes) {
-                env.include(getTemplate(templateName, env.getLocale()));
-            }
+        for (String templateName : getAutoIncludesWithoutFallback()) {
+            env.include(getTemplate(templateName, env.getLocale()));
         }
         
         List<String> tAutoIncludes = t.getAutoIncludesWithoutFallback();