freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/2] incubator-freemarker git commit: Avoid using TemplateElement methods that are Swing dependent in 2.3 (the non-GAE branch)
Date Tue, 15 Dec 2015 22:09:58 GMT
Avoid using TemplateElement methods that are Swing dependent in 2.3 (the non-GAE branch)


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

Branch: refs/heads/2.3-gae
Commit: 204723f0955c1e6e33a7591d20bc8b47d5d3adad
Parents: 44ca7eb
Author: ddekany <ddekany@apache.org>
Authored: Tue Dec 15 23:08:46 2015 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Tue Dec 15 23:08:46 2015 +0100

----------------------------------------------------------------------
 .../java/freemarker/core/ConditionalBlock.java    |  2 +-
 .../java/freemarker/core/TemplateElement.java     | 18 +++++++++++-------
 src/main/java/freemarker/core/_CoreAPI.java       |  8 ++++++++
 .../freemarker/debug/impl/RmiDebuggerService.java | 13 +++++++------
 src/test/java/freemarker/core/ASTPrinter.java     |  4 ++--
 5 files changed, 29 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/204723f0/src/main/java/freemarker/core/ConditionalBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/ConditionalBlock.java b/src/main/java/freemarker/core/ConditionalBlock.java
index 911affd..3b94001 100644
--- a/src/main/java/freemarker/core/ConditionalBlock.java
+++ b/src/main/java/freemarker/core/ConditionalBlock.java
@@ -63,7 +63,7 @@ final class ConditionalBlock extends TemplateElement {
         if (canonical) {
             buf.append(">");
             buf.append(getChildrenCanonicalForm());
-            if (!(getParent() instanceof IfBlock)) {
+            if (!(getParentElement() instanceof IfBlock)) {
                 buf.append("</#if>");
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/204723f0/src/main/java/freemarker/core/TemplateElement.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateElement.java b/src/main/java/freemarker/core/TemplateElement.java
index de1f109..916769e 100644
--- a/src/main/java/freemarker/core/TemplateElement.java
+++ b/src/main/java/freemarker/core/TemplateElement.java
@@ -214,6 +214,10 @@ abstract public class TemplateElement extends TemplateObject {
                 : Collections.enumeration(Collections.EMPTY_LIST);
     }
 
+    /**
+     * @deprecated Internal API - even internally, use {@link #getChild(int)} instead.
+     */
+    @Deprecated
     public TemplateElement getChildAt(int index) {
         if (childCount == 0) {
             throw new IndexOutOfBoundsException("Template element has no children");
@@ -245,6 +249,13 @@ abstract public class TemplateElement extends TemplateObject {
     public TemplateElement getParent() {
         return parent;
     }
+    
+    /**
+     * The element whose child this element is, or {@code null} if this is the root node.
+     */
+    final TemplateElement getParentElement() {
+        return parent;
+    }
 
     final void setChildBufferCapacity(int capacity) {
         int ln = childCount;
@@ -323,13 +334,6 @@ abstract public class TemplateElement extends TemplateObject {
     }
 
     /**
-     * The element whose child this element is, or {@code null} if this is the root node.
-     */
-    final TemplateElement getParentElement() {
-        return parent;
-    }
-
-    /**
      * This is a special case, because a root element is not contained in another element,
so we couldn't set the
      * private fields.
      */

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/204723f0/src/main/java/freemarker/core/_CoreAPI.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/_CoreAPI.java b/src/main/java/freemarker/core/_CoreAPI.java
index 620edd8..826f29e 100644
--- a/src/main/java/freemarker/core/_CoreAPI.java
+++ b/src/main/java/freemarker/core/_CoreAPI.java
@@ -173,4 +173,12 @@ public class _CoreAPI {
         }
     }
     
+    public static TemplateElement getParentElement(TemplateElement te) {
+        return te.getParentElement();
+    }
+
+    public static TemplateElement getChildElement(TemplateElement te, int index) {
+        return te.getChild(index);
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/204723f0/src/main/java/freemarker/debug/impl/RmiDebuggerService.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/debug/impl/RmiDebuggerService.java b/src/main/java/freemarker/debug/impl/RmiDebuggerService.java
index 8065830..25d1b2e 100644
--- a/src/main/java/freemarker/debug/impl/RmiDebuggerService.java
+++ b/src/main/java/freemarker/debug/impl/RmiDebuggerService.java
@@ -39,6 +39,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import freemarker.core.DebugBreak;
 import freemarker.core.Environment;
 import freemarker.core.TemplateElement;
+import freemarker.core._CoreAPI;
 import freemarker.debug.Breakpoint;
 import freemarker.debug.DebuggerListener;
 import freemarker.debug.EnvironmentSuspendedEvent;
@@ -188,7 +189,7 @@ extends
         if (te == null) {
             return;
         }
-        TemplateElement parent = te.getParent();
+        TemplateElement parent = _CoreAPI.getParentElement(te);
         DebugBreak db = new DebugBreak(te);
         // TODO: Ensure there always is a parent by making sure
         // that the root element in the template is always a MixedContent
@@ -285,13 +286,13 @@ extends
                 db = (DebugBreak) te;
                 break;
             }
-            te = te.getParent();
+            te = _CoreAPI.getParentElement(te);
         }
         if (db == null) {
             return;
         }
-        TemplateElement parent = db.getParent(); 
-        parent.setChildAt(parent.getIndex(db), db.getChildAt(0));
+        TemplateElement parent = _CoreAPI.getParentElement(db); 
+        parent.setChildAt(parent.getIndex(db), _CoreAPI.getChildElement(db, 0));
     }
     
     void removeBreakpoints(String templateName) {
@@ -334,9 +335,9 @@ extends
     private void removeDebugBreaks(TemplateElement te) {
         int count = te.getChildCount();
         for (int i = 0; i < count; ++i) {
-            TemplateElement child = te.getChildAt(i);
+            TemplateElement child = _CoreAPI.getChildElement(te, i);
             while (child instanceof DebugBreak) {
-                TemplateElement dbchild = child.getChildAt(0); 
+                TemplateElement dbchild = _CoreAPI.getChildElement(child, 0); 
                 te.setChildAt(i, dbchild);
                 child = dbchild;
             }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/204723f0/src/test/java/freemarker/core/ASTPrinter.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/ASTPrinter.java b/src/test/java/freemarker/core/ASTPrinter.java
index fa907e8..68d6ba0 100644
--- a/src/test/java/freemarker/core/ASTPrinter.java
+++ b/src/test/java/freemarker/core/ASTPrinter.java
@@ -267,8 +267,8 @@ public class ASTPrinter {
             // As MixedContent.accept does nothing but return its regulatedChildren, it's
optimized out in the final
             // AST tree. While it will be present as a child, the parent element also will
have regularedChildren
             // that contains the children of the MixedContent directly. 
-            if (parentElement instanceof MixedContent && parentElement.getParent()
!= null) {
-                parentElement = parentElement.getParent();
+            if (parentElement instanceof MixedContent && parentElement.getParentElement()
!= null) {
+                parentElement = parentElement.getParentElement();
             }
             if (parentElement != te) {
                 throw new InvalidASTException("Wrong parent node."


Mime
View raw message