freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/3] incubator-freemarker git commit: Replacing visibility hacks due to core.debug with less ugly visibility hacks.
Date Sun, 26 Feb 2017 01:30:57 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 946a42372 -> d74ccf3cc


Replacing visibility hacks due to core.debug with less ugly visibility hacks.


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

Branch: refs/heads/3
Commit: 8346c1f6b4c7e039fefe81a8d1a7bc3843e2d632
Parents: 946a423
Author: ddekany <ddekany@apache.org>
Authored: Sun Feb 26 01:56:49 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Sun Feb 26 01:56:49 2017 +0100

----------------------------------------------------------------------
 .../apache/freemarker/core/_ASTDebugBreak.java  |   2 +-
 .../org/apache/freemarker/core/_ASTElement.java |   2 +-
 .../org/apache/freemarker/core/_CoreAPI.java    |  14 +--
 .../java/org/apache/freemarker/core/_Debug.java | 104 +++++++++++++++++++
 .../core/debug/impl/RmiDebuggerService.java     | 101 ++----------------
 5 files changed, 116 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8346c1f6/src/main/java/org/apache/freemarker/core/_ASTDebugBreak.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/_ASTDebugBreak.java b/src/main/java/org/apache/freemarker/core/_ASTDebugBreak.java
index 00f1ef7..f113722 100644
--- a/src/main/java/org/apache/freemarker/core/_ASTDebugBreak.java
+++ b/src/main/java/org/apache/freemarker/core/_ASTDebugBreak.java
@@ -27,7 +27,7 @@ import org.apache.freemarker.core.debug.impl.DebuggerService;
  * Don't use this; used internally by FreeMarker, might changes without notice.
  * A debug breakpoint inserted into the template 
  */
-public class _ASTDebugBreak extends _ASTElement {
+class _ASTDebugBreak extends _ASTElement {
     public _ASTDebugBreak(_ASTElement nestedBlock) {
         addChild(nestedBlock);
         copyLocationFrom(nestedBlock);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8346c1f6/src/main/java/org/apache/freemarker/core/_ASTElement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/_ASTElement.java b/src/main/java/org/apache/freemarker/core/_ASTElement.java
index 1c9ca58..bac5540 100644
--- a/src/main/java/org/apache/freemarker/core/_ASTElement.java
+++ b/src/main/java/org/apache/freemarker/core/_ASTElement.java
@@ -35,7 +35,7 @@ import org.apache.freemarker.core.util._ArrayEnumeration;
  * compatibility.
  */
 // TODO [FM3] Get rid of "public" and thus the "_" prefix
-abstract public class _ASTElement extends ASTNode {
+abstract class _ASTElement extends ASTNode {
 
     private static final int INITIAL_CHILD_BUFFER_CAPACITY = 6;
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8346c1f6/src/main/java/org/apache/freemarker/core/_CoreAPI.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/_CoreAPI.java b/src/main/java/org/apache/freemarker/core/_CoreAPI.java
index 3c40a79..69966f3 100644
--- a/src/main/java/org/apache/freemarker/core/_CoreAPI.java
+++ b/src/main/java/org/apache/freemarker/core/_CoreAPI.java
@@ -19,7 +19,10 @@
 
 package org.apache.freemarker.core;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
 
 import org.apache.freemarker.core.model.TemplateModel;
 import org.apache.freemarker.core.model.TemplateModelException;
@@ -64,16 +67,6 @@ public final class _CoreAPI {
         }
     }
 
-    // Because of debug...
-    public static _ASTElement getParentElement(_ASTElement te) {
-        return te.getParent();
-    }
-
-    // Because of debug...
-    public static _ASTElement getChildElement(_ASTElement te, int index) {
-        return te.getChild(index);
-    }
-
     // [FM3] Should become unnecessary as custom directive classes are reworked
     public static boolean isMacroOrFunction(TemplateModel m) {
         return m instanceof ASTDirMacro;
@@ -97,4 +90,5 @@ public final class _CoreAPI {
                     + incompatibleImprovements);
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8346c1f6/src/main/java/org/apache/freemarker/core/_Debug.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/_Debug.java b/src/main/java/org/apache/freemarker/core/_Debug.java
new file mode 100644
index 0000000..15cfed1
--- /dev/null
+++ b/src/main/java/org/apache/freemarker/core/_Debug.java
@@ -0,0 +1,104 @@
+package org.apache.freemarker.core;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * Created by √Čn on 2/26/2017.
+ */
+public final class _Debug {
+
+    private _Debug() {
+        //
+    }
+
+
+    public static void insertDebugBreak(Template t, int line) {
+        _ASTElement te = findTemplateElement(t.getRootTreeNode(), line);
+        if (te == null) {
+            return;
+        }
+        _ASTElement parent = te.getParent();
+        _ASTDebugBreak db = new _ASTDebugBreak(te);
+        // TODO: Ensure there always is a parent by making sure
+        // that the root element in the template is always a ASTImplicitParent
+        // Also make sure it doesn't conflict with anyone's code.
+        parent.setChildAt(parent.getIndex(te), db);
+    }
+
+    public static void removeDebugBreak(Template t, int line) {
+        _ASTElement te = findTemplateElement(t.getRootTreeNode(), line);
+        if (te == null) {
+            return;
+        }
+        _ASTDebugBreak db = null;
+        while (te != null) {
+            if (te instanceof _ASTDebugBreak) {
+                db = (_ASTDebugBreak) te;
+                break;
+            }
+            te = te.getParent();
+        }
+        if (db == null) {
+            return;
+        }
+        _ASTElement parent = db.getParent();
+        parent.setChildAt(parent.getIndex(db), db.getChild(0));
+    }
+
+    private static _ASTElement findTemplateElement(_ASTElement te, int line) {
+        if (te.getBeginLine() > line || te.getEndLine() < line) {
+            return null;
+        }
+        // Find the narrowest match
+        List childMatches = new ArrayList();
+        for (Enumeration children = te.children(); children.hasMoreElements(); ) {
+            _ASTElement child = (_ASTElement) children.nextElement();
+            _ASTElement childmatch = findTemplateElement(child, line);
+            if (childmatch != null) {
+                childMatches.add(childmatch);
+            }
+        }
+        //find a match that exactly matches the begin/end line
+        _ASTElement bestMatch = null;
+        for (int i = 0; i < childMatches.size(); i++) {
+            _ASTElement e = (_ASTElement) childMatches.get(i);
+
+            if ( bestMatch == null ) {
+                bestMatch = e;
+            }
+
+            if ( e.getBeginLine() == line && e.getEndLine() > line ) {
+                bestMatch = e;
+            }
+
+            if ( e.getBeginLine() == e.getEndLine() && e.getBeginLine() == line)
{
+                bestMatch = e;
+                break;
+            }
+        }
+        if ( bestMatch != null) {
+            return bestMatch;
+        }
+        // If no child provides narrower match, return this
+        return te;
+    }
+
+    public static void removeDebugBreaks(Template t) {
+        removeDebugBreaks(t.getRootTreeNode());
+    }
+
+    private static void removeDebugBreaks(_ASTElement te) {
+        int count = te.getChildCount();
+        for (int i = 0; i < count; ++i) {
+            _ASTElement child = te.getChild(i);
+            while (child instanceof _ASTDebugBreak) {
+                _ASTElement dbchild = child.getChild(0);
+                te.setChildAt(i, dbchild);
+                child = dbchild;
+            }
+            removeDebugBreaks(child);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8346c1f6/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggerService.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggerService.java b/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggerService.java
index 54ce9a3..95cae45 100644
--- a/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggerService.java
+++ b/src/main/java/org/apache/freemarker/core/debug/impl/RmiDebuggerService.java
@@ -28,18 +28,13 @@ import java.rmi.server.UnicastRemoteObject;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.freemarker.core.Environment;
-import org.apache.freemarker.core.Template;
-import org.apache.freemarker.core._ASTDebugBreak;
-import org.apache.freemarker.core._ASTElement;
-import org.apache.freemarker.core._CoreAPI;
+import org.apache.freemarker.core.*;
 import org.apache.freemarker.core.debug.Breakpoint;
 import org.apache.freemarker.core.debug.DebuggerListener;
 import org.apache.freemarker.core.debug.EnvironmentSuspendedEvent;
@@ -138,7 +133,7 @@ extends
             // Inject already defined breakpoints into the template
             for (Iterator iter = tdi.breakpoints.iterator(); iter.hasNext(); ) {
                 Breakpoint breakpoint = (Breakpoint) iter.next();
-                insertDebugBreak(template, breakpoint);
+                _Debug.insertDebugBreak(template, breakpoint.getLine());
             }
         }
     }
@@ -178,64 +173,13 @@ extends
                     if (t == null) {
                         iter.remove();
                     } else {
-                        insertDebugBreak(t, breakpoint);
+                        _Debug.insertDebugBreak(t, breakpoint.getLine());
                     }
                 }
             }
         }
     }
 
-    private static void insertDebugBreak(Template t, Breakpoint breakpoint) {
-        _ASTElement te = findTemplateElement(t.getRootTreeNode(), breakpoint.getLine());
-        if (te == null) {
-            return;
-        }
-        _ASTElement parent = _CoreAPI.getParentElement(te);
-        _ASTDebugBreak db = new _ASTDebugBreak(te);
-        // TODO: Ensure there always is a parent by making sure
-        // that the root element in the template is always a ASTImplicitParent
-        // Also make sure it doesn't conflict with anyone's code.
-        parent.setChildAt(parent.getIndex(te), db);
-    }
-
-    private static _ASTElement findTemplateElement(_ASTElement te, int line) {
-        if (te.getBeginLine() > line || te.getEndLine() < line) {
-            return null;
-        }
-        // Find the narrowest match
-        List childMatches = new ArrayList();
-        for (Enumeration children = te.children(); children.hasMoreElements(); ) {
-            _ASTElement child = (_ASTElement) children.nextElement();
-            _ASTElement childmatch = findTemplateElement(child, line);
-            if (childmatch != null) {
-                childMatches.add(childmatch);
-            }
-        }
-        //find a match that exactly matches the begin/end line
-        _ASTElement bestMatch = null;
-        for (int i = 0; i < childMatches.size(); i++) {
-            _ASTElement e = (_ASTElement) childMatches.get(i);
-
-            if ( bestMatch == null ) {
-                bestMatch = e;
-            }
-
-            if ( e.getBeginLine() == line && e.getEndLine() > line ) {
-                bestMatch = e;
-            }
-
-            if ( e.getBeginLine() == e.getEndLine() && e.getBeginLine() == line)
{
-                bestMatch = e;
-                break;
-            }
-        }
-        if ( bestMatch != null) {
-           return bestMatch;
-        }
-        // If no child provides narrower match, return this
-        return te;
-    }
-    
     private TemplateDebugInfo findTemplateDebugInfo(String templateName) {
         processRefQueue();
         return (TemplateDebugInfo) templateDebugInfos.get(templateName); 
@@ -265,7 +209,7 @@ extends
                         if (t == null) {
                             iter.remove();
                         } else {
-                            removeDebugBreak(t, breakpoint);
+                            _Debug.removeDebugBreak(t, breakpoint.getLine());
                         }
                     }
                 }
@@ -276,26 +220,6 @@ extends
         }
     }
 
-    private void removeDebugBreak(Template t, Breakpoint breakpoint) {
-        _ASTElement te = findTemplateElement(t.getRootTreeNode(), breakpoint.getLine());
-        if (te == null) {
-            return;
-        }
-        _ASTDebugBreak db = null;
-        while (te != null) {
-            if (te instanceof _ASTDebugBreak) {
-                db = (_ASTDebugBreak) te;
-                break;
-            }
-            te = _CoreAPI.getParentElement(te);
-        }
-        if (db == null) {
-            return;
-        }
-        _ASTElement parent = _CoreAPI.getParentElement(db); 
-        parent.setChildAt(parent.getIndex(db), _CoreAPI.getChildElement(db, 0));
-    }
-    
     void removeBreakpoints(String templateName) {
         synchronized (templateDebugInfos) {
             TemplateDebugInfo tdi = findTemplateDebugInfo(templateName);
@@ -328,24 +252,11 @@ extends
             if (t == null) {
                 iter.remove();
             } else {
-                removeDebugBreaks(t.getRootTreeNode());
+                _Debug.removeDebugBreaks(t);
             }
         }
     }
-    
-    private void removeDebugBreaks(_ASTElement te) {
-        int count = te.getChildCount();
-        for (int i = 0; i < count; ++i) {
-            _ASTElement child = _CoreAPI.getChildElement(te, i);
-            while (child instanceof _ASTDebugBreak) {
-                _ASTElement dbchild = _CoreAPI.getChildElement(child, 0); 
-                te.setChildAt(i, dbchild);
-                child = dbchild;
-            }
-            removeDebugBreaks(child);
-        }
-    }
-    
+
     private static final class TemplateDebugInfo {
         final List templates = new ArrayList();
         final List breakpoints = new ArrayList();


Mime
View raw message