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 2015/12/15 23:23:55 UTC

[14/23] incubator-freemarker git commit: Adjusted #attempt AST structure so that its goes through postParseCleanup properly.

Adjusted #attempt AST structure so that its goes through postParseCleanup properly.


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

Branch: refs/heads/2.3
Commit: 81f81e9665813c88afc09372e7ab36817a9d0977
Parents: c82edf0
Author: ddekany <dd...@apache.org>
Authored: Sun Dec 13 16:52:44 2015 +0100
Committer: ddekany <dd...@apache.org>
Committed: Sun Dec 13 16:52:44 2015 +0100

----------------------------------------------------------------------
 src/main/java/freemarker/core/AttemptBlock.java | 26 +++++++++-----------
 src/main/java/freemarker/core/Environment.java  |  6 ++---
 2 files changed, 15 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/81f81e96/src/main/java/freemarker/core/AttemptBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/AttemptBlock.java b/src/main/java/freemarker/core/AttemptBlock.java
index 64e991f..5222500 100644
--- a/src/main/java/freemarker/core/AttemptBlock.java
+++ b/src/main/java/freemarker/core/AttemptBlock.java
@@ -24,24 +24,25 @@ import java.io.IOException;
 import freemarker.template.TemplateException;
 
 /**
- * #attempt element; might has a nested {@link RecoveryBlock}.
+ * Holder for the attempted section of the #attempt element and of the nested #recover element ({@link RecoveryBlock}).
  */
 final class AttemptBlock extends TemplateElement {
     
-    private TemplateElement[] attemptBlockChildren;
-    private RecoveryBlock recoveryBlock;
+    private TemplateElement attemptedSection;
+    private RecoveryBlock recoverySection;
     
-    AttemptBlock(TemplateElements attemptBlock, RecoveryBlock recoveryBlock) {
-        this.attemptBlockChildren = attemptBlock.getBuffer();
-        this.recoveryBlock = recoveryBlock;
+    AttemptBlock(TemplateElements attemptedSectionChildren, RecoveryBlock recoverySection) {
+        TemplateElement attemptedSection = attemptedSectionChildren.asSingleElement();
+        this.attemptedSection = attemptedSection;
+        this.recoverySection = recoverySection;
         setChildBufferCapacity(2);
-        addChild(attemptBlock.asSingleElement()); // for backward compatibility
-        addChild(recoveryBlock);
+        addChild(attemptedSection); // for backward compatibility
+        addChild(recoverySection);
     }
 
     @Override
     TemplateElement[] accept(Environment env) throws TemplateException, IOException {
-        env.visitAttemptRecover(this, attemptBlockChildren, recoveryBlock);
+        env.visitAttemptRecover(this, attemptedSection, recoverySection);
         return null;
     }
 
@@ -52,10 +53,7 @@ final class AttemptBlock extends TemplateElement {
         } else {
             StringBuilder buf = new StringBuilder();
             buf.append("<").append(getNodeTypeSymbol()).append(">");
-            buf.append(getChildrenCanonicalForm(attemptBlockChildren));            
-            if (recoveryBlock != null) {
-                buf.append(recoveryBlock.getCanonicalForm());
-            }
+            buf.append(getChildrenCanonicalForm());            
             buf.append("</").append(getNodeTypeSymbol()).append(">");
             return buf.toString();
         }
@@ -69,7 +67,7 @@ final class AttemptBlock extends TemplateElement {
     @Override
     Object getParameterValue(int idx) {
         if (idx != 0) throw new IndexOutOfBoundsException();
-        return recoveryBlock;
+        return recoverySection;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/81f81e96/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 3db2f81..004012e 100644
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@ -470,7 +470,7 @@ public final class Environment extends Configurable {
      * Visit a block using buffering/recovery
      */
      void visitAttemptRecover(
-             AttemptBlock attemptBlock, TemplateElement[] attemptBlockChildren, RecoveryBlock recoveryBlock)
+             AttemptBlock attemptBlock, TemplateElement attemptedSection, RecoveryBlock recoverySection)
              throws TemplateException, IOException {
         Writer prevOut = this.out;
         StringWriter sw = new StringWriter();
@@ -480,7 +480,7 @@ public final class Environment extends Configurable {
         boolean lastInAttemptBlock = inAttemptBlock;
         try {
             inAttemptBlock = true;
-            visit(attemptBlockChildren);
+            visit(attemptedSection);
         } catch (TemplateException te) {
             thrownException = te;
         } finally {
@@ -495,7 +495,7 @@ public final class Environment extends Configurable {
             }
             try {
                 recoveredErrorStack.add(thrownException);
-                visit(recoveryBlock);
+                visit(recoverySection);
             } finally {
                 recoveredErrorStack.remove(recoveredErrorStack.size() - 1);
             }