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/06/17 13:14:37 UTC

[3/4] incubator-freemarker git commit: Some internal cleanup: Renamed ArithmeticExpression to ASTExpArithmetic. Renamed ASTNode.getNodeTypeSymbol to getASTNodeDescriptor.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/ASTNode.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTNode.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTNode.java
index 18e34c1..6a2ce15 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTNode.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTNode.java
@@ -173,7 +173,7 @@ abstract class ASTNode {
      * source, assuming we turn off automatic white-space removal when parsing the canonical form.
      * 
      * @see ASTElement#getDescription()
-     * @see #getNodeTypeSymbol()
+     * @see #getASTNodeDescriptor()
      */
     abstract public String getCanonicalForm();
     
@@ -183,14 +183,11 @@ abstract class ASTNode {
      * be suitable as tree node labels in a tree view. Yet, they should be consistent and complete enough so that an AST
      * that is equivalent with the original could be reconstructed from the tree view. Thus, for literal values that are
      * leaf nodes the symbols should be the canonical form of value.
-     * 
-     * Note that {@link ASTElement#getDescription()} has similar role, only it doesn't go under the element level
-     * (i.e. down to the expression level), instead it always prints the embedded expressions itself.
-     * 
+     *
      * @see #getCanonicalForm()
      * @see ASTElement#getDescription()
      */
-    abstract String getNodeTypeSymbol();
+    abstract String getASTNodeDescriptor();
     
     /**
      * Returns highest valid parameter index + 1. So one should scan indexes with {@link #getParameterValue(int)}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/ASTStaticText.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTStaticText.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTStaticText.java
index 7766012..5e4b957 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTStaticText.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTStaticText.java
@@ -81,7 +81,7 @@ final class ASTStaticText extends ASTElement {
     }
     
     @Override
-    String getNodeTypeSymbol() {
+    String getASTNodeDescriptor() {
         return "#text";
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/ArithmeticExpression.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ArithmeticExpression.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ArithmeticExpression.java
deleted file mode 100644
index 764ec8a..0000000
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ArithmeticExpression.java
+++ /dev/null
@@ -1,129 +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 org.apache.freemarker.core;
-
-import org.apache.freemarker.core.arithmetic.ArithmeticEngine;
-import org.apache.freemarker.core.model.TemplateModel;
-import org.apache.freemarker.core.model.impl.SimpleNumber;
-
-/**
- * An operator for arithmetic operations. Note that the + operator is in {@link ASTExpAddOrConcat}, because its
- * overloaded (does string concatenation and more).
- */
-final class ArithmeticExpression extends ASTExpression {
-
-    static final int TYPE_SUBSTRACTION = 0;
-    static final int TYPE_MULTIPLICATION = 1;
-    static final int TYPE_DIVISION = 2;
-    static final int TYPE_MODULO = 3;
-
-    private static final char[] OPERATOR_IMAGES = new char[] { '-', '*', '/', '%' };
-
-    private final ASTExpression lho;
-    private final ASTExpression rho;
-    private final int operator;
-
-    ArithmeticExpression(ASTExpression lho, ASTExpression rho, int operator) {
-        this.lho = lho;
-        this.rho = rho;
-        this.operator = operator;
-    }
-
-    @Override
-    TemplateModel _eval(Environment env) throws TemplateException {
-        return _eval(env, this, lho.evalToNumber(env), operator, rho.evalToNumber(env));
-    }
-
-    static TemplateModel _eval(Environment env, ASTNode parent, Number lhoNumber, int operator, Number rhoNumber)
-            throws TemplateException {
-        ArithmeticEngine ae = _EvalUtil.getArithmeticEngine(env, parent);
-        switch (operator) {
-            case TYPE_SUBSTRACTION : 
-                return new SimpleNumber(ae.subtract(lhoNumber, rhoNumber));
-            case TYPE_MULTIPLICATION :
-                return new SimpleNumber(ae.multiply(lhoNumber, rhoNumber));
-            case TYPE_DIVISION :
-                return new SimpleNumber(ae.divide(lhoNumber, rhoNumber));
-            case TYPE_MODULO :
-                return new SimpleNumber(ae.modulus(lhoNumber, rhoNumber));
-            default:
-                if (parent instanceof ASTExpression) {
-                    throw new _MiscTemplateException((ASTExpression) parent,
-                            "Unknown operation: ", Integer.valueOf(operator));
-                } else {
-                    throw new _MiscTemplateException("Unknown operation: ", Integer.valueOf(operator));
-                }
-        }
-    }
-
-    @Override
-    public String getCanonicalForm() {
-        return lho.getCanonicalForm() + ' ' + getOperatorSymbol(operator) + ' ' + rho.getCanonicalForm();
-    }
-    
-    @Override
-    String getNodeTypeSymbol() {
-        return String.valueOf(getOperatorSymbol(operator));
-    }
-
-    static char getOperatorSymbol(int operator) {
-        return OPERATOR_IMAGES[operator];
-    }
-    
-    @Override
-    boolean isLiteral() {
-        return constantValue != null || (lho.isLiteral() && rho.isLiteral());
-    }
-
-    @Override
-    protected ASTExpression deepCloneWithIdentifierReplaced_inner(
-            String replacedIdentifier, ASTExpression replacement, ReplacemenetState replacementState) {
-    	return new ArithmeticExpression(
-    	        lho.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState),
-    	        rho.deepCloneWithIdentifierReplaced(replacedIdentifier, replacement, replacementState),
-    	        operator);
-    }
-    
-    @Override
-    int getParameterCount() {
-        return 3;
-    }
-
-    @Override
-    Object getParameterValue(int idx) {
-        switch (idx) {
-        case 0: return lho;
-        case 1: return rho;
-        case 2: return Integer.valueOf(operator);
-        default: throw new IndexOutOfBoundsException();
-        }
-    }
-
-    @Override
-    ParameterRole getParameterRole(int idx) {
-        switch (idx) {
-        case 0: return ParameterRole.LEFT_HAND_OPERAND;
-        case 1: return ParameterRole.RIGHT_HAND_OPERAND;
-        case 2: return ParameterRole.AST_NODE_SUBTYPE;
-        default: throw new IndexOutOfBoundsException();
-        }
-    }
-    
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInWithParseTimeParameters.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInWithParseTimeParameters.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInWithParseTimeParameters.java
index d2fa8be..47a37bd 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInWithParseTimeParameters.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInWithParseTimeParameters.java
@@ -48,8 +48,8 @@ abstract class BuiltInWithParseTimeParameters extends SpecialBuiltIn {
     }
     
     @Override
-    String getNodeTypeSymbol() {
-        return super.getNodeTypeSymbol() + "(...)";
+    String getASTNodeDescriptor() {
+        return super.getASTNodeDescriptor() + "(...)";
     }        
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java
index c5797c7..8edc322 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ParsingConfiguration.java
@@ -237,8 +237,9 @@ public interface ParsingConfiguration {
      * messages (or the column number you get through other API-s). So for example if the users edit templates in an
      * editor where the tab width is set to 4, you should set this to 4 so that the column numbers printed by FreeMarker
      * will match the column number shown in the editor. This setting doesn't affect the output of templates, as a tab
-     * in the template will remain a tab in the output too.
-     * It's value is at least 1, at most 256.
+     * in the template will remain a tab in the output too. The value of this setting is at least 1, and at most 256.
+     * When it's 1, tab characters will be kept in the return value of {@link Template#getSource(int, int, int, int)},
+     * otherwise they will be replaced with the appropriate number of spaces.
      */
     int getTabSize();
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
index d05ba08..05a786e 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ThreadInterruptionSupportTemplatePostProcessor.java
@@ -93,11 +93,11 @@ class ThreadInterruptionSupportTemplatePostProcessor extends TemplatePostProcess
 
         @Override
         protected String dump(boolean canonical) {
-            return canonical ? "" : "<#--" + getNodeTypeSymbol() + "--#>";
+            return canonical ? "" : "<#--" + getASTNodeDescriptor() + "--#>";
         }
 
         @Override
-        String getNodeTypeSymbol() {
+        String getASTNodeDescriptor() {
             return "##threadInterruptionCheck";
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java b/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java
index 5dfa623..4723f58 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java
@@ -76,7 +76,7 @@ public class _ErrorDescriptionBuilder {
                 Blaming blaming = findBlaming(parentElement, blamed, 0);
                 if (blaming != null) {
                     sb.append("For ");
-                    String nss = blaming.blamer.getNodeTypeSymbol();
+                    String nss = blaming.blamer.getASTNodeDescriptor();
                     char q = nss.indexOf('"') == -1 ? '\"' : '`';
                     sb.append(q).append(nss).append(q);
                     sb.append(" ").append(blaming.roleOfblamed).append(": ");

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cb4a93dc/freemarker-core/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/javacc/FTL.jj b/freemarker-core/src/main/javacc/FTL.jj
index 552f236..7a39545 100644
--- a/freemarker-core/src/main/javacc/FTL.jj
+++ b/freemarker-core/src/main/javacc/FTL.jj
@@ -1544,7 +1544,7 @@ ASTExpression AdditiveExpression() :
             } else {
                 numberLiteralOnly(lhs);
                 numberLiteralOnly(rhs);
-                result = new ArithmeticExpression(lhs, rhs, ArithmeticExpression.TYPE_SUBSTRACTION);
+                result = new ASTExpArithmetic(lhs, rhs, ASTExpArithmetic.TYPE_SUBSTRACTION);
             }
             result.setLocation(template, lhs, rhs);
             lhs = result;
@@ -1562,7 +1562,7 @@ ASTExpression AdditiveExpression() :
 ASTExpression MultiplicativeExpression() :
 {
     ASTExpression lhs, rhs, result;
-    int operation = ArithmeticExpression.TYPE_MULTIPLICATION;
+    int operation = ASTExpArithmetic.TYPE_MULTIPLICATION;
 }
 {
     lhs = UnaryExpression() { result = lhs; }
@@ -1570,18 +1570,18 @@ ASTExpression MultiplicativeExpression() :
         LOOKAHEAD(<TIMES>|<DIVIDE>|<PERCENT>)
         (
             (
-                <TIMES> { operation = ArithmeticExpression.TYPE_MULTIPLICATION; }
+                <TIMES> { operation = ASTExpArithmetic.TYPE_MULTIPLICATION; }
                 |
-                <DIVIDE> { operation = ArithmeticExpression.TYPE_DIVISION; }
+                <DIVIDE> { operation = ASTExpArithmetic.TYPE_DIVISION; }
                 |
-                <PERCENT> {operation = ArithmeticExpression.TYPE_MODULO; }
+                <PERCENT> {operation = ASTExpArithmetic.TYPE_MODULO; }
             )
         )
         rhs = UnaryExpression()
         {
             numberLiteralOnly(lhs);
             numberLiteralOnly(rhs);
-            result = new ArithmeticExpression(lhs, rhs, operation);
+            result = new ASTExpArithmetic(lhs, rhs, operation);
             result.setLocation(template, lhs, rhs);
             lhs = result;
         }