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/09/08 00:29:37 UTC

[6/6] incubator-freemarker git commit: Merge remote-tracking branch 'origin/2.3-gae'

Merge remote-tracking branch 'origin/2.3-gae'

Conflicts:
	src/main/java/freemarker/core/Environment.java
	src/main/java/freemarker/template/_TemplateAPI.java


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

Branch: refs/heads/master
Commit: 19b6bf8855ea2e02c7bedb8bc5de55bf357b13e1
Parents: d7584c4 8983313
Author: ddekany <dd...@apache.org>
Authored: Tue Sep 8 00:29:22 2015 +0200
Committer: ddekany <dd...@apache.org>
Committed: Tue Sep 8 00:29:22 2015 +0200

----------------------------------------------------------------------
 .../core/BuiltInsForMultipleTypes.java          |   62 +-
 src/main/java/freemarker/core/Environment.java  | 1573 +++++++++++-------
 src/main/java/freemarker/core/EvalUtil.java     |    4 +-
 .../core/ISOTemplateDateFormatFactory.java      |    7 +-
 .../core/JavaTemplateDateFormatFactory.java     |    6 +-
 .../java/freemarker/core/NumberLiteral.java     |    2 +-
 .../core/TemplateDateFormatFactory.java         |   34 +-
 .../core/XSTemplateDateFormatFactory.java       |    7 +-
 src/main/java/freemarker/core/_CoreAPI.java     |   17 +
 .../freemarker/template/TemplateException.java  |    4 +
 .../java/freemarker/template/_TemplateAPI.java  |    5 +
 src/manual/book.xml                             |   19 +-
 .../java/freemarker/core/DateFormatTest.java    |  108 ++
 ...EpochMillisDivTemplateDateFormatFactory.java |    5 +-
 .../EpochMillisTemplateDateFormatFactory.java   |    5 +-
 ...AndTZSensitiveTemplateDateFormatFactory.java |    5 +-
 .../java/freemarker/core/NumberFormatTest.java  |    2 +-
 17 files changed, 1144 insertions(+), 721 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/19b6bf88/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/19b6bf88/src/main/java/freemarker/core/Environment.java
----------------------------------------------------------------------
diff --cc src/main/java/freemarker/core/Environment.java
index 86c01bd,1987353..d05a33a
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@@ -137,37 -140,36 +140,38 @@@ public final class Environment extends 
      private static final int CACHED_TDFS_ZONELESS_INPUT_OFFS = 4;
      private static final int CACHED_TDFS_SQL_D_T_TZ_OFFS = CACHED_TDFS_ZONELESS_INPUT_OFFS * 2;
      private static final int CACHED_TDFS_LENGTH = CACHED_TDFS_SQL_D_T_TZ_OFFS * 2;
-     
+ 
      /** Caches the result of {@link #isSQLDateAndTimeTimeZoneSameAsNormal()}. */
      private Boolean cachedSQLDateAndTimeTimeZoneSameAsNormal;
-     
+ 
      private NumberFormat cNumberFormat;
-     
+ 
      /**
       * Used by the "iso_" built-ins to accelerate formatting.
-      * @see #getISOBuiltInCalendarFactory() 
+      * 
+      * @see #getISOBuiltInCalendarFactory()
       */
      private DateToISO8601CalendarFactory isoBuiltInCalendarFactory;
-     
+ 
      private Collator cachedCollator;
  
 +    private Template currentTemplate;
 +    private Namespace currentNamespace;
 +    private CallableInvocationContext currentMacroContext;
 +    
      private Writer out;
-     private ArrayList localContextStack; 
 -    private Macro.Context currentMacroContext;
+     private ArrayList localContextStack;
      private final Namespace mainNamespace;
 -    private Namespace currentNamespace, globalNamespace;
 +    private Namespace globalNamespace;
      private HashMap loadedLibs;
      private Configurable legacyParent;
  
      private boolean inAttemptBlock;
      private Throwable lastThrowable;
-     
+ 
      private TemplateModel lastReturnValue;
 -    private HashMap macroToNamespaceLookup = new HashMap();
  
-     private TemplateNodeModel currentVisitorNode;    
+     private TemplateNodeModel currentVisitorNode;
      private TemplateSequenceModel nodeNamespaces;
      // Things we keep track of for the fallback mechanism.
      private int nodeNamespaceIndex;
@@@ -509,13 -511,8 +513,13 @@@
          TemplateElement nestedContent = invokingMacroContext.nestedContent;
          if (nestedContent != null) {
              this.currentMacroContext = invokingMacroContext.prevMacroContext;
 +            
 +            final Namespace prevCurrentNamespace = currentNamespace;  
              currentNamespace = invokingMacroContext.nestedContentNamespace;
-             
+ 
 +            final Template prevCurrentTemplate = currentTemplate;
 +            currentTemplate = invokingMacroContext.nestedContentTemplate;
 +            
              final Configurable prevParent;
              final boolean parentReplacementOn = isBeforeIcI2322();
              prevParent = getParent();
@@@ -585,10 -581,10 +589,10 @@@
          }
          try {
              TemplateModel macroOrTransform = getNodeProcessor(node);
 -            if (macroOrTransform instanceof Macro) {
 -                invoke((Macro) macroOrTransform, null, null, null, null);
 +            if (macroOrTransform instanceof BoundCallable) {
 +                invoke((BoundCallable) macroOrTransform, null, null, null, null);
              } else if (macroOrTransform instanceof TemplateTransformModel) {
-                 visitAndTransform(null, (TemplateTransformModel) macroOrTransform, null); 
+                 visitAndTransform(null, (TemplateTransformModel) macroOrTransform, null);
              } else {
                  String nodeType = node.getNodeType();
                  if (nodeType != null) {
@@@ -638,46 -634,42 +642,46 @@@
                  new _DelayedJQuote(node.getNodeName()), nsPrefix, ns,
                  ", and there is no fallback handler called @", nodeType, " either." };
      }
-     
+ 
      void fallback() throws TemplateException, IOException {
          TemplateModel macroOrTransform = getNodeProcessor(currentNodeName, currentNodeNS, nodeNamespaceIndex);
 -        if (macroOrTransform instanceof Macro) {
 -            invoke((Macro) macroOrTransform, null, null, null, null);
 +        if (macroOrTransform instanceof BoundCallable) {
 +            invoke((BoundCallable) macroOrTransform, null, null, null, null);
          } else if (macroOrTransform instanceof TemplateTransformModel) {
-             visitAndTransform(null, (TemplateTransformModel) macroOrTransform, null); 
+             visitAndTransform(null, (TemplateTransformModel) macroOrTransform, null);
          }
      }
-     
+ 
      /**
       * Calls the macro or function with the given arguments and nested block.
       */
 -    void invoke(Macro macro,
 +    void invoke(BoundCallable boundCallable, 
-                Map namedArgs, List positionalArgs, 
-                List bodyParameterNames, TemplateElement nestedBlock) throws TemplateException, IOException {
+             Map namedArgs, List positionalArgs,
+             List bodyParameterNames, TemplateElement nestedBlock) throws TemplateException, IOException {
 -        if (macro == Macro.DO_NOTHING_MACRO) {
 +        UnboundCallable unboundCallable = boundCallable.getUnboundCallable();
 +        if (unboundCallable == UnboundCallable.NO_OP_MACRO) {
              return;
          }
-         
+ 
 -        pushElement(macro);
 +        pushElement(unboundCallable);
          try {
 -            final Macro.Context macroCtx = macro.new Context(this, nestedBlock, bodyParameterNames);
 -            setMacroContextLocalsFromArguments(macroCtx, macro, namedArgs, positionalArgs);
 +            final CallableInvocationContext macroCtx = new CallableInvocationContext(unboundCallable, this, nestedBlock, bodyParameterNames);
 +            setMacroContextLocalsFromArguments(macroCtx, unboundCallable, namedArgs, positionalArgs);
-             
+ 
 -            final Macro.Context prevMacroCtx = currentMacroContext;
 +            final CallableInvocationContext prevMacroCtx = currentMacroContext;
              currentMacroContext = macroCtx;
-             
+ 
              final ArrayList prevLocalContextStack = localContextStack;
              localContextStack = null;
-             
+ 
 -            final Namespace prevNamespace = currentNamespace;
 -            currentNamespace = (Namespace) macroToNamespaceLookup.get(macro);
 +            final Namespace prevCurrentNamespace = currentNamespace;
 +            currentNamespace = boundCallable.getNamespace();
 +            
 +            final Template prevCurrentTemplate = currentTemplate;
 +            currentTemplate = boundCallable.getTemplate();
-             
+ 
              try {
 -                macroCtx.runMacro(this);
 +                macroCtx.invoce(this);
              } catch (ReturnInstruction.Return re) {
                  // Not an error, just a <#return>
              } catch (TemplateException te) {
@@@ -709,11 -700,11 +713,11 @@@
              } else {
                  catchAllParamValue = null;
              }
-             
-             for (Iterator it = namedArgs.entrySet().iterator(); it.hasNext(); ) {
+ 
+             for (Iterator it = namedArgs.entrySet().iterator(); it.hasNext();) {
                  final Map.Entry argNameAndValExp = (Map.Entry) it.next();
                  final String argName = (String) argNameAndValExp.getKey();
 -                final boolean isArgNameDeclared = macro.hasArgNamed(argName);
 +                final boolean isArgNameDeclared = unboundCallable.hasArgNamed(argName);
                  if (isArgNameDeclared || catchAllParamName != null) {
                      Expression argValueExp = (Expression) argNameAndValExp.getValue();
                      TemplateModel argValue = argValueExp.eval(this);
@@@ -736,12 -727,12 +740,12 @@@
              } else {
                  catchAllParamValue = null;
              }
-             
+ 
 -            String[] argNames = macro.getArgumentNamesInternal();
 +            String[] argNames = unboundCallable.getArgumentNamesInternal();
              final int argsCnt = positionalArgs.size();
              if (argNames.length < argsCnt && catchAllParamName == null) {
-                 throw new _MiscTemplateException(this, 
+                 throw new _MiscTemplateException(this,
 -                        (macro.isFunction() ? "Function " : "Macro "), new _DelayedJQuote(macro.getName()),
 +                        (unboundCallable.isFunction() ? "Function " : "Macro "), new _DelayedJQuote(unboundCallable.getName()),
                          " only accepts ", new _DelayedToString(argNames.length), " parameters, but got ",
                          new _DelayedToString(argsCnt), ".");
              }
@@@ -765,14 -756,17 +769,14 @@@
      /**
       * Defines the given macro in the current namespace (doesn't call it).
       */
 -    void visitMacroDef(Macro macro) {
 -        macroToNamespaceLookup.put(macro, currentNamespace);
 -        currentNamespace.put(macro.getName(), macro);
 -    }
 -
 -    Namespace getMacroNamespace(Macro macro) {
 -        return (Namespace) macroToNamespaceLookup.get(macro);
 +    void visitCallableDefinition(UnboundCallable unboundCallable) {
 +        currentNamespace.put(
 +                unboundCallable.getName(),
 +                new BoundCallable(unboundCallable, currentTemplate, currentNamespace));
      }
-     
+ 
      void recurse(TemplateNodeModel node, TemplateSequenceModel namespaces)
-     throws TemplateException, IOException {
+             throws TemplateException, IOException {
          if (node == null) {
              node = this.getCurrentVisitorNode();
              if (node == null) {
@@@ -790,12 -784,12 +794,12 @@@
          }
      }
  
 -    Macro.Context getCurrentMacroContext() {
 +    CallableInvocationContext getCurrentMacroContext() {
          return currentMacroContext;
      }
-     
+ 
      private void handleTemplateException(TemplateException templateException)
-         throws TemplateException {
+             throws TemplateException {
          // Logic to prevent double-handling of the exception in
          // nested visit() calls.
          if (lastThrowable == templateException) {
@@@ -2209,22 -2488,16 +2498,22 @@@
          } else {
              legacyParent = includedTemplate;
          }
-         
+ 
 -        importMacros(includedTemplate);
 +        final Template prevCurrentTemplate = currentTemplate;
          try {
 -            visit(includedTemplate.getRootTreeNode());
 -        } finally {
 -            if (parentReplacementOn) {
 -                setParent(prevTemplate);
 +            currentTemplate = includedTemplate;
 +            predefineCallables(includedTemplate);
 +            try {
 +                visit(includedTemplate.getRootTreeNode());
 +            } finally {
 +                if (parentReplacementOn) {
 +                    setParent(prevTemplate);
              } else {
                  legacyParent = prevTemplate;
 +                }
              }
 +        } finally {
 +            currentTemplate = prevCurrentTemplate;
          }
      }
  
@@@ -2474,16 -2740,10 +2763,16 @@@
          public Template getTemplate() {
              return template == null ? Environment.this.getTemplate() : template;
          }
 +        
 +        @Override
 +        public String toString() {
 +            return StringUtil.jQuote(template.getName()) + super.toString();
 +        }
 +        
      }
  
-      private static final Writer EMPTY_BODY_WRITER = new Writer() {
-     
+     private static final Writer EMPTY_BODY_WRITER = new Writer() {
+ 
          @Override
          public void write(char[] cbuf, int off, int len) throws IOException {
              if (len > 0) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/19b6bf88/src/main/java/freemarker/core/EvalUtil.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/19b6bf88/src/main/java/freemarker/core/_CoreAPI.java
----------------------------------------------------------------------
diff --cc src/main/java/freemarker/core/_CoreAPI.java
index 7ebe486,620edd8..bb8d0f1
--- a/src/main/java/freemarker/core/_CoreAPI.java
+++ b/src/main/java/freemarker/core/_CoreAPI.java
@@@ -31,9 -25,12 +31,13 @@@ import java.util.Map.Entry
  import java.util.Set;
  import java.util.TreeSet;
  
 +import freemarker.template.Configuration;
  import freemarker.template.Template;
  import freemarker.template.TemplateDirectiveBody;
+ import freemarker.template.TemplateException;
+ import freemarker.template.TemplateModel;
+ import freemarker.template.TemplateModelException;
+ import freemarker.template._TemplateAPI;
  import freemarker.template.utility.ClassUtil;
  
  

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/19b6bf88/src/main/java/freemarker/template/TemplateException.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/19b6bf88/src/main/java/freemarker/template/_TemplateAPI.java
----------------------------------------------------------------------
diff --cc src/main/java/freemarker/template/_TemplateAPI.java
index 8660c55,765383e..8ca2642
--- a/src/main/java/freemarker/template/_TemplateAPI.java
+++ b/src/main/java/freemarker/template/_TemplateAPI.java
@@@ -26,8 -25,9 +26,9 @@@ import freemarker.cache.CacheStorage
  import freemarker.cache.TemplateLoader;
  import freemarker.cache.TemplateLookupStrategy;
  import freemarker.cache.TemplateNameFormat;
+ import freemarker.core.Expression;
 -import freemarker.core.OutputFormat;
  import freemarker.core.TemplateObject;
 +import freemarker.core.UnboundTemplate;
  import freemarker.template.utility.NullArgumentException;
  
  /**