freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [04/15] incubator-freemarker git commit: Some formatting fixes and cleanup
Date Sun, 13 Dec 2015 16:02:21 GMT
Some formatting fixes and 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/c64251ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/c64251ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/c64251ef

Branch: refs/heads/2.3-gae
Commit: c64251ef81070d031e953a6d9fd381d935d9c4a1
Parents: 113d670
Author: ddekany <ddekany@apache.org>
Authored: Sun Nov 29 21:05:53 2015 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Tue Dec 1 09:31:00 2015 +0100

----------------------------------------------------------------------
 src/main/java/freemarker/core/Environment.java  | 18 ++++----
 src/main/java/freemarker/core/MixedContent.java |  2 +-
 .../core/TemplateElementsToVisit.java           | 45 ++++++++++++--------
 3 files changed, 37 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/c64251ef/src/main/java/freemarker/core/Environment.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Environment.java b/src/main/java/freemarker/core/Environment.java
index fab6c80..2789e02 100644
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@ -325,28 +325,28 @@ public final class Environment extends Configurable {
      * #if as hidden in stack traces would be wrong, because we still want to show #if when
its test expression fails.)
      */
     void visit(TemplateElement element, boolean hideInParent) throws IOException, TemplateException
{
-        TemplateElement parent = null;
-        if(hideInParent) {
-            parent = replaceTopElement(element);
+        TemplateElement hiddenParent;
+        if (hideInParent) {
+            hiddenParent = replaceTopElement(element);
         } else {
             pushElement(element);
+            hiddenParent = null;
         }
         try {
             TemplateElementsToVisit templateElementsToVisit = element.accept(this);
-            if(null != templateElementsToVisit) {
+            if (templateElementsToVisit != null) {
                 boolean hideInnerElementInParent = templateElementsToVisit.isHideInParent();
                 for (TemplateElement templateElementToVisit : templateElementsToVisit.getTemplateElements())
{
-                    if(null != templateElementToVisit) {
+                    if (templateElementToVisit != null) {
                         visit(templateElementToVisit, hideInnerElementInParent);
                     }
                 }
             }
         } catch (TemplateException te) {
             handleTemplateException(te);
-        }
-        finally {
-            if(null != parent) {
-                replaceTopElement(parent);
+        } finally {
+            if (hiddenParent != null) {
+                replaceTopElement(hiddenParent);
             } else {
                 popElement();
             }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/c64251ef/src/main/java/freemarker/core/MixedContent.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/MixedContent.java b/src/main/java/freemarker/core/MixedContent.java
index 274e520..fc4a1d5 100644
--- a/src/main/java/freemarker/core/MixedContent.java
+++ b/src/main/java/freemarker/core/MixedContent.java
@@ -52,7 +52,7 @@ final class MixedContent extends TemplateElement {
     @Override
     TemplateElementsToVisit accept(Environment env)
         throws TemplateException, IOException {
-        return new TemplateElementsToVisit(getRegulatedChildren(), false);
+        return new TemplateElementsToVisit(getRegulatedChildren());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/c64251ef/src/main/java/freemarker/core/TemplateElementsToVisit.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateElementsToVisit.java b/src/main/java/freemarker/core/TemplateElementsToVisit.java
index 97aa6ea..3314b96 100644
--- a/src/main/java/freemarker/core/TemplateElementsToVisit.java
+++ b/src/main/java/freemarker/core/TemplateElementsToVisit.java
@@ -3,29 +3,38 @@ package freemarker.core;
 import java.util.Collection;
 import java.util.Collections;
 
+/**
+ * Used as the return value of {@link TemplateElement#accept(Environment)} when the invoked
element has nested elements
+ * to invoke. It would be more natural to invoke child elements before returning from
+ * {@link TemplateElement#accept(Environment)}, however, if there's nothing to do after the
child elements were invoked,
+ * that would mean wasting stack space.
+ * 
+ * @since 2.3.24
+ */
 class TemplateElementsToVisit {
 
-  private final Collection<TemplateElement> templateElements;
-  private final boolean hideInParent;
+    private final Collection<TemplateElement> templateElements;
+    private final boolean hideInParent;
 
-  TemplateElementsToVisit(Collection<TemplateElement> templateElements, boolean hideInParent)
{
-    this.templateElements = null != templateElements ? templateElements : Collections.<TemplateElement>emptyList();
-    this.hideInParent = hideInParent;
-  }
+    TemplateElementsToVisit(Collection<TemplateElement> templateElements, boolean hideInParent)
{
+        this.templateElements = null != templateElements ? templateElements : Collections.<TemplateElement>
emptyList();
+        this.hideInParent = hideInParent;
+    }
 
-  public TemplateElementsToVisit(Collection<TemplateElement> templateElements) {
-    this(templateElements, false);
-  }
+    TemplateElementsToVisit(Collection<TemplateElement> templateElements) {
+        this(templateElements, false);
+    }
 
-  public TemplateElementsToVisit(TemplateElement nestedBlock, boolean hideInParent) {
-    this(Collections.singleton(nestedBlock), hideInParent);
-  }
+    TemplateElementsToVisit(TemplateElement nestedBlock, boolean hideInParent) {
+        this(Collections.singleton(nestedBlock), hideInParent);
+    }
 
-  Collection<TemplateElement> getTemplateElements() {
-    return templateElements;
-  }
+    Collection<TemplateElement> getTemplateElements() {
+        return templateElements;
+    }
 
-  boolean isHideInParent() {
-    return hideInParent;
-  }
+    boolean isHideInParent() {
+        return hideInParent;
+    }
+    
 }


Mime
View raw message