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 2017/03/01 14:21:21 UTC

[23/50] [abbrv] incubator-freemarker git commit: (Renamed some internal classes and variables)

(Renamed some internal classes and variables)


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

Branch: refs/heads/2.3
Commit: b5148ee3af2b052407ae51f41f23ed893ab07c93
Parents: 1b94c28
Author: ddekany <dd...@apache.org>
Authored: Wed Feb 22 09:05:10 2017 +0100
Committer: ddekany <dd...@apache.org>
Committed: Thu Feb 23 12:45:22 2017 +0100

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java      |   8 +-
 .../core/BuiltInsForExistenceHandling.java      | 132 +++++++++++++++++++
 .../java/freemarker/core/ExistenceBuiltins.java | 132 -------------------
 .../java/freemarker/core/TemplateElement.java   |  38 +++---
 ...nterruptionSupportTemplatePostProcessor.java |   4 +-
 src/test/java/freemarker/core/ASTPrinter.java   |  22 ++--
 6 files changed, 168 insertions(+), 168 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b5148ee3/src/main/java/freemarker/core/BuiltIn.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltIn.java b/src/main/java/freemarker/core/BuiltIn.java
index fbe0842..99be0b8 100644
--- a/src/main/java/freemarker/core/BuiltIn.java
+++ b/src/main/java/freemarker/core/BuiltIn.java
@@ -105,14 +105,14 @@ abstract class BuiltIn extends Expression implements Cloneable {
         putBI("date_if_unknown", "dateIfUnknown", new BuiltInsForDates.dateType_if_unknownBI(TemplateDateModel.DATE));
         putBI("datetime", new BuiltInsForMultipleTypes.dateBI(TemplateDateModel.DATETIME));
         putBI("datetime_if_unknown", "datetimeIfUnknown", new BuiltInsForDates.dateType_if_unknownBI(TemplateDateModel.DATETIME));
-        putBI("default", new ExistenceBuiltins.defaultBI());
+        putBI("default", new BuiltInsForExistenceHandling.defaultBI());
         putBI("double", new doubleBI());
         putBI("ends_with", "endsWith", new BuiltInsForStringsBasic.ends_withBI());
         putBI("ensure_ends_with", "ensureEndsWith", new BuiltInsForStringsBasic.ensure_ends_withBI());
         putBI("ensure_starts_with", "ensureStartsWith", new BuiltInsForStringsBasic.ensure_starts_withBI());
         putBI("esc", new escBI());
         putBI("eval", new evalBI());
-        putBI("exists", new ExistenceBuiltins.existsBI());
+        putBI("exists", new BuiltInsForExistenceHandling.existsBI());
         putBI("first", new firstBI());
         putBI("float", new floatBI());
         putBI("floor", new floorBI());
@@ -120,10 +120,10 @@ abstract class BuiltIn extends Expression implements Cloneable {
         putBI("counter", new BuiltInsForLoopVariables.counterBI());
         putBI("item_cycle", "itemCycle", new BuiltInsForLoopVariables.item_cycleBI());
         putBI("has_api", "hasApi", new BuiltInsForMultipleTypes.has_apiBI());
-        putBI("has_content", "hasContent", new ExistenceBuiltins.has_contentBI());
+        putBI("has_content", "hasContent", new BuiltInsForExistenceHandling.has_contentBI());
         putBI("has_next", "hasNext", new BuiltInsForLoopVariables.has_nextBI());
         putBI("html", new BuiltInsForStringsEncoding.htmlBI());
-        putBI("if_exists", "ifExists", new ExistenceBuiltins.if_existsBI());
+        putBI("if_exists", "ifExists", new BuiltInsForExistenceHandling.if_existsBI());
         putBI("index", new BuiltInsForLoopVariables.indexBI());
         putBI("index_of", "indexOf", new BuiltInsForStringsBasic.index_ofBI(false));
         putBI("int", new intBI());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b5148ee3/src/main/java/freemarker/core/BuiltInsForExistenceHandling.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsForExistenceHandling.java b/src/main/java/freemarker/core/BuiltInsForExistenceHandling.java
new file mode 100644
index 0000000..7b1ba3e
--- /dev/null
+++ b/src/main/java/freemarker/core/BuiltInsForExistenceHandling.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package freemarker.core;
+
+import java.util.List;
+
+import freemarker.template.TemplateBooleanModel;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateMethodModelEx;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+/**
+ * A holder for builtins that deal with null left-hand values.
+ */
+class BuiltInsForExistenceHandling {
+
+    // Can't be instantiated
+    private BuiltInsForExistenceHandling() { }
+
+    private static abstract class ExistenceBuiltIn extends BuiltIn {
+    
+        protected TemplateModel evalMaybeNonexistentTarget(Environment env) throws TemplateException {
+            TemplateModel tm;
+            if (target instanceof ParentheticalExpression) {
+                boolean lastFIRE = env.setFastInvalidReferenceExceptions(true);
+                try {
+                    tm = target.eval(env);
+                } catch (InvalidReferenceException ire) {
+                    tm = null;
+                } finally {
+                    env.setFastInvalidReferenceExceptions(lastFIRE);
+                }
+            } else {
+                tm = target.eval(env);
+            }
+            return tm;
+        }
+        
+    }
+    
+    static class defaultBI extends BuiltInsForExistenceHandling.ExistenceBuiltIn {
+        
+        @Override
+        TemplateModel _eval(final Environment env) throws TemplateException {
+            TemplateModel model = evalMaybeNonexistentTarget(env);
+            return model == null ? FIRST_NON_NULL_METHOD : new ConstantMethod(model);
+        }
+
+        private static class ConstantMethod implements TemplateMethodModelEx {
+            private final TemplateModel constant;
+
+            ConstantMethod(TemplateModel constant) {
+                this.constant = constant;
+            }
+
+            public Object exec(List args) {
+                return constant;
+            }
+        }
+
+        /**
+         * A method that goes through the arguments one by one and returns
+         * the first one that is non-null. If all args are null, returns null.
+         */
+        private static final TemplateMethodModelEx FIRST_NON_NULL_METHOD =
+            new TemplateMethodModelEx() {
+                public Object exec(List args) throws TemplateModelException {
+                    int argCnt = args.size();
+                    if (argCnt == 0) throw MessageUtil.newArgCntError("?default", argCnt, 1, Integer.MAX_VALUE);
+                    for (int i = 0; i < argCnt; i++ ) {
+                        TemplateModel result = (TemplateModel) args.get(i);
+                        if (result != null) return result;
+                    }
+                    return null;
+                }
+            };
+    }
+    
+    static class existsBI extends BuiltInsForExistenceHandling.ExistenceBuiltIn {
+        @Override
+        TemplateModel _eval(Environment env) throws TemplateException {
+            return evalMaybeNonexistentTarget(env) == null ? TemplateBooleanModel.FALSE : TemplateBooleanModel.TRUE;
+        }
+    
+        @Override
+        boolean evalToBoolean(Environment env) throws TemplateException {
+            return _eval(env) == TemplateBooleanModel.TRUE;
+        }
+    }
+
+    static class has_contentBI extends BuiltInsForExistenceHandling.ExistenceBuiltIn {
+        @Override
+        TemplateModel _eval(Environment env) throws TemplateException {
+            return Expression.isEmpty(evalMaybeNonexistentTarget(env))
+                    ? TemplateBooleanModel.FALSE
+                    : TemplateBooleanModel.TRUE;
+        }
+    
+        @Override
+        boolean evalToBoolean(Environment env) throws TemplateException {
+            return _eval(env) == TemplateBooleanModel.TRUE;
+        }
+    }
+
+    static class if_existsBI extends BuiltInsForExistenceHandling.ExistenceBuiltIn {
+        @Override
+        TemplateModel _eval(Environment env)
+                throws TemplateException {
+            TemplateModel model = evalMaybeNonexistentTarget(env);
+            return model == null ? TemplateModel.NOTHING : model;
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b5148ee3/src/main/java/freemarker/core/ExistenceBuiltins.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/ExistenceBuiltins.java b/src/main/java/freemarker/core/ExistenceBuiltins.java
deleted file mode 100644
index ecc85f7..0000000
--- a/src/main/java/freemarker/core/ExistenceBuiltins.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package freemarker.core;
-
-import java.util.List;
-
-import freemarker.template.TemplateBooleanModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateMethodModelEx;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-
-/**
- * A holder for builtins that deal with null left-hand values.
- */
-class ExistenceBuiltins {
-
-    // Can't be instantiated
-    private ExistenceBuiltins() { }
-
-    private static abstract class ExistenceBuiltIn extends BuiltIn {
-    
-        protected TemplateModel evalMaybeNonexistentTarget(Environment env) throws TemplateException {
-            TemplateModel tm;
-            if (target instanceof ParentheticalExpression) {
-                boolean lastFIRE = env.setFastInvalidReferenceExceptions(true);
-                try {
-                    tm = target.eval(env);
-                } catch (InvalidReferenceException ire) {
-                    tm = null;
-                } finally {
-                    env.setFastInvalidReferenceExceptions(lastFIRE);
-                }
-            } else {
-                tm = target.eval(env);
-            }
-            return tm;
-        }
-        
-    }
-    
-    static class defaultBI extends ExistenceBuiltins.ExistenceBuiltIn {
-        
-        @Override
-        TemplateModel _eval(final Environment env) throws TemplateException {
-            TemplateModel model = evalMaybeNonexistentTarget(env);
-            return model == null ? FIRST_NON_NULL_METHOD : new ConstantMethod(model);
-        }
-
-        private static class ConstantMethod implements TemplateMethodModelEx {
-            private final TemplateModel constant;
-
-            ConstantMethod(TemplateModel constant) {
-                this.constant = constant;
-            }
-
-            public Object exec(List args) {
-                return constant;
-            }
-        }
-
-        /**
-         * A method that goes through the arguments one by one and returns
-         * the first one that is non-null. If all args are null, returns null.
-         */
-        private static final TemplateMethodModelEx FIRST_NON_NULL_METHOD =
-            new TemplateMethodModelEx() {
-                public Object exec(List args) throws TemplateModelException {
-                    int argCnt = args.size();
-                    if (argCnt == 0) throw MessageUtil.newArgCntError("?default", argCnt, 1, Integer.MAX_VALUE);
-                    for (int i = 0; i < argCnt; i++ ) {
-                        TemplateModel result = (TemplateModel) args.get(i);
-                        if (result != null) return result;
-                    }
-                    return null;
-                }
-            };
-    }
-    
-    static class existsBI extends ExistenceBuiltins.ExistenceBuiltIn {
-        @Override
-        TemplateModel _eval(Environment env) throws TemplateException {
-            return evalMaybeNonexistentTarget(env) == null ? TemplateBooleanModel.FALSE : TemplateBooleanModel.TRUE;
-        }
-    
-        @Override
-        boolean evalToBoolean(Environment env) throws TemplateException {
-            return _eval(env) == TemplateBooleanModel.TRUE;
-        }
-    }
-
-    static class has_contentBI extends ExistenceBuiltins.ExistenceBuiltIn {
-        @Override
-        TemplateModel _eval(Environment env) throws TemplateException {
-            return Expression.isEmpty(evalMaybeNonexistentTarget(env))
-                    ? TemplateBooleanModel.FALSE
-                    : TemplateBooleanModel.TRUE;
-        }
-    
-        @Override
-        boolean evalToBoolean(Environment env) throws TemplateException {
-            return _eval(env) == TemplateBooleanModel.TRUE;
-        }
-    }
-
-    static class if_existsBI extends ExistenceBuiltins.ExistenceBuiltIn {
-        @Override
-        TemplateModel _eval(Environment env)
-                throws TemplateException {
-            TemplateModel model = evalMaybeNonexistentTarget(env);
-            return model == null ? TemplateModel.NOTHING : model;
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b5148ee3/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 916769e..5d12ff9 100644
--- a/src/main/java/freemarker/core/TemplateElement.java
+++ b/src/main/java/freemarker/core/TemplateElement.java
@@ -259,11 +259,11 @@ abstract public class TemplateElement extends TemplateObject {
 
     final void setChildBufferCapacity(int capacity) {
         int ln = childCount;
-        TemplateElement[] newRegulatedChildBuffer = new TemplateElement[capacity];
+        TemplateElement[] newChildBuffer = new TemplateElement[capacity];
         for (int i = 0; i < ln; i++) {
-            newRegulatedChildBuffer[i] = childBuffer[i];
+            newChildBuffer[i] = childBuffer[i];
         }
-        childBuffer = newRegulatedChildBuffer;
+        childBuffer = newChildBuffer;
     }
 
     /**
@@ -277,27 +277,27 @@ abstract public class TemplateElement extends TemplateObject {
      * Inserts a new nested element at the given index, which can also be one higher than the current highest index.
      */
     final void addChild(int index, TemplateElement nestedElement) {
-        final int lRegulatedChildCount = childCount;
-
-        TemplateElement[] lRegulatedChildBuffer = childBuffer;
-        if (lRegulatedChildBuffer == null) {
-            lRegulatedChildBuffer = new TemplateElement[INITIAL_REGULATED_CHILD_BUFFER_CAPACITY];
-            childBuffer = lRegulatedChildBuffer;
-        } else if (lRegulatedChildCount == lRegulatedChildBuffer.length) {
-            setChildBufferCapacity(lRegulatedChildCount != 0 ? lRegulatedChildCount * 2 : 1);
-            lRegulatedChildBuffer = childBuffer;
+        final int childCount = this.childCount;
+
+        TemplateElement[] childBuffer = this.childBuffer;
+        if (childBuffer == null) {
+            childBuffer = new TemplateElement[INITIAL_REGULATED_CHILD_BUFFER_CAPACITY];
+            this.childBuffer = childBuffer;
+        } else if (childCount == childBuffer.length) {
+            setChildBufferCapacity(childCount != 0 ? childCount * 2 : 1);
+            childBuffer = this.childBuffer;
         }
         // At this point: nestedElements == this.nestedElements, and has sufficient capacity.
 
-        for (int i = lRegulatedChildCount; i > index; i--) {
-            TemplateElement movedElement = lRegulatedChildBuffer[i - 1];
+        for (int i = childCount; i > index; i--) {
+            TemplateElement movedElement = childBuffer[i - 1];
             movedElement.index = i;
-            lRegulatedChildBuffer[i] = movedElement;
+            childBuffer[i] = movedElement;
         }
         nestedElement.index = index;
         nestedElement.parent = this;
-        lRegulatedChildBuffer[index] = nestedElement;
-        childCount = lRegulatedChildCount + 1;
+        childBuffer[index] = nestedElement;
+        this.childCount = childCount + 1;
     }
 
     final TemplateElement getChild(int index) {
@@ -451,8 +451,8 @@ abstract public class TemplateElement extends TemplateObject {
     }
 
     private TemplateElement getLastChild() {
-        final int regulatedChildCount = this.childCount;
-        return regulatedChildCount == 0 ? null : childBuffer[regulatedChildCount - 1];
+        final int childCount = this.childCount;
+        return childCount == 0 ? null : childBuffer[childCount - 1];
     }
 
     private TemplateElement getFirstLeaf() {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b5148ee3/src/main/java/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java b/src/main/java/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
index 26d54aa..fb9bb6f 100644
--- a/src/main/java/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
+++ b/src/main/java/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
@@ -58,8 +58,8 @@ class ThreadInterruptionSupportTemplatePostProcessor extends TemplatePostProcess
             return;
         }
         
-        final int regulatedChildrenCount = te.getChildCount();
-        for (int i = 0; i < regulatedChildrenCount; i++) {
+        final int childCount = te.getChildCount();
+        for (int i = 0; i < childCount; i++) {
             addInterruptionChecks(te.getChild(i));
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b5148ee3/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 68d6ba0..82d61a1 100644
--- a/src/test/java/freemarker/core/ASTPrinter.java
+++ b/src/test/java/freemarker/core/ASTPrinter.java
@@ -264,8 +264,8 @@ public class ASTPrinter {
         for (int i = 0; i < childCount; i++) {
             TemplateElement child = te.getChild(i);
             TemplateElement parentElement = child.getParentElement();
-            // 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
+            // As MixedContent.accept does nothing but return its children, it's optimized out in the final
+            // AST tree. While it will be present as a child, the parent element also will have children
             // that contains the children of the MixedContent directly. 
             if (parentElement instanceof MixedContent && parentElement.getParentElement() != null) {
                 parentElement = parentElement.getParentElement();
@@ -287,31 +287,31 @@ public class ASTPrinter {
             throw new InvalidASTException("Mixed content with child count less than 2 should removed by optimizatoin, "
                     + "but found one with " + te.getChildCount() + " child(ren).");
         }
-        TemplateElement[] regulatedChildren = te.getChildBuffer();
-        if (regulatedChildren != null) {
+        TemplateElement[] children = te.getChildBuffer();
+        if (children != null) {
             if (childCount == 0) {
                 throw new InvalidASTException(
-                        "regularChildren must be null when regularChild is 0."
+                        "Children must be null when childCount is 0."
                         + "\nNode: " + te.dump(false));
             }
             for (int i = 0; i < te.getChildCount(); i++) {
-                if (regulatedChildren[i] == null) {
+                if (children[i] == null) {
                     throw new InvalidASTException(
-                            "regularChildren can't be null at index " + i
+                            "Children can't be null at index " + i
                             + "\nNode: " + te.dump(false));
                 }
             }
-            for (int i = te.getChildCount(); i < regulatedChildren.length; i++) {
-                if (regulatedChildren[i] != null) {
+            for (int i = te.getChildCount(); i < children.length; i++) {
+                if (children[i] != null) {
                     throw new InvalidASTException(
-                            "regularChildren can't be non-null at index " + i
+                            "Children can't be non-null at index " + i
                             + "\nNode: " + te.dump(false));
                 }
             }
         } else {
             if (childCount != 0) {
                 throw new InvalidASTException(
-                        "regularChildren mustn't be null when regularChild isn't 0."
+                        "Children mustn't be null when childCount isn't 0."
                         + "\nNode: " + te.dump(false));
             }
         }