incubator-freemarker git commit: TemplateModel implementations that contain an ObjectWrapper (which itself is not Serializable) were marked as Serializable mistakenly.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 d4de527bc -> 78428211c


TemplateModel implementations that contain an ObjectWrapper (which itself is 
not Serializable) were marked as Serializable mistakenly.


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

Branch: refs/heads/3
Commit: 78428211cda3f959b3f704c610390421869b9a1b
Parents: d4de527
Author: ddekany 
Authored: Tue Aug 8 23:47:05 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 23:47:05 2017 +0200

--
 .../apache/freemarker/core/model/impl/DefaultArrayAdapter.java   | 3 +--
 .../freemarker/core/model/impl/DefaultEnumerationAdapter.java| 3 +--
 .../freemarker/core/model/impl/DefaultIterableAdapter.java   | 3 +--
 .../freemarker/core/model/impl/DefaultIteratorAdapter.java   | 3 +--
 .../apache/freemarker/core/model/impl/DefaultListAdapter.java| 3 +--
 .../org/apache/freemarker/core/model/impl/DefaultMapAdapter.java | 4 +---
 .../core/model/impl/DefaultNonListCollectionAdapter.java | 3 +--
 .../java/org/apache/freemarker/core/model/impl/SimpleHash.java   | 3 +--
 .../org/apache/freemarker/core/model/impl/SimpleSequence.java| 3 +--
 9 files changed, 9 insertions(+), 19 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/78428211/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultArrayAdapter.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultArrayAdapter.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultArrayAdapter.java
index fc310c3..b661fcc 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultArrayAdapter.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultArrayAdapter.java
@@ -19,7 +19,6 @@
 
 package org.apache.freemarker.core.model.impl;
 
-import java.io.Serializable;
 import java.lang.reflect.Array;
 
 import org.apache.freemarker.core.model.AdapterTemplateModel;
@@ -51,7 +50,7 @@ import org.apache.freemarker.core.model.WrappingTemplateModel;
  * @see TemplateSequenceModel
  */
 public abstract class DefaultArrayAdapter extends WrappingTemplateModel 
implements TemplateSequenceModel,
-AdapterTemplateModel, WrapperTemplateModel, Serializable {
+AdapterTemplateModel, WrapperTemplateModel {
 
 /**
  * Factory method for creating new adapter instances.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/78428211/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
index d5b6989..2149f8c 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultEnumerationAdapter.java
@@ -19,7 +19,6 @@
 
 package org.apache.freemarker.core.model.impl;
 
-import java.io.Serializable;
 import java.util.Enumeration;
 import java.util.Iterator;
 
@@ -43,7 +42,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
  */
 @SuppressWarnings("serial")
 public class DefaultEnumerationAdapter extends WrappingTemplateModel 
implements TemplateCollectionModel,
-AdapterTemplateModel, WrapperTemplateModel, 
TemplateModelWithAPISupport, Serializable {
+AdapterTemplateModel, WrapperTemplateModel, 
TemplateModelWithAPISupport {
 
 @SuppressFBWarnings(value="SE_BAD_FIELD", justification="We hope it's 
Seralizable")
 private final Enumeration enumeration;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/78428211/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultIterableAdapter.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultIterableAdapter.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultIterableAdapter.java
index b778573..1033a5f 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultIterableAdapter.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultIterableAdapter.java
@@ -19,

incubator-freemarker git commit: Got rid of _TemplateModelException-s on places where TemplateException or simple TemplateModelException can be used.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 22de04e9b -> d4de527bc


Got rid of _TemplateModelException-s on places where TemplateException or 
simple TemplateModelException can be used.


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

Branch: refs/heads/3
Commit: d4de527bc7672f4febc63a77cc75a38d42fc363e
Parents: 22de04e
Author: ddekany 
Authored: Tue Aug 8 23:15:40 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 23:15:40 2017 +0200

--
 .../core/APINotSupportedTemplateException.java  |  2 +-
 .../org/apache/freemarker/core/ASTDirList.java  |  6 +--
 .../freemarker/core/ASTDollarInterpolation.java |  3 +-
 .../apache/freemarker/core/ASTExpBuiltIn.java   | 33 +++---
 .../freemarker/core/BuiltInForSequence.java |  2 +-
 .../freemarker/core/BuiltInsForDates.java   |  3 +-
 .../freemarker/core/BuiltInsForSequences.java   | 46 ++--
 .../core/BuiltInsForStringsBasic.java   |  8 ++--
 .../core/BuiltInsForStringsEncoding.java|  6 +--
 .../core/BuiltInsForStringsRegexp.java  | 10 ++---
 .../org/apache/freemarker/core/Environment.java |  2 +-
 .../apache/freemarker/core/MessageUtils.java| 26 +--
 .../core/UnexpectedTypeException.java   |  2 +-
 .../core/_DelayedFTLTypeDescription.java| 37 
 ..._DelayedTemplateLanguageTypeDescription.java | 37 
 .../org/apache/freemarker/core/_EvalUtils.java  |  4 +-
 .../freemarker/core/model/impl/BeanModel.java   |  4 +-
 .../core/model/impl/DefaultObjectWrapper.java   |  6 +--
 .../core/model/impl/SimpleMethod.java   |  4 +-
 .../apache/freemarker/servlet/IncludePage.java  |  5 +--
 20 files changed, 123 insertions(+), 123 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d4de527b/freemarker-core/src/main/java/org/apache/freemarker/core/APINotSupportedTemplateException.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/APINotSupportedTemplateException.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/APINotSupportedTemplateException.java
index 732f5e2..a3761ad 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/APINotSupportedTemplateException.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/APINotSupportedTemplateException.java
@@ -34,7 +34,7 @@ class APINotSupportedTemplateException extends 
TemplateException {
 TemplateModel tm) {
 final _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder(
 "The value doesn't support ?api. See requirements in the 
FreeMarker Manual. ("
-+ "FTL type: ", new _DelayedFTLTypeDescription(tm),
++ "FTL type: ", new 
_DelayedTemplateLanguageTypeDescription(tm),
 ", TemplateModel class: ", new 
_DelayedShortClassName(tm.getClass()),
 ", ObjectWapper: ", new 
_DelayedToString(env.getObjectWrapper()), ")"
 ).blame(blamedExpr);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d4de527b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirList.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirList.java 
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirList.java
index 57120c2..7878e97 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirList.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirList.java
@@ -308,7 +308,7 @@ final class ASTDirList extends ASTDirective {
 && 
!NonSequenceOrCollectionException.isWrappedIterable(listedValue)) {
 throw new NonSequenceOrCollectionException(env,
 new _ErrorDescriptionBuilder("The value you try to 
list is ",
-new _DelayedAOrAn(new 
_DelayedFTLTypeDescription(listedValue)),
+new _DelayedAOrAn(new 
_DelayedTemplateLanguageTypeDescription(listedValue)),
 ", thus you must declare two nested content 
parameters after the \"as\"; one for the "
 + "key, and another for the value, like ", 
"<#... as k, v>", ")."
 ));
@@ -365,7 +365,7 @@ final class ASTDirList extends ASTDirective {
 + "implementations, 
all keys must be stri

incubator-freemarker git commit: Got rid of _MiscTemplateException; merged internal constructors into TemplateException.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 3f2743387 -> 22de04e9b


Got rid of _MiscTemplateException; merged internal constructors into 
TemplateException.


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

Branch: refs/heads/3
Commit: 22de04e9b90e837c176f8ba3aea75c90e1494cde
Parents: 3f27433
Author: ddekany 
Authored: Tue Aug 8 22:18:34 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 22:18:34 2017 +0200

--
 .../apache/freemarker/core/ASTDirImport.java|   4 +-
 .../apache/freemarker/core/ASTDirInclude.java   |   6 +-
 .../org/apache/freemarker/core/ASTDirItems.java |   2 +-
 .../org/apache/freemarker/core/ASTDirList.java  |   4 +-
 .../apache/freemarker/core/ASTDirRecurse.java   |   2 +-
 .../org/apache/freemarker/core/ASTDirSep.java   |   2 +-
 .../apache/freemarker/core/ASTDirSetting.java   |   2 +-
 .../org/apache/freemarker/core/ASTDirVisit.java |   2 +-
 .../freemarker/core/ASTDynamicTopLevelCall.java |   6 +-
 .../freemarker/core/ASTExpArithmetic.java   |   4 +-
 .../freemarker/core/ASTExpBuiltInVariable.java  |   2 +-
 .../freemarker/core/ASTExpDynamicKeyName.java   |  14 +--
 .../freemarker/core/ASTExpListLiteral.java  |   2 +-
 .../apache/freemarker/core/ASTExpVariable.java  |   2 +-
 .../core/BuiltInForNestedContentParameter.java  |   2 +-
 .../freemarker/core/BuiltInsForDates.java   |   2 +-
 .../core/BuiltInsForMultipleTypes.java  |   4 +-
 .../core/BuiltInsForStringsBasic.java   |   2 +-
 .../freemarker/core/BuiltInsForStringsMisc.java |  12 +-
 .../core/BuiltInsWithParseTimeParameters.java   |   2 +-
 .../org/apache/freemarker/core/Environment.java |  24 ++--
 .../apache/freemarker/core/MessageUtils.java|   6 +-
 .../freemarker/core/TemplateClassResolver.java  |   2 +-
 .../freemarker/core/TemplateException.java  | 119 --
 .../apache/freemarker/core/_CallableUtils.java  |  12 +-
 .../org/apache/freemarker/core/_EvalUtils.java  |  20 +--
 .../freemarker/core/_MiscTemplateException.java | 124 ---
 .../impl/ConservativeArithmeticEngine.java  |   7 +-
 .../core/util/OptInTemplateClassResolver.java   |   7 +-
 .../apache/freemarker/servlet/IncludePage.java  |  14 +--
 .../freemarker/servlet/jsp/JspTagModelBase.java |   3 +-
 31 files changed, 193 insertions(+), 223 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/22de04e9/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirImport.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirImport.java 
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirImport.java
index 79b320a..88cfeb5 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirImport.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirImport.java
@@ -51,7 +51,7 @@ final class ASTDirImport extends ASTDirective {
 try {
 fullImportedTemplateName = 
env.toFullTemplateName(getTemplate().getLookupName(), importedTemplateName);
 } catch (MalformedTemplateNameException e) {
-throw new _MiscTemplateException(e, env,
+throw new TemplateException(e, env,
 "Malformed template name ", new 
_DelayedJQuote(e.getTemplateName()), ":\n",
 e.getMalformednessDescription());
 }
@@ -59,7 +59,7 @@ final class ASTDirImport extends ASTDirective {
 try {
 env.importLib(fullImportedTemplateName, targetNsVarName);
 } catch (IOException e) {
-throw new _MiscTemplateException(e, env,
+throw new TemplateException(e, env,
 "Template importing failed (for parameter value ",
 new _DelayedJQuote(importedTemplateName),
 "):\n", new _DelayedGetMessage(e));

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/22de04e9/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirInclude.java 
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
index 169541b..37cc017 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirInclude.java
@@ -68,7 +68,7 @@ final class ASTDirInclude extends ASTDirective {
 try {
  

incubator-freemarker git commit: BeanModel shouldn't log "no such key" events, not even on debug level.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 a5ac9983f -> 3f2743387


BeanModel shouldn't log "no such key" events, not even on debug level.


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

Branch: refs/heads/3
Commit: 3f2743387d6c29a13a0766efd15056133db8ca50
Parents: a5ac998
Author: ddekany 
Authored: Tue Aug 8 20:05:50 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 20:05:50 2017 +0200

--
 .../org/apache/freemarker/core/model/impl/BeanModel.java | 11 ---
 1 file changed, 11 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/3f274338/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/BeanModel.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/BeanModel.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/BeanModel.java
index 4320251..65c3953 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/BeanModel.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/BeanModel.java
@@ -45,7 +45,6 @@ import org.apache.freemarker.core.model.TemplateModelIterator;
 import org.apache.freemarker.core.model.TemplateModelWithAPISupport;
 import org.apache.freemarker.core.model.TemplateScalarModel;
 import org.apache.freemarker.core.model.WrapperTemplateModel;
-import org.apache.freemarker.core.util._StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -145,8 +144,6 @@ public class BeanModel
 if (retval == UNKNOWN) {
 if (wrapper.isStrict()) {
 throw new InvalidPropertyException("No such bean property: 
" + key);
-} else {
-logNoSuchKey(key, classInfo);
 }
 retval = wrapper.wrap(null);
 }
@@ -162,14 +159,6 @@ public class BeanModel
 }
 }
 
-private void logNoSuchKey(String key, Map keyMap) {
-if (LOG.isDebugEnabled()) {
-LOG.debug("Key " + _StringUtils.jQuoteNoXSS(key) + " was not found 
on instance of " +
-object.getClass().getName() + ". Introspection information for 
" +
-"the class is: " + keyMap);
-}
-}
-
 /**
  * Whether the model has a plain get(String) or get(Object) method
  */



[2/2] incubator-freemarker git commit: Renamed `FTLUtil` to `TemplateLanguageUtils` (as the FTL name will be abandoned in FM3, and supporting multiple languages are planned in the future).

2017-08-08 Thread ddekany
Renamed `FTLUtil` to `TemplateLanguageUtils` (as the FTL name will be abandoned 
in FM3, and supporting multiple languages are planned in the future).


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

Branch: refs/heads/3
Commit: a5ac9983f22ca59fe465c937b3737badf293ba85
Parents: ebb39b8
Author: ddekany 
Authored: Tue Aug 8 20:02:53 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 20:02:53 2017 +0200

--
 FM3-CHANGE-LOG.txt  |   2 +
 .../core/FM2ASTToFM3SourceConverter.java|  43 +-
 .../org/apache/freemarker/core/ASTPrinter.java  |   4 +-
 .../templatesuite/models/OverloadedMethods.java |   6 +-
 .../core/userpkg/TestTemplateCallableModel.java |   4 +-
 .../freemarker/core/util/FTLUtilTest.java   | 128 ---
 .../core/util/TemplateLanguageUtilsTest.java| 128 +++
 .../freemarker/core/ASTDollarInterpolation.java |   4 +-
 .../freemarker/core/ASTExpStringLiteral.java|   6 +-
 .../core/MutableProcessingConfiguration.java|   4 +-
 .../apache/freemarker/core/_CallableUtils.java  |  10 +-
 .../core/_DelayedFTLTypeDescription.java|   4 +-
 .../core/_ObjectBuilderSettingEvaluator.java|   4 +-
 .../freemarker/core/model/TemplateModel.java|   4 +-
 .../core/model/impl/OverloadedMethods.java  |   4 +-
 .../apache/freemarker/core/util/FTLUtil.java| 872 ---
 .../core/util/TemplateLanguageUtils.java| 872 +++
 .../freemarker/core/util/_StringUtils.java  |  10 +-
 freemarker-core/src/main/javacc/FTL.jj  |   4 +-
 .../test/templateutil/AssertDirective.java  |   4 +-
 20 files changed, 1060 insertions(+), 1057 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a5ac9983/FM3-CHANGE-LOG.txt
--
diff --git a/FM3-CHANGE-LOG.txt b/FM3-CHANGE-LOG.txt
index 685160a..0d6a14b 100644
--- a/FM3-CHANGE-LOG.txt
+++ b/FM3-CHANGE-LOG.txt
@@ -469,6 +469,8 @@ Core / Miscellaneous
 - Removed `NestedContentNotSupportedException`, as 
`TemplateDirectiveModel.isNestedContentSupported()` now takes care
   of that problem.
 - CallPlaceCustomDataInitializationException is not a checked exception 
anymore (now it extends RuntimeException)
+- Renamed `FTLUtil` to `TemplateLanguageUtils` (as the FTL name will be 
abandoned in FM3, and supporting multiple
+  languages are planned in the future)
 
 
 Build / development process changes

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a5ac9983/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
--
diff --git 
a/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
 
b/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
index 1b171bd..2ff86e9 100644
--- 
a/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
+++ 
b/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
@@ -35,7 +35,7 @@ import org.apache.freemarker.converter.ConversionMarkers;
 import org.apache.freemarker.converter.ConverterException;
 import org.apache.freemarker.converter.ConverterUtils;
 import org.apache.freemarker.converter.UnconvertableLegacyFeatureException;
-import org.apache.freemarker.core.util.FTLUtil;
+import org.apache.freemarker.core.util.TemplateLanguageUtils;
 import org.apache.freemarker.core.util._ClassUtils;
 import org.apache.freemarker.core.util._NullArgumentException;
 import org.apache.freemarker.core.util._ObjectHolder;
@@ -461,7 +461,7 @@ public class FM2ASTToFM3SourceConverter {
 int paramIdx = 1;
 while (paramIdx < node.getParameterCount()) {
 String paramName = getParam(node, paramIdx++, 
ParameterRole.ARGUMENT_NAME, String.class);
-print(FTLUtil.escapeIdentifier(paramName));
+print(TemplateLanguageUtils.escapeIdentifier(paramName));
 pos = getPositionAfterIdentifier(pos);
 
 pos = printSeparatorAndWSAndExpComments(pos, "=");
@@ -592,7 +592,7 @@ public class FM2ASTToFM3SourceConverter {
 
 int pos = printDirStartTagPartBeforeParams(node, "setting");
 
-print(FTLUtil.escapeIdentifier(convertSettingName(
+print(TemplateLanguageUtils.escapeIdentifier(convertSettingName(
 getParam(node, 0, ParameterRole.ITEM_KEY, String.class),
 node)));
 pos = getPositionAfterIdentifier(pos);
@@ -676,11 +676,11 @@ public class FM2ASTToFM

[1/2] incubator-freemarker git commit: Renamed `FTLUtil` to `TemplateLanguageUtils` (as the FTL name will be abandoned in FM3, and supporting multiple languages are planned in the future).

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 ebb39b845 -> a5ac9983f


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/a5ac9983/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
new file mode 100644
index 000..061cf51
--- /dev/null
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/TemplateLanguageUtils.java
@@ -0,0 +1,872 @@
+/*
+ * 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.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.freemarker.core.Environment;
+import org.apache.freemarker.core._CoreAPI;
+import org.apache.freemarker.core.model.AdapterTemplateModel;
+import org.apache.freemarker.core.model.TemplateBooleanModel;
+import org.apache.freemarker.core.model.TemplateCallableModel;
+import org.apache.freemarker.core.model.TemplateCollectionModel;
+import org.apache.freemarker.core.model.TemplateCollectionModelEx;
+import org.apache.freemarker.core.model.TemplateDateModel;
+import org.apache.freemarker.core.model.TemplateDirectiveModel;
+import org.apache.freemarker.core.model.TemplateFunctionModel;
+import org.apache.freemarker.core.model.TemplateHashModel;
+import org.apache.freemarker.core.model.TemplateHashModelEx;
+import org.apache.freemarker.core.model.TemplateMarkupOutputModel;
+import org.apache.freemarker.core.model.TemplateModel;
+import org.apache.freemarker.core.model.TemplateModelIterator;
+import org.apache.freemarker.core.model.TemplateNodeModel;
+import org.apache.freemarker.core.model.TemplateNodeModelEx;
+import org.apache.freemarker.core.model.TemplateNumberModel;
+import org.apache.freemarker.core.model.TemplateScalarModel;
+import org.apache.freemarker.core.model.TemplateSequenceModel;
+import org.apache.freemarker.core.model.WrapperTemplateModel;
+import org.apache.freemarker.core.model.impl.BeanAndStringModel;
+import org.apache.freemarker.core.model.impl.BeanModel;
+import org.apache.freemarker.core.model.impl.JavaMethodModel;
+
+/**
+ * Static utility methods that perform tasks specific to the FreeMarker 
Template Language (FTL).
+ * This is meant to be used from outside FreeMarker (i.e., it's an official, 
published API), not just from inside it.
+ */
+// TODO [FM3] This name won't be good if the template language isn't called 
"FTL"...
+public final class TemplateLanguageUtils {
+
+private static final char[] ESCAPES = createEscapes();
+
+private TemplateLanguageUtils() {
+// Not meant to be instantiated
+}
+
+private static char[] createEscapes() {
+char[] escapes = new char['\\' + 1];
+for (int i = 0; i < 32; ++i) {
+escapes[i] = 1;
+}
+escapes['\\'] = '\\';
+escapes['\''] = '\'';
+escapes['"'] = '"';
+escapes['<'] = 'l';
+escapes['>'] = 'g';
+escapes['&'] = 'a';
+escapes['\b'] = 'b';
+escapes['\t'] = 't';
+escapes['\n'] = 'n';
+escapes['\f'] = 'f';
+escapes['\r'] = 'r';
+return escapes;
+}
+
+/**
+ * Escapes a string according the FTL string literal escaping rules, 
assuming the literal is quoted with
+ * {@code quotation}; it doesn't add the quotation marks themselves. 
{@code '&'}, {@code '<'}, and {@code '>'}
+ * characters will be escaped.
+ *
+ * @param quotation Either {@code '"'} or {@code '\''}. It's assumed that 
the string literal whose part we calculate is
+ *  enclosed within this kind of quotation mark. Thus, the 
other kind of quotation character will not be
+ *  escaped in the result.
+ */
+public static String escapeStringLiteralPart(String s, char quotation) {
+return escapeStringLiteralPart(s, quotation, false, true, true, true);
+}
+
+/**
+ * Escapes a string according the FTL string literal escaping rules, 
assuming the litera

[02/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtil.java
--
diff --git 
a/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtil.java 
b/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtil.java
deleted file mode 100644
index f5b58f8..000
--- a/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtil.java
+++ /dev/null
@@ -1,67 +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.dom;
-
-/**
- * For internal use only; don't depend on this, there's no backward 
compatibility guarantee at all!
- * This class is to work around the lack of module system in Java, i.e., so 
that other FreeMarker packages can
- * access things inside this package that users shouldn't. 
- */
-final class DomStringUtil {
-
-private DomStringUtil() {
-// Not meant to be instantiated
-}
-
-static boolean isXMLNameLike(String name) {
-return isXMLNameLike(name, 0);
-}
-
-/**
- * Check if the name looks like an XML element name.
- * 
- * @param firstCharIdx The index of the character in the string parameter 
that we treat as the beginning of the
- *  string to check. This is to spare substringing that has become 
more expensive in Java 7.  
- * 
- * @return whether the name is a valid XML element name. (This routine 
might only be 99% accurate. REVISIT)
- */
-static boolean isXMLNameLike(String name, int firstCharIdx) {
-int ln = name.length();
-for (int i = firstCharIdx; i < ln; i++) {
-char c = name.charAt(i);
-if (i == firstCharIdx && (c == '-' || c == '.' || 
Character.isDigit(c))) {
-return false;
-}
-if (!Character.isLetterOrDigit(c) && c != '_' && c != '-' && c != 
'.') {
-if (c == ':') {
-if (i + 1 < ln && name.charAt(i + 1) == ':') {
-// "::" is used in XPath
-return false;
-}
-// We don't return here, as a lonely ":" is allowed.
-} else {
-return false;
-}
-}
-}
-return true;
-}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtils.java
--
diff --git 
a/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtils.java 
b/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtils.java
new file mode 100644
index 000..b796c1e
--- /dev/null
+++ b/freemarker-dom/src/main/java/org/apache/freemarker/dom/DomStringUtils.java
@@ -0,0 +1,67 @@
+/*
+ * 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.dom;
+
+/**
+ * For internal use only; don't depend on this, there's no backward 
compatibility guarantee at all!
+ * This class is to work around the lack of module system in Java, i.e., so 
that other FreeMarker packages can
+ * access things inside this package that users shouldn't. 
+ */
+final class DomStringUtils {
+
+private DomStringUtils() {
+// Not meant to be instantiated
+}
+
+st

[03/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
new file mode 100644
index 000..9218005
--- /dev/null
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtils.java
@@ -0,0 +1,1625 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+
+import org.apache.freemarker.core.Environment;
+import org.apache.freemarker.core.Template;
+import org.apache.freemarker.core.Version;
+
+/** Don't use this; used internally by FreeMarker, might changes without 
notice. */
+public class _StringUtils {
+
+private static final char[] LT = new char[] { '&', 'l', 't', ';' };
+private static final char[] GT = new char[] { '&', 'g', 't', ';' };
+private static final char[] AMP = new char[] { '&', 'a', 'm', 'p', ';' };
+private static final char[] QUOT = new char[] { '&', 'q', 'u', 'o', 't', 
';' };
+private static final char[] HTML_APOS = new char[] { '&', '#', '3', '9', 
';' };
+private static final char[] XML_APOS = new char[] { '&', 'a', 'p', 'o', 
's', ';' };
+
+/**
+ *  XML Encoding.
+ *  Replaces all '>' '<' '&', "'" and '"' with entity reference
+ */
+public static String XMLEnc(String s) {
+return XMLOrHTMLEnc(s, true, true, XML_APOS);
+}
+
+/**
+ * Like {@link #XMLEnc(String)}, but writes the result into a {@link 
Writer}.
+ */
+public static void XMLEnc(String s, Writer out) throws IOException {
+XMLOrHTMLEnc(s, XML_APOS, out);
+}
+
+/**
+ *  XHTML Encoding.
+ *  Replaces all '>' '<' '&', "'" and '"' with entity reference
+ *  suitable for XHTML decoding in common user agents (including legacy
+ *  user agents, which do not decode "'" to "'", so "'" 
is used
+ *  instead [see http://www.w3.org/TR/xhtml1/#C_16])
+ */
+public static String XHTMLEnc(String s) {
+return XMLOrHTMLEnc(s, true, true, HTML_APOS);
+}
+
+/**
+ * Like {@link #XHTMLEnc(String)}, but writes the result into a {@link 
Writer}.
+ */
+public static void XHTMLEnc(String s, Writer out) throws IOException {
+XMLOrHTMLEnc(s, HTML_APOS, out);
+}
+
+private static String XMLOrHTMLEnc(String s, boolean escGT, boolean 
escQuot, char[] apos) {
+final int ln = s.length();
+
+// First we find out if we need to escape, and if so, what the length 
of the output will be:
+int firstEscIdx = -1;
+int lastEscIdx = 0;
+int plusOutLn = 0;
+for (int i = 0; i < ln; i++) {
+escape: do {
+final char c = s.charAt(i);
+switch (c) {
+case '<':
+plusOutLn += LT.length - 1;
+break;
+case '>':
+if (!(escGT || maybeCDataEndGT(s, i))) {
+break escape;
+}
+plusOutLn += GT.length - 1;
+break;
+case '&':
+plusOutLn += AMP.length - 1;
+break;
+case '"':
+if (!escQuot) {
+break escape;
+}
+plusOutLn += QUOT.length - 1;
+break;
+case '\'': // apos
+if (apos == null) {
+break escape;
+}
+plusOutLn += apos.length - 1;
+break;
+default:
+break escape;
+

[06/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/util/_CollectionUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_CollectionUtils.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_CollectionUtils.java
new file mode 100644
index 000..5801f2e
--- /dev/null
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_CollectionUtils.java
@@ -0,0 +1,220 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Don't use this; used internally by FreeMarker, might changes without notice.
+ * {@link Collection} and {@link Map}-related utilities.
+ */
+public class _CollectionUtils {
+
+private _CollectionUtils() { }
+
+public static final Object[] EMPTY_OBJECT_ARRAY = new Object[] { };
+public static final Class[] EMPTY_CLASS_ARRAY = new Class[] { };
+public static final String[] EMPTY_STRING_ARRAY = new String[] { };
+public static final char[] EMPTY_CHAR_ARRAY = new char[] { };
+
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public static  List safeCastList(
+String argName, List list,
+Class itemClass, boolean allowNullItem) {
+if (list == null) {
+return null;
+}
+for (int i = 0; i < list.size(); i++) {
+Object it = list.get(i);
+if (!itemClass.isInstance(it)) {
+if (it == null) {
+if (!allowNullItem) {
+throw new IllegalArgumentException(
+(argName != null ? "Invalid value for argument 
\"" + argName + "\"" : "")
++ "List item at index " + i + " is null");
+}
+} else {
+throw new IllegalArgumentException(
+(argName != null ? "Invalid value for argument \"" 
+ argName + "\"" : "")
++ "List item at index " + i + " is not instance of 
" + itemClass.getName() + "; "
++ "its class is " + it.getClass().getName() + ".");
+}
+}
+}
+
+return list;
+}
+
+@SuppressWarnings({ "rawtypes", "unchecked" })
+public static  Map safeCastMap(
+String argName, Map map,
+Class keyClass, boolean allowNullKey,
+Class valueClass, boolean allowNullValue) {
+if (map == null) {
+return null;
+}
+for (Map.Entry ent : ((Map) map).entrySet()) {
+Object key = ent.getKey();
+if (!keyClass.isInstance(key)) {
+if (key == null) {
+if (!allowNullKey) {
+throw new IllegalArgumentException(
+(argName != null ? "Invalid value for argument 
\"" + argName + "\": " : "")
++ "The Map contains null key");
+}
+} else {
+throw new IllegalArgumentException(
+(argName != null ? "Invalid value for argument \"" 
+ argName + "\": " : "")
++ "The Map contains a key that's not 
instance of " + keyClass.getName() +
+"; its class is " + 
key.getClass().getName() + ".");
+}
+}
+
+Object value = ent.getValue();
+if (!valueClass.isInstance(value)) {
+if (value == null) {
+if (!allowNullValue) {
+throw new IllegalArgumentException(
+(argName != null ? "Invalid value for argument 
\"" + argName + "\"" : "")
+   

[11/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java 
b/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java
new file mode 100644
index 000..3ce73b8
--- /dev/null
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java
@@ -0,0 +1,344 @@
+/*
+ * 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 java.util.ArrayList;
+
+import org.apache.freemarker.core.model.TemplateModel;
+import org.apache.freemarker.core.model.TemplateModelException;
+import org.apache.freemarker.core.util._StringUtils;
+import org.apache.freemarker.core.valueformat.TemplateDateFormat;
+import org.apache.freemarker.core.valueformat.TemplateNumberFormat;
+import org.apache.freemarker.core.valueformat.TemplateValueFormatException;
+import 
org.apache.freemarker.core.valueformat.UnknownDateTypeFormattingUnsupportedException;
+
+/**
+ * Utilities for creating error messages (and other messages).
+ */
+class MessageUtils {
+
+static final String UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE
+= "Can't convert the date-like value to string because it isn't "
+  + "known if it's a date (no time part), time or date-time 
value.";
+
+static final String UNKNOWN_DATE_TYPE_ERROR_TIP =
+"Use ?date, ?time, or ?dateTime to tell FreeMarker the exact 
type.";
+
+static final Object[] UNKNOWN_DATE_TO_STRING_TIPS = {
+UNKNOWN_DATE_TYPE_ERROR_TIP,
+"If you need a particular format only once, use ?string(pattern), 
like ?string('dd.MM. HH:mm:ss'), "
++ "to specify which fields to display. "
+};
+
+static final String FM3_SNAKE_CASE = "\nThe name contains '_' character, 
but since FreeMarker 3 names defined "
++ "by the template language use camel case (e.g. 
someExampleName).";
+
+static final String EMBEDDED_MESSAGE_BEGIN = "---begin-message---\n";
+
+static final String EMBEDDED_MESSAGE_END = "\n---end-message---";
+
+static final String ERROR_MESSAGE_HR = "";
+
+// Can't be instantiated
+private MessageUtils() { }
+
+static String formatLocationForSimpleParsingError(Template template, int 
line, int column) {
+return formatLocation("in", template, line, column);
+}
+
+static String formatLocationForSimpleParsingError(String 
templateSourceOrLookupName, int line, int column) {
+return formatLocation("in", templateSourceOrLookupName, line, column);
+}
+
+static String formatLocationForEvaluationError(Template template, int 
line, int column) {
+return formatLocation("at", template, line, column);
+}
+
+static String formatLocationForEvaluationError(ASTDirMacroOrFunction 
macro, int line, int column) {
+Template t = macro.getTemplate();
+return formatLocation("at", t != null ? t.getSourceOrLookupName() : 
null, macro.getName(), macro.isFunction(),
+line, column);
+}
+
+private static String formatLocation(String preposition, Template 
template, int line, int column) {
+return formatLocation(preposition, template != null ? 
template.getSourceOrLookupName() : null, line, column);
+}
+
+private static String formatLocation(String preposition, String 
templateSourceName, int line, int column) {
+return formatLocation(
+preposition, templateSourceName,
+null, false,
+line, column);
+}
+
+private static String formatLocation(
+String preposition, String templateSourceName,
+String macroOrFuncName, boolean isFunction,
+int line, int column) {
+String templateDesc;
+if (line < 0) {
+templateDesc = "?eval-ed string";
+macroOrFuncName = null;
+} else {
+templateDesc = templateSourceName != null
+? "template " + _StringUtils.jQuoteNoXSS(templateSourceName)
+   

[15/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core-test/src/test/java/org/apache/freemarker/core/templatesuite/models/OverloadedMethods2.java
--
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/templatesuite/models/OverloadedMethods2.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/templatesuite/models/OverloadedMethods2.java
index e9084c9..495a72e 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/templatesuite/models/OverloadedMethods2.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/templatesuite/models/OverloadedMethods2.java
@@ -38,8 +38,8 @@ import 
org.apache.freemarker.core.model.TemplateModelException;
 import org.apache.freemarker.core.model.TemplateNumberModel;
 import org.apache.freemarker.core.model.WrapperTemplateModel;
 import org.apache.freemarker.core.model.impl.RationalNumber;
-import org.apache.freemarker.core.util._StringUtil;
-import org.apache.freemarker.test.TestUtil;
+import org.apache.freemarker.core.util._StringUtils;
+import org.apache.freemarker.test.TestUtils;
 
 public class OverloadedMethods2 {
 
@@ -321,80 +321,80 @@ public class OverloadedMethods2 {
 }
 
 public String varargs1(String s, int... xs) {
-return "varargs1(String s = " + _StringUtil.jQuote(s) + ", int... xs = 
" + TestUtil.arrayToString(xs) + ")";
+return "varargs1(String s = " + _StringUtils.jQuote(s) + ", int... xs 
= " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs1(String s, double... xs) {
-return "varargs1(String s = " + _StringUtil.jQuote(s) + ", double... 
xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs1(String s = " + _StringUtils.jQuote(s) + ", double... 
xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs1(String s, Object... xs) {
-return "varargs1(String s = " + _StringUtil.jQuote(s) + ", Object... 
xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs1(String s = " + _StringUtils.jQuote(s) + ", Object... 
xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs1(Object s, Object... xs) {
-return "varargs1(Object s = " + s + ", Object... xs = " + 
TestUtil.arrayToString(xs) + ")";
+return "varargs1(Object s = " + s + ", Object... xs = " + 
TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs2(int... xs) {
-return "varargs2(int... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs2(int... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs2(double... xs) {
-return "varargs2(double... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs2(double... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs3(String... xs) {
-return "varargs3(String... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs3(String... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs3(Comparable... xs) {
-return "varargs3(Comparable... xs = " + TestUtil.arrayToString(xs) + 
")";
+return "varargs3(Comparable... xs = " + TestUtils.arrayToString(xs) + 
")";
 }
 
 public String varargs3(Object... xs) {
-return "varargs3(Object... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs3(Object... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs4(Integer... xs) {
-return "varargs4(Integer... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs4(Integer... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs4(int... xs) {
-return "varargs4(int... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs4(int... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs5(int... xs) {
-return "varargs5(int... xs = " + TestUtil.arrayToString(xs) + ")";
+return "varargs5(int... xs = " + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs5(int a1, int... xs) {
-return "varargs5(int a1 = " + a1 + ", int... xs = " + 
TestUtil.arrayToString(xs) + ")";
+return "varargs5(int a1 = " + a1 + ", int... xs = " + 
TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs5(int a1, int a2, int... xs) {
-return "varargs5(int a1 = " + a1 + ", int a2 = " + a2 + ", int... xs = 
" + TestUtil.arrayToString(xs) + ")";
+return "varargs5(int a1 = " + a1 + ", int a2 = " + a2 + ", int... xs = 
" + TestUtils.arrayToString(xs) + ")";
 }
 
 public String varargs5(int a1, int a2, int a3, int... xs) {
 return "varargs5(int a1 = " + a1 + ", int a2 = " + a2 + ", int a3 = " 
+ a3
-+ ", int... xs = " + TestUtil.arrayToString(xs) + ")";
+  

[09/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapper.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapper.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapper.java
index 9d797ce..709fe81 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapper.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapper.java
@@ -68,7 +68,7 @@ import org.apache.freemarker.core.model.TemplateSequenceModel;
 import org.apache.freemarker.core.model.WrapperTemplateModel;
 import org.apache.freemarker.core.util.BugException;
 import org.apache.freemarker.core.util.CommonBuilder;
-import org.apache.freemarker.core.util._ClassUtil;
+import org.apache.freemarker.core.util._ClassUtils;
 import org.apache.freemarker.core.util._NullArgumentException;
 
 /**
@@ -561,7 +561,7 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 Object res = tryUnwrapTo(model, targetClass, typeFlags, null);
 if ((typeFlags & TypeFlags.WIDENED_NUMERICAL_UNWRAPPING_HINT) != 0
 && res instanceof Number) {
-return OverloadedNumberUtil.addFallbackType((Number) res, 
typeFlags);
+return OverloadedNumberUtils.addFallbackType((Number) res, 
typeFlags);
 } else {
 return res;
 }
@@ -578,7 +578,7 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 }
 
 if (targetClass.isPrimitive()) {
-targetClass = _ClassUtil.primitiveClassToBoxingClass(targetClass);
+targetClass = _ClassUtils.primitiveClassToBoxingClass(targetClass);
 }
 
 // This is for transparent interop with other wrappers (and ourselves)
@@ -592,7 +592,7 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 }
 
 // Attempt numeric conversion:
-if (targetClass != Object.class && (wrapped instanceof Number && 
_ClassUtil.isNumerical(targetClass))) {
+if (targetClass != Object.class && (wrapped instanceof Number && 
_ClassUtils.isNumerical(targetClass))) {
 Number number = forceUnwrappedNumberToType((Number) wrapped, 
targetClass);
 if (number != null) return number;
 }
@@ -605,7 +605,7 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 }
 
 // Attempt numeric conversion:
-if (targetClass != Object.class && (wrapped instanceof Number && 
_ClassUtil.isNumerical(targetClass))) {
+if (targetClass != Object.class && (wrapped instanceof Number && 
_ClassUtils.isNumerical(targetClass))) {
 Number number = forceUnwrappedNumberToType((Number) wrapped, 
targetClass);
 if (number != null) {
 return number;
@@ -629,7 +629,7 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 }
 
 // Primitive numeric types & Number.class and its subclasses
-if (_ClassUtil.isNumerical(targetClass)) {
+if (_ClassUtils.isNumerical(targetClass)) {
 if (model instanceof TemplateNumberModel) {
 Number number = forceUnwrappedNumberToType(
 ((TemplateNumberModel) model).getAsNumber(), 
targetClass);
@@ -861,7 +861,7 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 if (listItem != null && !componentType.isInstance(listItem)) {
 // Type conversion is needed. If we can't do it, we just 
let it fail at Array.set later.
 if (!isComponentTypeExamined) {
-isComponentTypeNumerical = 
_ClassUtil.isNumerical(componentType);
+isComponentTypeNumerical = 
_ClassUtils.isNumerical(componentType);
 isComponentTypeList = 
List.class.isAssignableFrom(componentType);
 isComponentTypeExamined = true;
 }
@@ -889,10 +889,10 @@ public class DefaultObjectWrapper implements 
RichObjectWrapper {
 Array.set(array, i, listItem);
 } catch (IllegalArgumentException e) {
 throw new TemplateModelException(
-"Failed to convert " + 
_ClassUtil.getShortClassNameOfObject(list)
-+ " object to " + 
_ClassUtil.getShortClassNameOfObject(array)
+"Failed to convert " + 
_ClassUtils.getShortClassNameOfObject(list)
++ " object to " + 
_ClassUtils.getShortClassNameOfObject(array)
 + ": Problematic List 

[12/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java
index b1bd1dd..6632654 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForMultipleTypes.java
@@ -60,7 +60,7 @@ class BuiltInsForMultipleTypes {
 return formatNumber(env, model);
 } else if (model instanceof TemplateBooleanModel) {
 return new SimpleScalar(((TemplateBooleanModel) 
model).getAsBoolean()
-? MiscUtil.C_TRUE : MiscUtil.C_FALSE);
+? TemplateBooleanFormat.C_TRUE : 
TemplateBooleanFormat.C_FALSE);
 } else {
 throw new UnexpectedTypeException(
 target, model,
@@ -71,7 +71,7 @@ class BuiltInsForMultipleTypes {
 
 @Override
 protected TemplateModel formatNumber(Environment env, TemplateModel 
model) throws TemplateModelException {
-Number num = _EvalUtil.modelToNumber((TemplateNumberModel) model, 
target);
+Number num = _EvalUtils.modelToNumber((TemplateNumberModel) model, 
target);
 if (num instanceof Integer || num instanceof Long) {
 // Accelerate these fairly common cases
 return new SimpleScalar(num.toString());
@@ -514,7 +514,7 @@ class BuiltInsForMultipleTypes {
 defaultFormat = dateType == TemplateDateModel.UNKNOWN
 ? null  // Lazy unknown type error in getAsString()
 : env.getTemplateDateFormat(
-dateType, _EvalUtil.modelToDate(dateModel, 
target).getClass(), target, true);
+dateType, _EvalUtils.modelToDate(dateModel, 
target).getClass(), target, true);
 }
 
 @Override
@@ -550,16 +550,16 @@ class BuiltInsForMultipleTypes {
 if (cachedValue == null) {
 if (defaultFormat == null) {
 if (dateModel.getDateType() == 
TemplateDateModel.UNKNOWN) {
-throw 
MessageUtil.newCantFormatUnknownTypeDateException(target, null);
+throw 
MessageUtils.newCantFormatUnknownTypeDateException(target, null);
 } else {
 throw new BugException();
 }
 }
 try {
-cachedValue = 
_EvalUtil.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel));
+cachedValue = 
_EvalUtils.assertFormatResultNotNull(defaultFormat.formatToPlainText(dateModel));
 } catch (TemplateValueFormatException e) {
 try {
-throw 
MessageUtil.newCantFormatDateException(defaultFormat, target, e, true);
+throw 
MessageUtils.newCantFormatDateException(defaultFormat, target, e, true);
 } catch (TemplateException e2) {
 // `e` should always be a TemplateModelException 
here, but to be sure: 
 throw 
_CoreAPI.ensureIsTemplateModelException("Failed to format date/time/dateTime", 
e2);
@@ -587,7 +587,7 @@ class BuiltInsForMultipleTypes {
 
 // As we format lazily, we need a snapshot of the format 
inputs:
 this.numberModel = numberModel;
-number = _EvalUtil.modelToNumber(numberModel, target);  // for 
BackwardCompatibleTemplateNumberFormat-s
+number = _EvalUtils.modelToNumber(numberModel, target);  // 
for BackwardCompatibleTemplateNumberFormat-s
 try {
 defaultFormat = env.getTemplateNumberFormat(stringBI.this, 
true);
 } catch (TemplateException e) {
@@ -652,7 +652,7 @@ class BuiltInsForMultipleTypes {
 TemplateModel model = target.eval(env);
 if (model instanceof TemplateNumberModel) {
 TemplateNumberModel numberModel = (TemplateNumberModel) model;
-Number num = _EvalUtil.modelToNumber(numberModel, target);
+Number num = _EvalUtils.modelToNumber(numberModel, target);
 return new NumberFormatter(numberModel, env);
 } else if (model instanceof TemplateDateModel) {
 TemplateDateModel dm = (TemplateDateModel) model;
@@ -688,7 +688,7 @@ class BuiltInsForMultipleTypes {
 return formatNumber(env, model);
 } else if (mo

[17/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
Renamed XxxUtil classes to XxxUtils, as this convention is more widespread 
nowadays.


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

Branch: refs/heads/3
Commit: ebb39b8457918dcf58211edeb45e6eaaf6e0b0dc
Parents: cfd3796
Author: ddekany 
Authored: Tue Aug 8 19:56:35 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 19:56:35 2017 +0200

--
 .../core/FM2ASTToFM3SourceConverter.java|   22 +-
 .../core/UnexpectedNodeContentException.java|6 +-
 .../apache/freemarker/converter/Converter.java  |4 +-
 .../freemarker/converter/ConverterUtilTest.java |   24 -
 .../org/apache/freemarker/core/ASTPrinter.java  |   10 +-
 .../org/apache/freemarker/core/ASTTest.java |8 +-
 .../freemarker/core/ConfigurationTest.java  |   10 +-
 .../freemarker/core/CoreLocaleUtilsTest.java|   22 +-
 ...leParsingAndProcessingConfigurationTest.java |4 +-
 .../MutableProcessingConfigurationTest.java |   30 +-
 .../core/ParsingErrorMessagesTest.java  |6 +-
 .../apache/freemarker/core/SQLTimeZoneTest.java |   10 +-
 .../core/TagSyntaxVariationsTest.java   |6 +-
 .../DefaultObjectWrapperSingletonsTest.java |4 +-
 .../core/model/impl/IsApplicableTest.java   |2 +-
 .../impl/IsMoreSpecificParameterTypeTest.java   |  100 +-
 .../model/impl/MiscNumericalOperationsTest.java |2 +-
 .../model/impl/ModelAPINewInstanceTest.java |6 +-
 .../model/impl/OverloadedNumberUtilTest.java|  585 ---
 .../model/impl/OverloadedNumberUtilsTest.java   |  585 +++
 .../impl/ParameterListPreferabilityTest.java|   12 +-
 .../templatesuite/models/JavaObjectInfo.java|4 +-
 .../models/OverloadedMethods2.java  |  146 +-
 .../BaseNTemplateNumberFormatFactory.java   |   10 +-
 .../core/userpkg/CustomHTMLOutputFormat.java|4 +-
 ...EpochMillisDivTemplateDateFormatFactory.java |4 +-
 .../HTMLISOTemplateDateFormatFactory.java   |   18 +-
 .../userpkg/HexTemplateNumberFormatFactory.java |4 +-
 .../PrintfGTemplateNumberFormatFactory.java |4 +-
 .../core/userpkg/TestTemplateCallableModel.java |4 +-
 .../core/util/CollectionUtilTest.java   |   43 -
 .../core/util/CollectionUtilsTest.java  |   43 +
 .../freemarker/core/util/DateUtilTest.java  | 1085 
 .../freemarker/core/util/DateUtilsTest.java | 1085 
 .../freemarker/core/util/NumberUtilTest.java|  215 ---
 .../freemarker/core/util/NumberUtilsTest.java   |  215 +++
 .../freemarker/core/util/StringUtilTest.java|  416 -
 .../freemarker/core/util/StringUtilsTest.java   |  416 +
 .../org/apache/freemarker/core/ASTComment.java  |4 +-
 .../freemarker/core/ASTDirAssignment.java   |6 +-
 .../apache/freemarker/core/ASTDirEscape.java|4 +-
 .../apache/freemarker/core/ASTDirImport.java|4 +-
 .../apache/freemarker/core/ASTDirInclude.java   |4 +-
 .../org/apache/freemarker/core/ASTDirItems.java |6 +-
 .../org/apache/freemarker/core/ASTDirList.java  |6 +-
 .../freemarker/core/ASTDirMacroOrFunction.java  |   14 +-
 .../apache/freemarker/core/ASTDirSetting.java   |   10 +-
 .../apache/freemarker/core/ASTDirSwitch.java|4 +-
 .../freemarker/core/ASTDollarInterpolation.java |2 +-
 .../freemarker/core/ASTDynamicTopLevelCall.java |   12 +-
 .../freemarker/core/ASTExpAddOrConcat.java  |   16 +-
 .../freemarker/core/ASTExpArithmetic.java   |2 +-
 .../freemarker/core/ASTExpBooleanLiteral.java   |4 +-
 .../apache/freemarker/core/ASTExpBuiltIn.java   |   76 +-
 .../freemarker/core/ASTExpBuiltInVariable.java  |8 +-
 .../freemarker/core/ASTExpComparison.java   |   14 +-
 .../org/apache/freemarker/core/ASTExpDot.java   |4 +-
 .../freemarker/core/ASTExpDynamicKeyName.java   |2 +-
 .../freemarker/core/ASTExpFunctionCall.java |4 +-
 .../freemarker/core/ASTExpStringLiteral.java|4 +-
 .../apache/freemarker/core/ASTExpVariable.java  |4 +-
 .../apache/freemarker/core/ASTExpression.java   |   14 +-
 .../org/apache/freemarker/core/ASTNode.java |4 +-
 .../apache/freemarker/core/ASTStaticText.java   |   20 +-
 .../apache/freemarker/core/BuiltInForDate.java  |2 +-
 .../core/BuiltInForLegacyEscaping.java  |2 +-
 .../freemarker/core/BuiltInsForDates.java   |   18 +-
 .../core/BuiltInsForMultipleTypes.java  |   18 +-
 .../freemarker/core/BuiltInsForNodes.java   |4 +-
 .../freemarker/core/BuiltInsForNumbers.java |   16 +-
 .../core/BuiltInsForOutputFormatRelated.java|2 +-
 .../freemarker/core/BuiltInsForSequences.java   |   16 +-
 .../core/BuiltInsForStringsBas

[10/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/_EvalUtil.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/_EvalUtil.java 
b/freemarker-core/src/main/java/org/apache/freemarker/core/_EvalUtil.java
deleted file mode 100644
index 727085f..000
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/_EvalUtil.java
+++ /dev/null
@@ -1,545 +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 java.util.Date;
-
-import org.apache.freemarker.core.arithmetic.ArithmeticEngine;
-import org.apache.freemarker.core.arithmetic.impl.BigDecimalArithmeticEngine;
-import org.apache.freemarker.core.model.TemplateBooleanModel;
-import org.apache.freemarker.core.model.TemplateCollectionModel;
-import org.apache.freemarker.core.model.TemplateDateModel;
-import org.apache.freemarker.core.model.TemplateMarkupOutputModel;
-import org.apache.freemarker.core.model.TemplateModel;
-import org.apache.freemarker.core.model.TemplateModelException;
-import org.apache.freemarker.core.model.TemplateNumberModel;
-import org.apache.freemarker.core.model.TemplateScalarModel;
-import org.apache.freemarker.core.model.TemplateSequenceModel;
-import org.apache.freemarker.core.outputformat.MarkupOutputFormat;
-import org.apache.freemarker.core.util.BugException;
-import org.apache.freemarker.core.valueformat.TemplateDateFormat;
-import org.apache.freemarker.core.valueformat.TemplateNumberFormat;
-import org.apache.freemarker.core.valueformat.TemplateValueFormat;
-import org.apache.freemarker.core.valueformat.TemplateValueFormatException;
-
-/**
- * Internally used static utilities for evaluation expressions.
- */
-public class _EvalUtil {
-static final int CMP_OP_EQUALS = 1;
-static final int CMP_OP_NOT_EQUALS = 2;
-static final int CMP_OP_LESS_THAN = 3;
-static final int CMP_OP_GREATER_THAN = 4;
-static final int CMP_OP_LESS_THAN_EQUALS = 5;
-static final int CMP_OP_GREATER_THAN_EQUALS = 6;
-// If you add a new operator here, update the "compare" and 
"cmpOpToString" methods!
-
-// Prevents instantination.
-private _EvalUtil() { }
-
-/**
- * @param expr {@code null} is allowed, but may results in less helpful 
error messages
- * @param env {@code null} is allowed
- */
-static String modelToString(TemplateScalarModel model, ASTExpression expr, 
Environment env)
-throws TemplateModelException {
-String value = model.getAsString();
-if (value == null) {
-throw newModelHasStoredNullException(String.class, model, expr);
-}
-return value;
-}
-
-/**
- * @param expr {@code null} is allowed, but may results in less helpful 
error messages
- */
-static Number modelToNumber(TemplateNumberModel model, ASTExpression expr)
-throws TemplateModelException {
-Number value = model.getAsNumber();
-if (value == null) throw newModelHasStoredNullException(Number.class, 
model, expr);
-return value;
-}
-
-/**
- * @param expr {@code null} is allowed, but may results in less helpful 
error messages
- */
-static Date modelToDate(TemplateDateModel model, ASTExpression expr)
-throws TemplateModelException {
-Date value = model.getAsDate();
-if (value == null) throw newModelHasStoredNullException(Date.class, 
model, expr);
-return value;
-}
-
-/** Signals the buggy case where we have a non-null model, but it wraps a 
null. */
-public static TemplateModelException newModelHasStoredNullException(
-Class expected, TemplateModel model, ASTExpression expr) {
-return new _TemplateModelException(expr,
-
_TemplateModelException.modelHasStoredNullDescription(expected, model));
-}
-
-/**
- * Compares two expressions according the rules of the FTL comparator 
operators.
- * 
- * @param leftExp not {@code null}
- * @param operator one of the {@code COMP_OP_...} constants, like {@link 
#CMP_OP_EQUA

[16/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core-test/src/test/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtilTest.java
--
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtilTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtilTest.java
deleted file mode 100644
index 37e4726..000
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtilTest.java
+++ /dev/null
@@ -1,585 +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.model.impl;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-import junit.framework.TestCase;
-
-@SuppressWarnings("boxing")
-public class OverloadedNumberUtilTest extends TestCase {
-
-public OverloadedNumberUtilTest(String name) {
-super(name);
-}
-
-public void testIntegerCoercions() {
-cipEqu(Byte.valueOf(Byte.MAX_VALUE));
-cipEqu(Byte.valueOf((byte) 0));
-cipEqu(Byte.valueOf(Byte.MIN_VALUE));
-
-cipEqu(Short.valueOf(Byte.MAX_VALUE),
-new OverloadedNumberUtil.ShortOrByte((short) Byte.MAX_VALUE, 
Byte.MAX_VALUE));
-cipEqu(Short.valueOf((short) 0),
-new OverloadedNumberUtil.ShortOrByte((short) 0, (byte) 0));
-cipEqu(Short.valueOf(Byte.MIN_VALUE),
-new OverloadedNumberUtil.ShortOrByte((short) Byte.MIN_VALUE, 
Byte.MIN_VALUE));
-
-cipEqu(Short.valueOf((short) (Byte.MAX_VALUE + 1)));
-cipEqu(Short.valueOf((short) (Byte.MIN_VALUE - 1)));
-cipEqu(Short.valueOf(Short.MAX_VALUE));
-cipEqu(Short.valueOf(Short.MIN_VALUE));
-
-cipEqu(Integer.valueOf(Byte.MAX_VALUE),
-new OverloadedNumberUtil.IntegerOrByte((int) Byte.MAX_VALUE, 
Byte.MAX_VALUE));
-cipEqu(Integer.valueOf(0),
-new OverloadedNumberUtil.IntegerOrByte(0, (byte) 0));
-cipEqu(Integer.valueOf(Byte.MIN_VALUE),
-new OverloadedNumberUtil.IntegerOrByte((int) Byte.MIN_VALUE, 
Byte.MIN_VALUE));
-
-cipEqu(Integer.valueOf(Byte.MAX_VALUE + 1),
-new OverloadedNumberUtil.IntegerOrShort(Byte.MAX_VALUE + 1, 
(short) (Byte.MAX_VALUE + 1)));
-cipEqu(Integer.valueOf(Byte.MIN_VALUE - 1),
-new OverloadedNumberUtil.IntegerOrShort(Byte.MIN_VALUE - 1, 
(short) (Byte.MIN_VALUE - 1)));
-cipEqu(Integer.valueOf(Short.MAX_VALUE),
-new OverloadedNumberUtil.IntegerOrShort((int) Short.MAX_VALUE, 
Short.MAX_VALUE));
-cipEqu(Integer.valueOf(Short.MIN_VALUE),
-new OverloadedNumberUtil.IntegerOrShort((int) Short.MIN_VALUE, 
Short.MIN_VALUE));
-
-cipEqu(Integer.valueOf(Short.MAX_VALUE + 1));
-cipEqu(Integer.valueOf(Short.MIN_VALUE - 1));
-cipEqu(Integer.valueOf(Integer.MAX_VALUE));
-cipEqu(Integer.valueOf(Integer.MIN_VALUE));
-
-cipEqu(Long.valueOf(Byte.MAX_VALUE),
-new OverloadedNumberUtil.LongOrByte((long) Byte.MAX_VALUE, 
Byte.MAX_VALUE));
-cipEqu(Long.valueOf(0),
-new OverloadedNumberUtil.LongOrByte((long) 0, (byte) 0));
-cipEqu(Long.valueOf(Byte.MIN_VALUE),
-new OverloadedNumberUtil.LongOrByte((long) Byte.MIN_VALUE, 
Byte.MIN_VALUE));
-
-cipEqu(Long.valueOf(Byte.MAX_VALUE + 1),
-new OverloadedNumberUtil.LongOrShort((long) (Byte.MAX_VALUE + 
1), (short) (Byte.MAX_VALUE + 1)));
-cipEqu(Long.valueOf(Byte.MIN_VALUE - 1),
-new OverloadedNumberUtil.LongOrShort((long) (Byte.MIN_VALUE - 
1), (short) (Byte.MIN_VALUE - 1)));
-cipEqu(Long.valueOf(Short.MAX_VALUE),
-new OverloadedNumberUtil.LongOrShort((long) Short.MAX_VALUE, 
Short.MAX_VALUE));
-cipEqu(Long.valueOf(Short.MIN_VALUE),
-new OverloadedNumberUtil.LongOrShort((long) Short.MIN_VALUE, 
Short.MIN_VALUE));
-
-cipEqu(Long.valueOf(Short.MAX_VALUE + 1),
-  

[14/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/DateUtilsTest.java
--
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/DateUtilsTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/DateUtilsTest.java
new file mode 100644
index 000..c44eee3
--- /dev/null
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/DateUtilsTest.java
@@ -0,0 +1,1085 @@
+/*
+ * 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.util;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import 
org.apache.freemarker.core.util._DateUtils.CalendarFieldsToDateConverter;
+import org.apache.freemarker.core.util._DateUtils.DateParseException;
+import org.apache.freemarker.core.util._DateUtils.DateToISO8601CalendarFactory;
+import 
org.apache.freemarker.core.util._DateUtils.TrivialCalendarFieldsToDateConverter;
+
+import junit.framework.TestCase;
+
+public class DateUtilsTest extends TestCase {
+
+private final TimeZone originalDefaultTZ = TimeZone.getDefault();
+
+@Override
+protected void setUp() throws Exception {
+TimeZone.setDefault(TimeZone.getTimeZone("Europe/Prague"));
+}
+
+@Override
+protected void tearDown() throws Exception {
+TimeZone.setDefault(originalDefaultTZ);
+}
+
+private final DateFormat df
+= new SimpleDateFormat("G -MM-dd HH:mm:ss:S Z", Locale.US);
+{
+df.setTimeZone(_DateUtils.UTC);
+}
+
+private CalendarFieldsToDateConverter cf2dc = new 
TrivialCalendarFieldsToDateConverter();
+
+private DateToISO8601CalendarFactory calendarFactory
+= new _DateUtils.TrivialDateToISO8601CalendarFactory();
+
+public DateUtilsTest(String name) {
+super(name);
+}
+
+public void testDateToUTCString() throws ParseException {
+assertEquals(
+"1998-10-30T15:30:00.512Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 1998-10-30 19:30:00:512 +0400"), true));
+assertEquals(
+"1998-10-30T15:30:00.5Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 1998-10-30 19:30:00:500 +0400"), true));
+assertEquals(
+"1998-10-30T15:30:00.51Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 1998-10-30 19:30:00:510 +0400"), true));
+assertEquals(
+"1998-10-30T15:30:00.1Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 1998-10-30 19:30:00:100 +0400"), true));
+assertEquals(
+"1998-10-30T15:30:00.01Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 1998-10-30 19:30:00:10 +0400"), true));
+assertEquals(
+"1998-10-30T15:30:00.001Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 1998-10-30 19:30:00:1 +0400"), true));
+assertEquals(
+"2000-02-08T06:05:04Z",
+dateToISO8601UTCDateTimeMSString(
+df.parse("AD 2000-02-08 09:05:04:0 +0300"), true));
+assertEquals(
+"0099-02-28T06:15:24Z",
+dateToISO8601UTCDateTimeString(
+df.parse(
+"AD 0099-03-02 09:15:24:0 +0300"), true));
+assertEquals(
+"0010-02-28T06:15:24Z",
+dateToISO8601UTCDateTimeString(
+df.parse("AD 0010-03-02 09:15:24:0 +0300"), true));
+assertEquals(
+"0001-02-28T06:15:24Z",
+dateToISO8601UTCDateTimeString(
+  

[04/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
deleted file mode 100644
index 57ba42c..000
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_StringUtil.java
+++ /dev/null
@@ -1,1625 +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.util;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.regex.Pattern;
-
-import org.apache.freemarker.core.Environment;
-import org.apache.freemarker.core.Template;
-import org.apache.freemarker.core.Version;
-
-/** Don't use this; used internally by FreeMarker, might changes without 
notice. */
-public class _StringUtil {
-
-private static final char[] LT = new char[] { '&', 'l', 't', ';' };
-private static final char[] GT = new char[] { '&', 'g', 't', ';' };
-private static final char[] AMP = new char[] { '&', 'a', 'm', 'p', ';' };
-private static final char[] QUOT = new char[] { '&', 'q', 'u', 'o', 't', 
';' };
-private static final char[] HTML_APOS = new char[] { '&', '#', '3', '9', 
';' };
-private static final char[] XML_APOS = new char[] { '&', 'a', 'p', 'o', 
's', ';' };
-
-/**
- *  XML Encoding.
- *  Replaces all '>' '<' '&', "'" and '"' with entity reference
- */
-public static String XMLEnc(String s) {
-return XMLOrHTMLEnc(s, true, true, XML_APOS);
-}
-
-/**
- * Like {@link #XMLEnc(String)}, but writes the result into a {@link 
Writer}.
- */
-public static void XMLEnc(String s, Writer out) throws IOException {
-XMLOrHTMLEnc(s, XML_APOS, out);
-}
-
-/**
- *  XHTML Encoding.
- *  Replaces all '>' '<' '&', "'" and '"' with entity reference
- *  suitable for XHTML decoding in common user agents (including legacy
- *  user agents, which do not decode "'" to "'", so "'" 
is used
- *  instead [see http://www.w3.org/TR/xhtml1/#C_16])
- */
-public static String XHTMLEnc(String s) {
-return XMLOrHTMLEnc(s, true, true, HTML_APOS);
-}
-
-/**
- * Like {@link #XHTMLEnc(String)}, but writes the result into a {@link 
Writer}.
- */
-public static void XHTMLEnc(String s, Writer out) throws IOException {
-XMLOrHTMLEnc(s, HTML_APOS, out);
-}
-
-private static String XMLOrHTMLEnc(String s, boolean escGT, boolean 
escQuot, char[] apos) {
-final int ln = s.length();
-
-// First we find out if we need to escape, and if so, what the length 
of the output will be:
-int firstEscIdx = -1;
-int lastEscIdx = 0;
-int plusOutLn = 0;
-for (int i = 0; i < ln; i++) {
-escape: do {
-final char c = s.charAt(i);
-switch (c) {
-case '<':
-plusOutLn += LT.length - 1;
-break;
-case '>':
-if (!(escGT || maybeCDataEndGT(s, i))) {
-break escape;
-}
-plusOutLn += GT.length - 1;
-break;
-case '&':
-plusOutLn += AMP.length - 1;
-break;
-case '"':
-if (!escQuot) {
-break escape;
-}
-plusOutLn += QUOT.length - 1;
-break;
-case '\'': // apos
-if (apos == null) {
-break escape;
-}
-plusOutLn += apos.length - 1;
-break;
-default:
-break escape;
-}

[13/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/StringUtilsTest.java
--
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/StringUtilsTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/StringUtilsTest.java
new file mode 100644
index 000..a4d57a8
--- /dev/null
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/StringUtilsTest.java
@@ -0,0 +1,416 @@
+/*
+ * 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.util;
+
+import static junit.framework.TestCase.assertNull;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.regex.Pattern;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+public class StringUtilsTest {
+
+@Test
+public void testV2319() {
+assertEquals("\\n\\r\\f\\b\\t\\x00\\x19", 
_StringUtils.javaScriptStringEnc("\n\r\f\b\t\u\u0019"));
+}
+
+@Test
+public void testControlChars() {
+assertEsc(
+"\n\r\f\b\t \u\u0019\u001F \u007F\u0080\u009F 
\u2028\u2029",
+"\\n\\r\\f\\b\\t \\x00\\x19\\x1F \\x7F\\x80\\x9F 
\\u2028\\u2029",
+"\\n\\r\\f\\b\\t \\u\\u0019\\u001F \\u007F\\u0080\\u009F 
\\u2028\\u2029");
+}
+
+@Test
+public void testHtmlChars() {
+assertEsc(
+"/>->]>",
+"/>->]> <\\/foo> \\x3C!-- --\\> \\x3C![CDATA[ ]]\\> 
\\x3C?php?>",
+"/>->]> <\\/foo> \\u003C!-- --\\u003E \\u003C![CDATA[ 
]]\\u003E \\u003C?php?>");
+assertEsc("", "\\>", "\\u003E");
+assertEsc("->", "-\\>", "-\\u003E");
+assertEsc("-->", "--\\>", "--\\u003E");
+assertEsc("c-->", "c--\\>", "c--\\u003E");
+assertEsc("-->c", "--\\>c", "--\\u003Ec");
+assertEsc("]>", "]\\>", "]\\u003E");
+assertEsc("]]>", "]]\\>", "]]\\u003E");
+assertEsc("c]]>", "c]]\\>", "c]]\\u003E");
+assertEsc("]]>c", "]]\\>c", "]]\\u003Ec");
+assertEsc("c->", "c->", "c->");
+assertEsc("c>", "c>", "c>");
+assertEsc("-->", "--\\>", "--\\u003E");
+assertEsc("/", "\\/", "\\/");
+assertEsc("/c", "\\/c", "\\/c");
+assertEsc(" I/m !";
+assertTrue(s == _StringUtils.jsStringEnc(s, false));  // "==" because 
is must return the same object
+assertTrue(s == _StringUtils.jsStringEnc(s, true));
+
+s = "";
+assertTrue(s == _StringUtils.jsStringEnc(s, false));
+assertTrue(s == _StringUtils.jsStringEnc(s, true));
+
+s = "\u00E1rv\u00EDzt\u0171r\u0151 \u3020";
+assertEquals(s, _StringUtils.jsStringEnc(s, false));
+assertTrue(s == _StringUtils.jsStringEnc(s, false));
+assertTrue(s == _StringUtils.jsStringEnc(s, true));
+}
+
+@Test
+public void testOneOffs() {
+assertEsc("c\"c\"cc\"\"c", "c\\\"c\\\"cc\\\"\\\"c", 
"c\\\"c\\\"cc\\\"\\\"c");
+assertEsc("\"c\"cc\"", "\\\"c\\\"cc\\\"", "\\\"c\\\"cc\\\"");
+assertEsc("c/c/cc//c", "c/c/cc//c", "c/c/cc//c");
+assertEsc("c", "\\>", "\\u003E");
+assertEsc("]>", "]\\>", "]\\u003E");
+assertEsc("->", "-\\>", "-\\u003E");
+}
+
+private void assertEsc(String s, String javaScript, String json) {
+assertEquals(javaScript, _StringUtils.jsStringEnc(s, false));
+assertEquals(json, _StringUtils.jsStringEnc(s, true));
+}
+
+@Test
+public void testTrim() {
+assertSame(_CollectionUtils.EMPTY_CHAR_ARRAY, 
_StringUtils.trim(_CollectionUtils.EMPTY_CHAR_ARRAY));
+assertSame(_CollectionUtils.EMPTY_CHAR_ARRAY, _StringUtils.trim(" 
\t\u0001 ".toCharArray()));
+{
+char[] cs = "foo".toCharArray();
+assertSame(cs, cs);
+}
+assertArrayEquals("foo".toCharArray(), _StringUtils.trim("foo 
".toCharArray()));
+assertArrayEquals("foo".toCharArray(), _StringUtils.trim(" 
foo".toCharArray()));
+assertArrayEquals("foo".toCharArray(), _StringUtils.trim("

[07/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/_MethodUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/_MethodUtils.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/_MethodUtils.java
new file mode 100644
index 000..cec556f
--- /dev/null
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/_MethodUtils.java
@@ -0,0 +1,319 @@
+/*
+ * 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.model.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.freemarker.core._DelayedConversionToString;
+import org.apache.freemarker.core._DelayedJQuote;
+import org.apache.freemarker.core._TemplateModelException;
+import org.apache.freemarker.core.model.TemplateModelException;
+import org.apache.freemarker.core.util.BugException;
+import org.apache.freemarker.core.util._ClassUtils;
+
+/**
+ * For internal use only; don't depend on this, there's no backward 
compatibility guarantee at all!
+ */
+public final class _MethodUtils {
+
+private _MethodUtils() {
+// Not meant to be instantiated
+}
+
+/**
+ * Determines whether the type given as the 1st argument is convertible to 
the type given as the 2nd argument
+ * for method call argument conversion. This follows the rules of the Java 
reflection-based method call, except
+ * that since we don't have the value here, a boxed class is never seen as 
convertible to a primitive type. 
+ * 
+ * @return 0 means {@code false}, non-0 means {@code true}.
+ * That is, 0 is returned less specificity or incomparable 
specificity, also when if
+ * then method was aborted because of {@code ifHigherThan}.
+ * The absolute value of the returned non-0 number symbolizes how 
more specific it is:
+ * 
+ *   1: The two classes are identical
+ *   2: The 1st type is primitive, the 2nd type is the 
corresponding boxing class
+ *   3: Both classes are numerical, and one is convertible 
into the other with widening conversion.
+ *  E.g., {@code int} is convertible to {@code long} and 
{#code double}, hence {@code int} is more
+ *  specific.
+ *  This ignores primitive VS boxed mismatches, except 
that a boxed class is never seen as
+ *  convertible to a primitive class.
+ *   4: One class is {@code instanceof} of the other, but they 
aren't identical.
+ *   But unlike in Java, primitive numerical types are {@code 
instanceof} {@link Number} here.
+ *  
+ */
+// TODO Seems that we don't use the full functionality of this anymore, so 
we could simplify this. See usages.
+static int isMoreOrSameSpecificParameterType(final Class specific, 
final Class generic, boolean bugfixed,
+int ifHigherThan) {
+if (ifHigherThan >= 4) return 0;
+if (generic.isAssignableFrom(specific)) {
+// Identity or widening reference conversion:
+return generic == specific ? 1 : 4;
+} else {
+final boolean specificIsPrim = specific.isPrimitive(); 
+final boolean genericIsPrim = generic.isPrimitive();
+if (specificIsPrim) {
+if (genericIsPrim) {
+if (ifHigherThan >= 3) return 0;
+return isWideningPrimitiveNumberConversion(specific, 
generic) ? 3 : 0;
+} else {  // => specificIsPrim && !genericIsPrim
+if (bugfixed) {
+final Class specificAsBoxed = 
_ClassUtils.primitiveClassToBoxingClass(specific);
+if (specificAsBoxed == generic) {
+// A primitive class is 

[08/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtils.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtils.java
new file mode 100644
index 000..6ffe937
--- /dev/null
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/impl/OverloadedNumberUtils.java
@@ -0,0 +1,1289 @@
+/*
+ * 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.model.impl;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.apache.freemarker.core.model.TemplateNumberModel;
+import org.apache.freemarker.core.util._ClassUtils;
+import org.apache.freemarker.core.util._NumberUtils;
+
+/**
+ * Everything related to coercion to ambiguous numerical types.  
+ */
+class OverloadedNumberUtils {
+
+// Can't be instantiated
+private OverloadedNumberUtils() { }
+
+/**
+ * The lower limit of conversion prices where there's a risk of 
significant mantissa loss.
+ * The value comes from misc/overloadedNumberRules/prices.ods and 
generator.ftl.
+ */
+static final int BIG_MANTISSA_LOSS_PRICE = 4 * 1;
+
+/** The highest long that can be stored in double without precision loss: 
2**53. */
+private static final long MAX_DOUBLE_OR_LONG = 9007199254740992L;
+/** The lowest long that can be stored in double without precision loss: 
-(2**53). */
+private static final long MIN_DOUBLE_OR_LONG = -9007199254740992L;
+private static final int MAX_DOUBLE_OR_LONG_LOG_2 = 53;
+
+/** The highest long that can be stored in float without precision loss: 
2**24. */
+private static final int MAX_FLOAT_OR_INT = 16777216;
+/** The lowest long that can be stored in float without precision loss: 
-(2**24). */
+private static final int MIN_FLOAT_OR_INT = -16777216;
+private static final int MAX_FLOAT_OR_INT_LOG_2 = 24;
+/** Lowest number that we don't thread as possible integer 0. */
+private static final double LOWEST_ABOVE_ZERO = 0.01;
+/** Highest number that we don't thread as possible integer 1. */
+private static final double HIGHEST_BELOW_ONE = 0.99;
+
+/**
+ * Attaches the lowest alternative number type to the parameter number via 
{@link NumberWithFallbackType}, if
+ * that's useful according the possible target number types. This 
transformation is applied on the method call
+ * argument list before overloaded method selection.
+ * 
+ * Note that as of this writing, this method is only used when
+ * {@link DefaultObjectWrapper#getIncompatibleImprovements()} >= 2.3.21.
+ * 
+ * Why's this needed, how it works: Overloaded method selection only 
selects methods where the type
+ * (not the value!) of the argument is "smaller" or the same as the 
parameter type. This is similar to how it's in
+ * the Java language. That it only decides based on the parameter type is 
important because this way
+ * {@link OverloadedMethodsSubset} can cache method lookup decisions using 
the types as the cache key. Problem is,
+ * since you don't declare the exact numerical types in FTL, and FTL has 
only a single generic numeric type
+ * anyway, what Java type a {@link TemplateNumberModel} uses internally is 
often seen as a technical detail of which
+ * the template author can't always keep track of. So we investigate the 
value of the number too,
+ * then coerce it down without overflow to a type that will match the most 
overloaded methods. (This
+ * is especially important as FTL often stores numbers in {@link 
BigDecimal}-s, which will hardly ever match any
+ * method parameters.) We could simply return that number, like {@code 
Byte(0)} for an {@code Integer(0)},
+ * however, then we would lose the information about what the original 
type was. The original type is sometimes
+ * important, as in ambiguous situations the method where there's an e

[05/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/util/_LocaleUtils.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_LocaleUtils.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_LocaleUtils.java
new file mode 100644
index 000..249a624
--- /dev/null
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_LocaleUtils.java
@@ -0,0 +1,43 @@
+/*
+ * 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.util;
+
+import java.util.Locale;
+
+/**
+ * For internal use only; don't depend on this, there's no backward 
compatibility guarantee at all!
+ */
+public class _LocaleUtils {
+
+/**
+ * Returns a locale that's one less specific, or {@code null} if there's 
no less specific locale.
+ */
+public static Locale getLessSpecificLocale(Locale locale) {
+String country = locale.getCountry();
+if (locale.getVariant().length() != 0) {
+String language = locale.getLanguage();
+return country != null ? new Locale(language, country) : new 
Locale(language);
+}
+if (country.length() != 0) {
+return new Locale(locale.getLanguage());
+}
+return null;
+}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-core/src/main/java/org/apache/freemarker/core/util/_NumberUtil.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_NumberUtil.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/_NumberUtil.java
deleted file mode 100644
index c300b5c..000
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/_NumberUtil.java
+++ /dev/null
@@ -1,224 +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.util;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-/** Don't use this; used internally by FreeMarker, might changes without 
notice. */
-public class _NumberUtil {
-
-private static final BigDecimal BIG_DECIMAL_INT_MIN = 
BigDecimal.valueOf(Integer.MIN_VALUE);
-private static final BigDecimal BIG_DECIMAL_INT_MAX = 
BigDecimal.valueOf(Integer.MAX_VALUE);
-private static final BigInteger BIG_INTEGER_INT_MIN = 
BIG_DECIMAL_INT_MIN.toBigInteger();
-private static final BigInteger BIG_INTEGER_INT_MAX = 
BIG_DECIMAL_INT_MAX.toBigInteger();
-private static final BigInteger BIG_INTEGER_LONG_MIN = 
BigInteger.valueOf(Long.MIN_VALUE);
-private static final BigInteger BIG_INTEGER_LONG_MAX = 
BigInteger.valueOf(Long.MAX_VALUE);
-
-private _NumberUtil() { }
-
-public static boolean isInfinite(Number num) {
-if (num instanceof Double) {
-return ((Double) num).isInfinite();
-} else if (num instanceof Float) {
-return ((Float) num).isInfinite();
-} else if (isNonFPNumberOfSupportedClass(num)) {
-return false;
-} else {
-throw new UnsupportedNumberClassException(num.getClass());
-}   
-}
-
-public static boolean isNaN(Number num) {
-if (num instanceof Double) {
-return ((Double) num).isNaN();
-

[01/17] incubator-freemarker git commit: Renamed XxxUtil classes to XxxUtils, as this convention is more widespread nowadays.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 cfd379605 -> ebb39b845


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-test-utils/src/main/java/org/apache/freemarker/test/ResourcesExtractor.java
--
diff --git 
a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/ResourcesExtractor.java
 
b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/ResourcesExtractor.java
index 4e05cdc..a0b4045 100644
--- 
a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/ResourcesExtractor.java
+++ 
b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/ResourcesExtractor.java
@@ -32,7 +32,7 @@ import java.util.zip.ZipEntry;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.freemarker.core.util._StringUtil;
+import org.apache.freemarker.core.util._StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -142,8 +142,8 @@ public final class ResourcesExtractor {
 int arrowIdx = contLine.indexOf(ARROW);
 if (arrowIdx != -1) {
 if (!contLine.startsWith("/")) {
-throw new IOException("In " + _StringUtil.jQuote(contResource) 
+ ", this line must start with "
-+ "\"/\" as it uses the " + _StringUtil.jQuote(ARROW) 
+ " operator : "
+throw new IOException("In " + 
_StringUtils.jQuote(contResource) + ", this line must start with "
++ "\"/\" as it uses the " + _StringUtils.jQuote(ARROW) 
+ " operator : "
 + contLine);
 }
 contSrcPath = contLine.substring(0, arrowIdx).trim();
@@ -151,7 +151,7 @@ public final class ResourcesExtractor {
 contSrcPathRelative = false;
 } else {
 if (contLine.startsWith("/")) {
-throw new IOException("In " + _StringUtil.jQuote(contResource)
+throw new IOException("In " + _StringUtils.jQuote(contResource)
 + ", this line can't start with \"/\": " + contLine);
 }
 contSrcPathRelative = true;
@@ -172,7 +172,7 @@ public final class ResourcesExtractor {
 try {
 if (dstFile.exists()) {
 throw new IOException(
-"Destination already exists; check if " + 
_StringUtil.jQuote(contDstPath)
+"Destination already exists; check if " + 
_StringUtils.jQuote(contDstPath)
 + " occurs for multiple times in \"" + 
CONTENTS_TXT + "\".");
 }
 FileUtils.copyInputStreamToFile(entryIn, dstFile);
@@ -180,8 +180,8 @@ public final class ResourcesExtractor {
 File parent = dstFile;
 while ((parent = dstFile.getParentFile()) != null) {
 if (parent.isFile()) {
-throw new IOException("An ancestor directory of " + 
_StringUtil.jQuote(dstFile) + ", "
-+ _StringUtil.jQuote(parent) + " already exists, but 
as a file, not as a directory. "
+throw new IOException("An ancestor directory of " + 
_StringUtils.jQuote(dstFile) + ", "
++ _StringUtils.jQuote(parent) + " already exists, but 
as a file, not as a directory. "
 + "Check if you have accidentally added the directory 
itself to \"" + CONTENTS_TXT
 + "\". Only files should be listed there.");
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ebb39b84/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
--
diff --git 
a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
 
b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
index 9e588d4..dce3719 100644
--- 
a/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
+++ 
b/freemarker-test-utils/src/main/java/org/apache/freemarker/test/TemplateTest.java
@@ -41,7 +41,7 @@ import 
org.apache.freemarker.core.templateresolver.TemplateLoader;
 import 
org.apache.freemarker.core.templateresolver.impl.ByteArrayTemplateLoader;
 import org.apache.freemarker.core.templateresolver.impl.MultiTemplateLoader;
 import org.apache.freemarker.core.util._NullArgumentException;
-import org.apache.freemarker.core.util._StringUtil;
+import org.apache.freemarker.core.util._StringUtils;
 import org.junit.Ignore;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -106,7 +106,7 @@ public abstract class TemplateTest {
 throw new IOException("Reference output resource not found: " 
+ getClass() + ", " + resName);
 }
 try {
-expectedOut = 
Te

[jira] [Created] (FREEMARKER-66) Link to freemarker-java8 while we wait for support

2017-08-08 Thread Jakob Vad Nielsen (JIRA)
Jakob Vad Nielsen created FREEMARKER-66:
---

 Summary: Link to freemarker-java8 while we wait for support
 Key: FREEMARKER-66
 URL: https://issues.apache.org/jira/browse/FREEMARKER-66
 Project: Apache Freemarker
  Issue Type: Wish
  Components: documentation
Reporter: Jakob Vad Nielsen
Priority: Minor


Hi, 

>From the documentation I understand that we have to wait a while for Java8 
>date/time support in Freemarker (?). We have created a sort of workaround that 
>actually many people seems to be using. If you would like to link to this from 
>the http://freemarker.org/contribute.html site, I think that would be helpful 
>while we are waiting.

The project can be found here https://github.com/amedia/freemarker-java-8 and 
are available in the central maven repo.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


incubator-freemarker git commit: Got rid of o.a.f.core.mode.Constants, moved the constants to respectable TemplateModel subinterfaces.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 836de2657 -> cfd379605


Got rid of o.a.f.core.mode.Constants, moved the constants to respectable 
TemplateModel subinterfaces.


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

Branch: refs/heads/3
Commit: cfd3796051265a43e70266dc4c4580c3617cb851
Parents: 836de26
Author: ddekany 
Authored: Tue Aug 8 14:50:58 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 14:50:58 2017 +0200

--
 ...a8DefaultObjectWrapperBridgeMethodsTest.java |   6 +-
 .../impl/Java8DefaultObjectWrapperTest.java |  10 +-
 .../core/TemplateConfigurationTest.java |   1 -
 .../impl/AbstractParallelIntrospectionTest.java |   4 +-
 .../model/impl/DefaultObjectWrapperTest.java|  10 +-
 .../core/model/impl/EnumModelsTest.java |   4 +-
 .../core/model/impl/StaticModelsTest.java   |   4 +-
 .../freemarker/core/model/ConstantsTest.java|   4 +-
 .../TwoNestedContentParamsDirective.java|   4 +-
 .../apache/freemarker/core/ASTExpDefault.java   |   5 +-
 .../freemarker/core/ASTExpDynamicKeyName.java   |   3 +-
 .../freemarker/core/BuiltInsForSequences.java   |   3 +-
 .../apache/freemarker/core/_CallableUtils.java  |  16 +-
 .../core/model/ArgumentArrayLayout.java |   4 +-
 .../apache/freemarker/core/model/Constants.java | 163 ---
 .../core/model/EmptyCollectionExModel.java  |  41 +
 .../freemarker/core/model/EmptyHashModel.java   |  55 +++
 .../core/model/EmptyIteratorModel.java  |  36 
 .../core/model/EmptyKeyValuePairIterator.java   |  36 
 .../core/model/EmptySequenceModel.java  |  36 
 .../core/model/GeneralPurposeNothing.java   |   6 +-
 .../core/model/TemplateCollectionModel.java |   2 +
 .../core/model/TemplateHashModel.java   |   4 +-
 .../core/model/TemplateHashModelEx2.java|   4 +-
 .../core/model/TemplateModelIterator.java   |   3 +
 .../core/model/TemplateNumberModel.java |   5 +
 .../core/model/TemplateSequenceModel.java   |   2 +
 .../model/impl/OverloadedFixArgsMethods.java|   4 +-
 .../model/impl/OverloadedVarArgsMethods.java|   4 +-
 .../core/model/impl/SimpleMethod.java   |   4 +-
 30 files changed, 269 insertions(+), 214 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cfd37960/freemarker-core-test-java8/src/test/java/org/apache/freemarker/core/model/impl/Java8DefaultObjectWrapperBridgeMethodsTest.java
--
diff --git 
a/freemarker-core-test-java8/src/test/java/org/apache/freemarker/core/model/impl/Java8DefaultObjectWrapperBridgeMethodsTest.java
 
b/freemarker-core-test-java8/src/test/java/org/apache/freemarker/core/model/impl/Java8DefaultObjectWrapperBridgeMethodsTest.java
index 095dc37..62bb7af 100644
--- 
a/freemarker-core-test-java8/src/test/java/org/apache/freemarker/core/model/impl/Java8DefaultObjectWrapperBridgeMethodsTest.java
+++ 
b/freemarker-core-test-java8/src/test/java/org/apache/freemarker/core/model/impl/Java8DefaultObjectWrapperBridgeMethodsTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.*;
 import org.apache.freemarker.core.Configuration;
 import org.apache.freemarker.core.NonTemplateCallPlace;
 import org.apache.freemarker.core.TemplateException;
-import org.apache.freemarker.core.model.Constants;
+import org.apache.freemarker.core._CallableUtils;
 import org.apache.freemarker.core.model.TemplateHashModel;
 import org.junit.Test;
 
@@ -56,10 +56,10 @@ public class Java8DefaultObjectWrapperBridgeMethodsTest {
 JavaMethodModel m1 = (JavaMethodModel) wrapped.get("m1");
 assertEquals(
 BridgeMethodsBean.M1_RETURN_VALUE,
-"" + m1.execute(Constants.EMPTY_TEMPLATE_MODEL_ARRAY, 
NonTemplateCallPlace.INSTANCE));
+"" + m1.execute(_CallableUtils.EMPTY_TEMPLATE_MODEL_ARRAY, 
NonTemplateCallPlace.INSTANCE));
 
 JavaMethodModel m2 = (JavaMethodModel) wrapped.get("m2");
-assertNull(m2.execute(Constants.EMPTY_TEMPLATE_MODEL_ARRAY, 
NonTemplateCallPlace.INSTANCE));
+assertNull(m2.execute(_CallableUtils.EMPTY_TEMPLATE_MODEL_ARRAY, 
NonTemplateCallPlace.INSTANCE));
 }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cfd37960/freemarker-core-test-java8/src/test/java/org/apache/freemarker/core/model/impl/Java8DefaultObjectWrapperTest.java
--
diff --git 
a/freemarker-core-test-java8/src/test/java/org/apache/freemarker/

[2/2] incubator-freemarker git commit: GeneralPurposeNothing implements TemplateHashModelEx2 (ported from 2.3-gae)

2017-08-08 Thread ddekany
GeneralPurposeNothing implements TemplateHashModelEx2 (ported from 2.3-gae)


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

Branch: refs/heads/3
Commit: 836de2657cee8b12509af24e79d9bdf7ed1c4fd7
Parents: ddb9c8a
Author: ddekany 
Authored: Tue Aug 8 14:25:12 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 14:25:12 2017 +0200

--
 .../apache/freemarker/core/model/GeneralPurposeNothing.java   | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/836de265/freemarker-core/src/main/java/org/apache/freemarker/core/model/GeneralPurposeNothing.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/GeneralPurposeNothing.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/GeneralPurposeNothing.java
index b19b912..ffc2ad2 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/model/GeneralPurposeNothing.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/model/GeneralPurposeNothing.java
@@ -30,7 +30,7 @@ import org.apache.freemarker.core.TemplateException;
  */
 
 final class GeneralPurposeNothing
-implements TemplateBooleanModel, TemplateScalarModel, TemplateSequenceModel, 
TemplateHashModelEx,
+implements TemplateBooleanModel, TemplateScalarModel, TemplateSequenceModel, 
TemplateHashModelEx2,
 TemplateFunctionModel {
 
 public static final TemplateModel INSTANCE = new GeneralPurposeNothing();
@@ -90,4 +90,9 @@ implements TemplateBooleanModel, TemplateScalarModel, 
TemplateSequenceModel, Tem
 return Constants.EMPTY_COLLECTION;
 }
 
+@Override
+public KeyValuePairIterator keyValuePairIterator() throws 
TemplateModelException {
+return Constants.EMPTY_KEY_VALUE_PAIR_ITERATOR;
+}
+
 }



[1/2] incubator-freemarker git commit: (JavaDoc improvement from 2.3-gae)

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 1b6f894ee -> 836de2657


(JavaDoc improvement from 2.3-gae)


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

Branch: refs/heads/3
Commit: ddb9c8ae3307c375c825deadb0dc68b4e6329d31
Parents: 1b6f894
Author: ddekany 
Authored: Tue Aug 8 14:22:49 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 14:22:49 2017 +0200

--
 .../org/apache/freemarker/core/arithmetic/ArithmeticEngine.java | 5 +++--
 .../core/arithmetic/impl/BigDecimalArithmeticEngine.java| 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ddb9c8ae/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/ArithmeticEngine.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/ArithmeticEngine.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/ArithmeticEngine.java
index afe22be..74f4434 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/ArithmeticEngine.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/ArithmeticEngine.java
@@ -25,8 +25,9 @@ import org.apache.freemarker.core.Configuration;
 import org.apache.freemarker.core.TemplateException;
 
 /**
- * Implements the arithmetic operations executed by the template language; see
- * {@link Configuration#getArithmeticEngine()}.
+ * Used for implementing the arithmetic operations and number comparisons in 
the template language. The concrete
+ * implementation is plugged into the configuration with the {@code 
arithmeticalEngine} setting ({@link
+ * Configuration#getArithmeticEngine()}).
  */
 public abstract class ArithmeticEngine {
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ddb9c8ae/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/impl/BigDecimalArithmeticEngine.java
--
diff --git 
a/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/impl/BigDecimalArithmeticEngine.java
 
b/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/impl/BigDecimalArithmeticEngine.java
index b022f74..0d22656 100644
--- 
a/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/impl/BigDecimalArithmeticEngine.java
+++ 
b/freemarker-core/src/main/java/org/apache/freemarker/core/arithmetic/impl/BigDecimalArithmeticEngine.java
@@ -24,8 +24,8 @@ import org.apache.freemarker.core.arithmetic.ArithmeticEngine;
 import org.apache.freemarker.core.util._NumberUtil;
 
 /**
- * Arithmetic engine that converts all numbers to {@link BigDecimal} and
- * then operates on them. This is FreeMarker's default arithmetic engine.
+ * Arithmetic engine that converts all numbers to {@link BigDecimal} and then 
operates on them, and also keeps the
+ * result as a {@link BigDecimal}. This is FreeMarker's default arithmetic 
engine.
  */
 public class BigDecimalArithmeticEngine extends ArithmeticEngine {
 



[jira] [Closed] (FREEMARKER-63) FM3 Unification and improvement of directive-like constructs

2017-08-08 Thread Daniel Dekany (JIRA)

 [ 
https://issues.apache.org/jira/browse/FREEMARKER-63?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Dekany closed FREEMARKER-63.
---
   Resolution: Fixed
Fix Version/s: 3.0.0

> FM3 Unification and improvement of directive-like constructs
> 
>
> Key: FREEMARKER-63
> URL: https://issues.apache.org/jira/browse/FREEMARKER-63
> Project: Apache Freemarker
>  Issue Type: New Feature
>  Components: engine
>Affects Versions: 3.0.0
>Reporter: Daniel Dekany
>Assignee: Daniel Dekany
> Fix For: 3.0.0
>
>
> In FreeMarker 3 all kind of directive-like user defined objects (macros, 
> {{TemplateDirectiveModel}}-s, {{TempalteTransfromModel}}-s, etc) has to be 
> united under a single {{TemplateModel}} subinterface, which support all the 
> features supported by the replaced FM2 concepts (e.g. nested content 
> execution, loop variables, passing parameters by position and by name, 
> varargs in both cases, call place bound caching, etc.). Obviously, the 
> template language has to support calling this new interface, and then the old 
> ones has to be removed.
> Furthermore, as a new feature in FM3, passing parameter both by position and 
> by name in the same invocation (as in {{<@image "foo.jpg" alt="Foo" />}}) 
> need to be supported.
> (Similarly, {{#function}} and {{TempalteMethodModel}} will have to be 
> generalized and united, but that will be in a separate issue.)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Closed] (FREEMARKER-64) FM3 Unification and improvement of function-like constructs

2017-08-08 Thread Daniel Dekany (JIRA)

 [ 
https://issues.apache.org/jira/browse/FREEMARKER-64?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Dekany closed FREEMARKER-64.
---
   Resolution: Fixed
Fix Version/s: 3.0.0

> FM3 Unification and improvement of function-like constructs
> ---
>
> Key: FREEMARKER-64
> URL: https://issues.apache.org/jira/browse/FREEMARKER-64
> Project: Apache Freemarker
>  Issue Type: New Feature
>  Components: engine
>Affects Versions: 3.0.0
>Reporter: Daniel Dekany
>Assignee: Daniel Dekany
> Fix For: 3.0.0
>
>
> FREEMARKER-63 has introduced {{TemplateFunctionModel}}, which is the type of 
> values that {{#function}} creates. It should also replace 
> {{TemplateMethodModel}} and {{TemplateMethodModelEx}}, so that we have only 
> one interface for function-like things. (If that doesn't work out well, we at 
> least should remove the deprecated {{TemplateMethodModel}}, and then rename 
> {{TemplateMethodModelEx}} to that name. Also, we need to support the explicit 
> selection overloaded Java methods - see in {{CallPlace}}).
> As {{TemplateFunctionModel}} supports both positional and named parameters, 
> the expression language has to be upgraded to support that too.
> Things like `?isMethod` and `?isFunction` have to be reworked as well.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (FREEMARKER-64) FM3 Unification and improvement of function-like constructs

2017-08-08 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/FREEMARKER-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16118241#comment-16118241
 ] 

ASF GitHub Bot commented on FREEMARKER-64:
--

Github user asfgit closed the pull request at:

https://github.com/apache/incubator-freemarker/pull/33


> FM3 Unification and improvement of function-like constructs
> ---
>
> Key: FREEMARKER-64
> URL: https://issues.apache.org/jira/browse/FREEMARKER-64
> Project: Apache Freemarker
>  Issue Type: New Feature
>  Components: engine
>Affects Versions: 3.0.0
>Reporter: Daniel Dekany
>Assignee: Daniel Dekany
>
> FREEMARKER-63 has introduced {{TemplateFunctionModel}}, which is the type of 
> values that {{#function}} creates. It should also replace 
> {{TemplateMethodModel}} and {{TemplateMethodModelEx}}, so that we have only 
> one interface for function-like things. (If that doesn't work out well, we at 
> least should remove the deprecated {{TemplateMethodModel}}, and then rename 
> {{TemplateMethodModelEx}} to that name. Also, we need to support the explicit 
> selection overloaded Java methods - see in {{CallPlace}}).
> As {{TemplateFunctionModel}} supports both positional and named parameters, 
> the expression language has to be upgraded to support that too.
> Things like `?isMethod` and `?isFunction` have to be reworked as well.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[GitHub] incubator-freemarker pull request #33: FREEMARKER-64: Function (and thus als...

2017-08-08 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/incubator-freemarker/pull/33


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[1/2] incubator-freemarker git commit: FREEMARKER-64: Function (and thus also method) call syntax now supports passing parameter by name.

2017-08-08 Thread ddekany
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 89d436965 -> 1b6f894ee


FREEMARKER-64: Function (and thus also method) call syntax now supports passing 
parameter by name.


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

Branch: refs/heads/3
Commit: b59a03a8add0f47427ddd9594852f7bd86a8a7e9
Parents: 8d5263f
Author: ddekany 
Authored: Tue Aug 8 13:46:50 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 13:46:50 2017 +0200

--
 .../core/TemplateCallableModelTest.java |  36 +++-
 .../core/userpkg/AllFeaturesFunction.java   |  29 ++-
 .../core/userpkg/NamedVarargsOnlyFunction.java  |  61 ++
 .../userpkg/PositionalVarargsOnlyFunction.java  |  19 +-
 .../core/userpkg/TestTemplateCallableModel.java |  58 +++---
 .../core/userpkg/TwoNamedParamsFunction.java|  71 +++
 .../userpkg/TwoPositionalParamsFunction.java|  21 +-
 .../templates/string-builtins3.ftl  |  16 +-
 .../freemarker/core/ASTDynamicTopLevelCall.java | 154 +-
 .../freemarker/core/ASTExpFunctionCall.java | 201 +++
 .../apache/freemarker/core/_CallableUtils.java  | 180 -
 .../core/model/ArgumentArrayLayout.java |  14 ++
 freemarker-core/src/main/javacc/FTL.jj  | 118 +--
 13 files changed, 650 insertions(+), 328 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b59a03a8/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateCallableModelTest.java
--
diff --git 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateCallableModelTest.java
 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateCallableModelTest.java
index 3459aea..d6c9e66 100644
--- 
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateCallableModelTest.java
+++ 
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/TemplateCallableModelTest.java
@@ -24,9 +24,11 @@ import java.io.IOException;
 import org.apache.freemarker.core.userpkg.AllFeaturesDirective;
 import org.apache.freemarker.core.userpkg.AllFeaturesFunction;
 import org.apache.freemarker.core.userpkg.NamedVarargsOnlyDirective;
+import org.apache.freemarker.core.userpkg.NamedVarargsOnlyFunction;
 import org.apache.freemarker.core.userpkg.PositionalVarargsOnlyDirective;
 import org.apache.freemarker.core.userpkg.PositionalVarargsOnlyFunction;
 import org.apache.freemarker.core.userpkg.TwoNamedParamsDirective;
+import org.apache.freemarker.core.userpkg.TwoNamedParamsFunction;
 import org.apache.freemarker.core.userpkg.TwoNestedContentParamsDirective;
 import org.apache.freemarker.core.userpkg.TwoPositionalParamsDirective;
 import org.apache.freemarker.core.userpkg.TwoPositionalParamsFunction;
@@ -48,7 +50,9 @@ public class TemplateCallableModelTest extends TemplateTest {
 
 addToDataModel("fa", AllFeaturesFunction.INSTANCE);
 addToDataModel("fp", TwoPositionalParamsFunction.INSTANCE);
+addToDataModel("fn", TwoNamedParamsFunction.INSTANCE);
 addToDataModel("fpvo", PositionalVarargsOnlyFunction.INSTANCE);
+addToDataModel("fnvo", NamedVarargsOnlyFunction.INSTANCE);
 }
 
 @Test
@@ -121,6 +125,13 @@ public class TemplateCallableModelTest extends 
TemplateTest {
 assertOutput("${fp(1, 2)}",
 "fp(p1=1, p2=2)");
 
+assertOutput("${fn()}",
+"fn(n1=null, n2=null)");
+assertOutput("${fn(n1=11)}",
+"fn(n1=11, n2=null)");
+assertOutput("${fn(n1=11, n2=22)}",
+"fn(n1=11, n2=22)");
+
 assertOutput("${fpvo()}",
 "fpvo(pVarargs=[])");
 assertOutput("${fpvo(1)}",
@@ -132,10 +143,27 @@ public class TemplateCallableModelTest extends 
TemplateTest {
 "fa(p1=null, p2=null, pVarargs=[], n1=null, n2=null, 
nVarargs={})");
 assertOutput("${fa(1, 2)}",
 "fa(p1=1, p2=2, pVarargs=[], n1=null, n2=null, nVarargs={})");
-assertOutput("${fa(1, 2, 3)}",
-"fa(p1=1, p2=2, pVarargs=[3], n1=null, n2=null, nVarargs={})");
-assertOutput("${fa(1, 2, 3, 4)}",
-"fa(p1=1, p2=2, pVarargs=[3, 4], n1=null, n2=null, 
nVarargs={})");
+assertOutput("${fa(n1=11, n2=22)}",
+"fa(p1=null, p2=null, pVarargs=[], n1=11, n2=22, 
nVarargs={})");
+
+assertOutput("${fa(1, 2, n1=11, n2=22)}",
+"fa(p1=1, p2=2, pVarargs=[], n1=11, n2=22, nVarargs={})");
+assertOutput("${fa

[2/2] incubator-freemarker git commit: FREEMARKER-64: Merged: Function (and thus also method) call syntax now supports passing parameter by name.

2017-08-08 Thread ddekany
FREEMARKER-64: Merged: Function (and thus also method) call syntax now supports 
passing parameter by name.

Merge commit 'refs/pull/33/head' of 
https://github.com/apache/incubator-freemarker into 3


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

Branch: refs/heads/3
Commit: 1b6f894ee14351d320d434fc1f6f547d29f3335e
Parents: 89d4369 b59a03a
Author: ddekany 
Authored: Tue Aug 8 13:54:45 2017 +0200
Committer: ddekany 
Committed: Tue Aug 8 13:56:06 2017 +0200

--
 .../core/TemplateCallableModelTest.java |  36 +++-
 .../core/userpkg/AllFeaturesFunction.java   |  29 ++-
 .../core/userpkg/NamedVarargsOnlyFunction.java  |  61 ++
 .../userpkg/PositionalVarargsOnlyFunction.java  |  19 +-
 .../core/userpkg/TestTemplateCallableModel.java |  58 +++---
 .../core/userpkg/TwoNamedParamsFunction.java|  71 +++
 .../userpkg/TwoPositionalParamsFunction.java|  21 +-
 .../templates/string-builtins3.ftl  |  16 +-
 .../freemarker/core/ASTDynamicTopLevelCall.java | 154 +-
 .../freemarker/core/ASTExpFunctionCall.java | 201 +++
 .../apache/freemarker/core/_CallableUtils.java  | 180 -
 .../core/model/ArgumentArrayLayout.java |  14 ++
 freemarker-core/src/main/javacc/FTL.jj  | 118 +--
 13 files changed, 650 insertions(+), 328 deletions(-)
--




[jira] [Commented] (FREEMARKER-64) FM3 Unification and improvement of function-like constructs

2017-08-08 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/FREEMARKER-64?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16118228#comment-16118228
 ] 

ASF GitHub Bot commented on FREEMARKER-64:
--

GitHub user ddekany opened a pull request:

https://github.com/apache/incubator-freemarker/pull/33

FREEMARKER-64: Function (and thus also method) call syntax now suppor…

…ts passing parameter by name.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/ddekany/incubator-freemarker FREEMARKER-64

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-freemarker/pull/33.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #33


commit b59a03a8add0f47427ddd9594852f7bd86a8a7e9
Author: ddekany 
Date:   2017-08-08T11:46:50Z

FREEMARKER-64: Function (and thus also method) call syntax now supports 
passing parameter by name.




> FM3 Unification and improvement of function-like constructs
> ---
>
> Key: FREEMARKER-64
> URL: https://issues.apache.org/jira/browse/FREEMARKER-64
> Project: Apache Freemarker
>  Issue Type: New Feature
>  Components: engine
>Affects Versions: 3.0.0
>Reporter: Daniel Dekany
>Assignee: Daniel Dekany
>
> FREEMARKER-63 has introduced {{TemplateFunctionModel}}, which is the type of 
> values that {{#function}} creates. It should also replace 
> {{TemplateMethodModel}} and {{TemplateMethodModelEx}}, so that we have only 
> one interface for function-like things. (If that doesn't work out well, we at 
> least should remove the deprecated {{TemplateMethodModel}}, and then rename 
> {{TemplateMethodModelEx}} to that name. Also, we need to support the explicit 
> selection overloaded Java methods - see in {{CallPlace}}).
> As {{TemplateFunctionModel}} supports both positional and named parameters, 
> the expression language has to be upgraded to support that too.
> Things like `?isMethod` and `?isFunction` have to be reworked as well.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[GitHub] incubator-freemarker pull request #33: FREEMARKER-64: Function (and thus als...

2017-08-08 Thread ddekany
GitHub user ddekany opened a pull request:

https://github.com/apache/incubator-freemarker/pull/33

FREEMARKER-64: Function (and thus also method) call syntax now suppor…

…ts passing parameter by name.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/ddekany/incubator-freemarker FREEMARKER-64

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-freemarker/pull/33.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #33


commit b59a03a8add0f47427ddd9594852f7bd86a8a7e9
Author: ddekany 
Date:   2017-08-08T11:46:50Z

FREEMARKER-64: Function (and thus also method) call syntax now supports 
passing parameter by name.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---