Repository: incubator-freemarker
Updated Branches:
refs/heads/3 50b4a93e7 -> ce72f4ba2
Removed long deprecated `#{}` interpolations.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/ce72f4ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/ce72f4ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/ce72f4ba
Branch: refs/heads/3
Commit: ce72f4ba24c076b76727c96014d0f12ad13c62bc
Parents: 50b4a93
Author: ddekany <[email protected]>
Authored: Tue Jun 27 00:00:27 2017 +0200
Committer: ddekany <[email protected]>
Committed: Tue Jun 27 00:00:35 2017 +0200
----------------------------------------------------------------------
FM3-CHANGE-LOG.txt | 5 +-
.../core/InterpolationSyntaxTest.java | 35 ++++
.../core/ObjectBuilderSettingsTest.java | 15 +-
.../freemarker/core/OutputFormatTest.java | 16 --
.../core/StringLiteralInterpolationTest.java | 9 +-
.../freemarker/core/util/FTLUtilTest.java | 3 +-
.../freemarker/core/ast-strlitinterpolation.ast | 4 +-
.../freemarker/core/ast-strlitinterpolation.ftl | 2 +-
.../core/cano-strlitinterpolation.ftl | 2 +-
.../core/cano-strlitinterpolation.ftl.out | 2 +-
.../core/templatesuite/expected/arithmetic.txt | 46 -----
.../core/templatesuite/templates/arithmetic.ftl | 50 ------
.../templatesuite/templates/lastcharacter.ftl | 2 +-
.../templatesuite/templates/listliteral.ftl | 2 +-
.../templatesuite/templates/number-literal.ftl | 6 +-
.../freemarker/core/templatesuite/testcases.xml | 1 -
.../freemarker/core/ASTDirAssignment.java | 2 +-
.../freemarker/core/ASTExpStringLiteral.java | 3 +-
.../freemarker/core/ASTHashInterpolation.java | 172 -------------------
.../apache/freemarker/core/Configuration.java | 2 +-
.../core/MutableProcessingConfiguration.java | 4 +-
.../core/_ObjectBuilderSettingEvaluator.java | 5 +-
.../apache/freemarker/core/util/FTLUtil.java | 3 +-
freemarker-core/src/main/javacc/FTL.jj | 123 ++-----------
24 files changed, 80 insertions(+), 434 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/FM3-CHANGE-LOG.txt
----------------------------------------------------------------------
diff --git a/FM3-CHANGE-LOG.txt b/FM3-CHANGE-LOG.txt
index 0759d58..a930bc6 100644
--- a/FM3-CHANGE-LOG.txt
+++ b/FM3-CHANGE-LOG.txt
@@ -282,4 +282,7 @@ the FreeMarer 3 changelog here:
behaves as if it was false. When a FreeMarker method throws an exception, the
caller is responsible for either logging it or letting it bubble up.
- util.ObjectFactory was renamed to CommonSupplier, and its createObject()
method was renamed to
- get(), to be more similar to the Java 8 API.
\ No newline at end of file
+ get(), to be more similar to the Java 8 API.
+- Removed long deprecated `#{}` interpolations. They are treated as plain
static text now. (The
+ template converter tool translates these to `${}` interpolations. For
example `#{x}` is simply
+ translated to `${b}`, while `#{x; m1M3}` is translated to
`${x?string('0.0##')}`).
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
new file mode 100644
index 0000000..b352298
--- /dev/null
+++
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/InterpolationSyntaxTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.io.IOException;
+
+import org.apache.freemarker.test.TemplateTest;
+import org.junit.Test;
+
+public class InterpolationSyntaxTest extends TemplateTest {
+
+ @Test
+ public void fm2HashInterpolationNotRecognized() throws IOException,
TemplateException {
+ // Find related: [interpolation prefixes]
+ assertOutput("#{1} ${1} ${'#{2} ${2}'}", "#{1} 1 #{2} 2");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java
index cc02d3f..b02a736 100644
---
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java
+++
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java
@@ -523,24 +523,17 @@ public class ObjectBuilderSettingsTest {
} catch (_ObjectBuilderSettingEvaluationException e) {
assertThat(e.getMessage(), containsString("\")\""));
}
-
+
try {
_ObjectBuilderSettingEvaluator.eval(
- "foo.Bar('s${x}s'))",
+ "'s${x}s'",
Object.class, false,
_SettingEvaluationEnvironment.getCurrent());
fail();
} catch (_ObjectBuilderSettingEvaluationException e) {
assertThat(e.getMessage(), containsString("${...}"));
}
-
- try {
- _ObjectBuilderSettingEvaluator.eval(
- "foo.Bar('s#{x}s'))",
- Object.class, false,
_SettingEvaluationEnvironment.getCurrent());
- fail();
- } catch (_ObjectBuilderSettingEvaluationException e) {
- assertThat(e.getMessage(), containsString("#{...}"));
- }
+ // Find related: [interpolation prefixes]
+ assertEqualsEvaled("s#{x}s", "'s#{x}s'"); // FM2 #{} is not recognized
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
index a21cff7..538a01f 100644
---
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
+++
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
@@ -315,22 +315,6 @@ public class OutputFormatTest extends TemplateTest {
}
@Test
- public void testNumericalInterpolation() throws IOException,
TemplateException {
- setConfiguration(new TestConfigurationBuilder()
-
.registeredCustomOutputFormats(Collections.<OutputFormat>singleton(DummyOutputFormat.INSTANCE))
- .build());
- assertOutput(
- "<#ftl outputFormat='dummy'>#{1.5}; #{1.5; m3}; ${'a.b'}",
- "1\\.5; 1\\.500; a\\.b");
- assertOutput(
- "<#ftl outputFormat='dummy' autoEsc=false>#{1.5}; #{1.5; m3};
${'a.b'}; ${'a.b'?esc}",
- "1.5; 1.500; a.b; a\\.b");
- assertOutput("<#ftl outputFormat='plainText'>#{1.5}", "1.5");
- assertOutput("<#ftl outputFormat='HTML'>#{1.5}", "1.5");
- assertOutput("#{1.5}", "1.5");
- }
-
- @Test
public void testUndefinedOutputFormat() throws IOException,
TemplateException {
assertOutput("${'a < b'}; ${htmlPlain}; ${htmlMarkup}", "a < b; a <
{h'}; <p>c");
assertErrorContains("${'x'?esc}", "undefined", "escaping", "?esc");
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
index ae72dac..7a71289 100644
---
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
+++
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/StringLiteralInterpolationTest.java
@@ -34,11 +34,8 @@ public class StringLiteralInterpolationTest extends
TemplateTest {
@Test
public void basics() throws IOException, TemplateException {
addToDataModel("x", 1);
- assertOutput("${'${x}'}", "1");
- assertOutput("${'#{x}'}", "1");
+ assertOutput("${'${x}'}", "1"); // Find related: [interpolation
prefixes]
assertOutput("${'a${x}b${x*2}c'}", "a1b2c");
- assertOutput("${'a#{x}b#{x*2}c'}", "a1b2c");
- assertOutput("${'a#{x; m2}'}", "a1.00");
assertOutput("${'${x} ${x}'}", "1 1");
assertOutput("${'$\\{x}'}", "${x}");
assertOutput("${'$\\{x} $\\{x}'}", "${x} ${x}");
@@ -116,12 +113,10 @@ public class StringLiteralInterpolationTest extends
TemplateTest {
assertOutput("${\"${1000}_&\"}", "1.00*10<sup>3</sup>_&");
assertOutput("${\"${1000}, ${2000}\"}", "1.00*10<sup>3</sup>,
2.00*10<sup>3</sup>");
assertOutput("${\"& ${'x'}, ${2000}\"}", "& x,
2.00*10<sup>3</sup>");
- assertOutput("${\"& ${'x'}, #{2000}\"}", "& x, 2000");
-
+
assertOutput("${\"${2000}\"?isMarkupOutput?c}", "true");
assertOutput("${\"x ${2000}\"?isMarkupOutput?c}", "true");
assertOutput("${\"${2000} x\"?isMarkupOutput?c}", "true");
- assertOutput("${\"#{2000}\"?isMarkupOutput?c}", "false");
assertOutput("${\"${'x'}\"?isMarkupOutput?c}", "false");
assertOutput("${\"x ${'x'}\"?isMarkupOutput?c}", "false");
assertOutput("${\"${'x'} x\"?isMarkupOutput?c}", "false");
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/FTLUtilTest.java
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/FTLUtilTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/FTLUtilTest.java
index f1e44f3..14e5a07 100644
---
a/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/FTLUtilTest.java
+++
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/util/FTLUtilTest.java
@@ -35,7 +35,8 @@ public class FTLUtilTest {
assertEquals("a{b}c", FTLUtil.escapeStringLiteralPart("a{b}c"));
assertEquals("a#b", FTLUtil.escapeStringLiteralPart("a#b"));
assertEquals("a$b", FTLUtil.escapeStringLiteralPart("a$b"));
- assertEquals("a#\\{b}c", FTLUtil.escapeStringLiteralPart("a#{b}c"));
+ // Find related: [interpolation prefixes]
+ assertEquals("a#{b}c", FTLUtil.escapeStringLiteralPart("a#{b}c"));
assertEquals("a$\\{b}c", FTLUtil.escapeStringLiteralPart("a${b}c"));
assertEquals("a'c\\\"d", FTLUtil.escapeStringLiteralPart("a'c\"d",
'"'));
assertEquals("a\\'c\"d", FTLUtil.escapeStringLiteralPart("a'c\"d",
'\''));
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ast
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ast
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ast
index 321721e..90317bd 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ast
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ast
@@ -58,10 +58,8 @@
- content: dynamic "..." // o.a.f.c.ASTExpStringLiteral
- value part: ${...} // o.a.f.c.ASTDollarInterpolation
- content: x // o.a.f.c.ASTExpVariable
- - value part: #{...} // o.a.f.c.ASTHashInterpolation
+ - value part: ${...} // o.a.f.c.ASTDollarInterpolation
- content: y // o.a.f.c.ASTExpVariable
- - minimum decimals: "0" // Integer
- - maximum decimals: "0" // Integer
#text // o.a.f.c.ASTStaticText
- content: "\n6. " // String
${...} // o.a.f.c.ASTDollarInterpolation
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ftl
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ftl
index cd86f2f..ce73ab2 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ftl
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/ast-strlitinterpolation.ftl
@@ -20,6 +20,6 @@
2. ${'a${x}b${x}c'}
3. ${'${x}b'}
4. ${'a${x}'}
-5. ${'${x}#{y}'}
+5. ${'${x}${y}'}
6. ${'a b ${x} c d'}
7. ${'${x} a b ${y} c$d'}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl
index 85189a4..9f6fef6 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl
@@ -16,4 +16,4 @@
specific language governing permissions and limitations
under the License.
-->
-<@m x='${e1 + "a\'b${x}"}#{x; M2}' y='$\{e2}' />
\ No newline at end of file
+<@m x='${e1 + "a\'b${x}"}' y='$\{e2}' />
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl.out
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl.out
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl.out
index 754c225..7ad90a7 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl.out
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/cano-strlitinterpolation.ftl.out
@@ -16,4 +16,4 @@
* specific language governing permissions and limitations
* under the License.
*/
-<@m x="${e1 + \"a'b$\{x}\"}#{x ; m0M2}" y="$\{e2}"/>
\ No newline at end of file
+<@m x="${e1 + \"a'b$\{x}\"}" y="$\{e2}"/>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/arithmetic.txt
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/arithmetic.txt
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/arithmetic.txt
deleted file mode 100644
index 33a7186..0000000
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/expected/arithmetic.txt
+++ /dev/null
@@ -1,46 +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.
- */
-<html>
-<head>
-<title>FreeMarker: Arithmetic Test</title>
-</head>
-<body>
-
-<p>A simple test follows:</p>
-
-<p>Perform a number assignment:</p>
-
-
-3.234
-2.00
-0.6172500000000000000000000000000000000000
-1.620089104901
-1.6201
-
-<P>Display a number with at least 3 digits after the decimal point</P>
-
-1234.000
-
-<p>Now use numbers in assignment</p>
-
-
-1257.77
-
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/arithmetic.ftl
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/arithmetic.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/arithmetic.ftl
deleted file mode 100644
index afd4c28..0000000
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/arithmetic.ftl
+++ /dev/null
@@ -1,50 +0,0 @@
-[#ftl]
-[#--
- 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.
---]
-<html>
-<head>
-<title>FreeMarker: Arithmetic Test</title>
-</head>
-<body>
-[#assign foo = 1234, bar = 23.77]
-
-<p>A simple test follows:</p>
-
-<p>Perform a number assignment:</p>
-
-[#setting locale="en_US"][#assign x = 1.2345, y=2]
-
-#{ x+y ; m2M3}
-#{ y ; m2M3}
-#{ x/y ; m40M40}
-#{y/x}
-#{ y/x ; M4}
-
-<P>Display a number with at least 3 digits after the decimal point</P>
-
-#{foo ; m3}
-
-<p>Now use numbers in assignment</p>
-
-[#assign mynumber = foo + bar [#-- a comment --] ]
-
-#{mynumber}
-
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/lastcharacter.ftl
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/lastcharacter.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/lastcharacter.ftl
index e762356..a2ad295 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/lastcharacter.ftl
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/lastcharacter.ftl
@@ -24,7 +24,7 @@
<p>A simple test follows:</p>
- #{message?capitalize?length}
+ ${message?capitalize?length}
${message [1..] ? upper_case}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/listliteral.ftl
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/listliteral.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/listliteral.ftl
index d48578c..8fba519 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/listliteral.ftl
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/listliteral.ftl
@@ -32,7 +32,7 @@
<#assign mymessage = "hello">
<#assign test = [ "test1", "test23", "test45", message, mymessage]>
-The list contains #{test?size} items.
+The list contains ${test?size} items.
<#list test as item>
<p>${item}</p>
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/number-literal.ftl
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/number-literal.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/number-literal.ftl
index c881d0f..2ca9e8b 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/number-literal.ftl
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/number-literal.ftl
@@ -53,14 +53,14 @@
<p>Now perform a number assignment:</p>
-#{1.300000?double}
+${1.300000?double}
<#assign mynumber = 1.8, USA="en_US" />
<#assign myfloat = mynumber?float />
My number is: ${mynumber}
<#setting locale="en_US">
-My float is: #{myfloat ; m6}
+My float is: ${myfloat?string('0.000000')}
The int part is: ${myfloat?int}
<#assign mymessage = mynumber?string>
@@ -73,7 +73,7 @@ ${mymessage + 3}
${mymessage}
<#assign mymessage = mymessage + 2>
-#{mymessage}
+${mymessage}
<p>Try numbers in tests</p>
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/testcases.xml
----------------------------------------------------------------------
diff --git
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/testcases.xml
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/testcases.xml
index 958ff0e..55ed29d 100644
---
a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/testcases.xml
+++
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/testcases.xml
@@ -57,7 +57,6 @@ Note that for the incompatible_improvements setting you can
specify a list of ve
<testCase name="api-builtins" noOutput="true">
<setting api_builtin_enabled="true" />
</testCase>
- <testCase name="arithmetic" />
<testCase name="assignments" noOutput="true" />
<testCase name="boolean" />
<testCase name="charset-in-header" />
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
index db008f5..f25e9fe 100644
---
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
+++
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java
@@ -224,7 +224,7 @@ final class ASTDirAssignment extends ASTDirective {
} else if (scope == ASTDirAssignment.NAMESPACE) {
return "#assign";
} else {
- return "#{unknown_assignment_type}";
+ throw new BugException();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
index e8e0d96..82901b2 100644
---
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
+++
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpStringLiteral.java
@@ -51,8 +51,7 @@ final class ASTExpStringLiteral extends ASTExpression
implements TemplateScalarM
void parseValue(FMParserTokenManager parentTkMan, OutputFormat
outputFormat) throws ParseException {
// The way this works is incorrect (the literal should be parsed
without un-escaping),
// but we can't fix this backward compatibly.
- if (value.length() > 3 && (value.indexOf("${") >= 0 ||
value.indexOf("#{") >= 0)) {
-
+ if (value.length() > 3 && value.indexOf("${") >= 0) { // Find related:
[interpolation prefixes]
Template parentTemplate = getTemplate();
ParsingConfiguration pCfg =
parentTemplate.getParsingConfiguration();
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java
deleted file mode 100644
index 1b49248..0000000
---
a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java
+++ /dev/null
@@ -1,172 +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.io.IOException;
-import java.io.Writer;
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import org.apache.freemarker.core.outputformat.MarkupOutputFormat;
-import org.apache.freemarker.core.util.FTLUtil;
-
-/**
- * AST interpolation node: <tt>#{exp}</tt>
- */
-final class ASTHashInterpolation extends ASTInterpolation {
-
- private final ASTExpression expression;
- private final boolean hasFormat;
- private final int minFracDigits;
- private final int maxFracDigits;
- /** For OutputFormat-based auto-escaping */
- private final MarkupOutputFormat autoEscapeOutputFormat;
- private volatile FormatHolder formatCache; // creating new NumberFormat is
slow operation
-
- ASTHashInterpolation(ASTExpression expression, MarkupOutputFormat
autoEscapeOutputFormat) {
- this.expression = expression;
- hasFormat = false;
- minFracDigits = 0;
- maxFracDigits = 0;
- this.autoEscapeOutputFormat = autoEscapeOutputFormat;
- }
-
- ASTHashInterpolation(ASTExpression expression,
- int minFracDigits, int maxFracDigits,
- MarkupOutputFormat autoEscapeOutputFormat) {
- this.expression = expression;
- hasFormat = true;
- this.minFracDigits = minFracDigits;
- this.maxFracDigits = maxFracDigits;
- this.autoEscapeOutputFormat = autoEscapeOutputFormat;
- }
-
- @Override
- ASTElement[] accept(Environment env) throws TemplateException, IOException
{
- String s = calculateInterpolatedStringOrMarkup(env);
- Writer out = env.getOut();
- if (autoEscapeOutputFormat != null) {
- autoEscapeOutputFormat.output(s, out);
- } else {
- out.write(s);
- }
- return null;
- }
-
- @Override
- protected String calculateInterpolatedStringOrMarkup(Environment env)
throws TemplateException {
- Number num = expression.evalToNumber(env);
-
- FormatHolder fmth = formatCache; // atomic sampling
- if (fmth == null || !fmth.locale.equals(env.getLocale())) {
- synchronized (this) {
- fmth = formatCache;
- if (fmth == null || !fmth.locale.equals(env.getLocale())) {
- NumberFormat fmt =
NumberFormat.getNumberInstance(env.getLocale());
- if (hasFormat) {
- fmt.setMinimumFractionDigits(minFracDigits);
- fmt.setMaximumFractionDigits(maxFracDigits);
- } else {
- fmt.setMinimumFractionDigits(0);
- fmt.setMaximumFractionDigits(50);
- }
- fmt.setGroupingUsed(false);
- formatCache = new FormatHolder(fmt, env.getLocale());
- fmth = formatCache;
- }
- }
- }
- // We must use Format even if hasFormat == false.
- // Some locales may use non-Arabic digits, thus replacing the
- // decimal separator in the result of toString() is not enough.
- return fmth.format.format(num);
- }
-
- @Override
- protected String dump(boolean canonical, boolean inStringLiteral) {
- StringBuilder buf = new StringBuilder("#{");
- final String exprCF = expression.getCanonicalForm();
- buf.append(inStringLiteral ? FTLUtil.escapeStringLiteralPart(exprCF,
'"') : exprCF);
- if (hasFormat) {
- buf.append(" ; ");
- buf.append("m");
- buf.append(minFracDigits);
- buf.append("M");
- buf.append(maxFracDigits);
- }
- buf.append("}");
- return buf.toString();
- }
-
- @Override
- String getASTNodeDescriptor() {
- return "#{...}";
- }
-
- @Override
- boolean heedsOpeningWhitespace() {
- return true;
- }
-
- @Override
- boolean heedsTrailingWhitespace() {
- return true;
- }
-
- private static class FormatHolder {
- final NumberFormat format;
- final Locale locale;
-
- FormatHolder(NumberFormat format, Locale locale) {
- this.format = format;
- this.locale = locale;
- }
- }
-
- @Override
- int getParameterCount() {
- return 3;
- }
-
- @Override
- Object getParameterValue(int idx) {
- switch (idx) {
- case 0: return expression;
- case 1: return Integer.valueOf(minFracDigits);
- case 2: return Integer.valueOf(maxFracDigits);
- default: throw new IndexOutOfBoundsException();
- }
- }
-
- @Override
- ParameterRole getParameterRole(int idx) {
- switch (idx) {
- case 0: return ParameterRole.CONTENT;
- case 1: return ParameterRole.MINIMUM_DECIMALS;
- case 2: return ParameterRole.MAXIMUM_DECIMALS;
- default: throw new IndexOutOfBoundsException();
- }
- }
-
- @Override
- boolean isNestedBlockRepeater() {
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java
index 4eefda1..8122e92 100644
---
a/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java
+++
b/freemarker-core/src/main/java/org/apache/freemarker/core/Configuration.java
@@ -657,7 +657,7 @@ public final class Configuration implements
TopLevelConfiguration, CustomStateSc
* <p><b>About auto-escaping</b></p>
*
* <p>
- * Auto-escaping has significance when a value is printed with
<code>${...}</code> (or <code>#{...}</code>). If
+ * Auto-escaping has significance when a value is printed with
<code>${...}</code>. If
* auto-escaping is on, FreeMarker will assume that the value is plain
text (as opposed to markup or some kind of
* rich text), so it will escape it according the current output format
(see {@link #getOutputFormat()}
* and {@link
TemplateConfiguration.Builder#setOutputFormat(OutputFormat)}). If auto-escaping
is off, FreeMarker
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
index 843e607..efdb953 100644
---
a/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
+++
b/freemarker-core/src/main/java/org/apache/freemarker/core/MutableProcessingConfiguration.java
@@ -1706,8 +1706,8 @@ public abstract class
MutableProcessingConfiguration<SelfT extends MutableProces
* {@code BigDecimal} and "bi" for {@code BigInteger}.</li>
* <li>A boolean literal: {@code true} or {@code false}
* <li>The null literal: {@code null}
- * <li>A string literal with FTL syntax, except that it can't
contain <tt>${...}</tt>-s and
- * <tt>#{...}</tt>-s. Examples: {@code "Line 1\nLine 2"} or
{@code r"C:\temp"}.
+ * <li>A string literal with FTL syntax, except that it can't
contain <tt>${...}</tt>-s.
+ * Examples: {@code "Line 1\nLine 2"} or {@code r"C:\temp"}.
* <li>A list literal (since 2.3.24) with FTL-like syntax, for
example {@code [ 'foo', 2, true ]}.
* If the parameter is expected to be array, the list will be
automatically converted to array.
* The list items can be any kind of expression, like even
object builder expressions.
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
index 89cdfaf..3ebada9 100644
---
a/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
+++
b/freemarker-core/src/main/java/org/apache/freemarker/core/_ObjectBuilderSettingEvaluator.java
@@ -510,9 +510,10 @@ public class _ObjectBuilderSettingEvaluator {
break seekTokenEnd;
} else if (c == '{') {
char prevC = src.charAt(pos - 1);
- if (prevC == '$' || prevC == '#') {
+ // Find related: [interpolation prefixes]
+ if (prevC == '$') {
throw new _ObjectBuilderSettingEvaluationException(
- "${...} and #{...} aren't allowed here.");
+ "${...} isn't allowed here.");
}
}
} else {
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/java/org/apache/freemarker/core/util/FTLUtil.java
----------------------------------------------------------------------
diff --git
a/freemarker-core/src/main/java/org/apache/freemarker/core/util/FTLUtil.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/FTLUtil.java
index 4b3adc6..8baa927 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/util/FTLUtil.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/FTLUtil.java
@@ -159,7 +159,8 @@ public final class FTLUtil {
}
private static boolean isInterpolationStart(char c) {
- return c == '$' || c == '#';
+ // Find related: [interpolation prefixes]
+ return c == '$';
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ce72f4ba/freemarker-core/src/main/javacc/FTL.jj
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/javacc/FTL.jj
b/freemarker-core/src/main/javacc/FTL.jj
index 7a39545..3214075 100644
--- a/freemarker-core/src/main/javacc/FTL.jj
+++ b/freemarker-core/src/main/javacc/FTL.jj
@@ -958,13 +958,14 @@ TOKEN:
{
<STATIC_TEXT_WS : ("\n" | "\r" | "\t" | " ")+>
|
- <STATIC_TEXT_NON_WS : (~["$", "<", "#", "[", "{", "\n", "\r", "\t", " "])+>
+ // Find related: [interpolation prefixes]
+ <STATIC_TEXT_NON_WS : (~["$", "<", "[", "{", "\n", "\r", "\t", " "])+>
|
- <STATIC_TEXT_FALSE_ALARM : "$" | "#" | "<" | "[" | "{"> // to handle a
lone dollar sign or "<" or "# or <@ with whitespace after"
+ // Find related: [interpolation prefixes]
+ <STATIC_TEXT_FALSE_ALARM : "$" | "<" | "[" | "{"> // to handle a lone
dollar sign or "<" or "# or <@ with whitespace after
|
+ // Find related: [interpolation prefixes]
<DOLLAR_INTERPOLATION_OPENING : "${"> { startInterpolation(matchedToken); }
- |
- <HASH_INTERPOLATION_OPENING : "#{"> { startInterpolation(matchedToken); }
}
<FM_EXPRESSION, IN_PAREN, NAMED_PARAMETER_EXPRESSION> SKIP :
@@ -1152,7 +1153,7 @@ TOKEN:
}
}
|
- <OPEN_MISPLACED_INTERPOLATION : "${" | "#{">
+ <OPEN_MISPLACED_INTERPOLATION : "${"> // Find related: [interpolation
prefixes]
{
if ("".length() == 0) { // prevents unreachabe "break" compilation
error in generated Java
char c = matchedToken.image.charAt(0);
@@ -2117,7 +2118,7 @@ ASTExpStringLiteral ASTExpStringLiteral(boolean
interpolate) :
result.setLocation(template, t, t);
if (interpolate && !raw) {
// TODO: This logic is broken. It can't handle literals that
contains both ${...} and $\{...}.
- if (t.image.indexOf("${") >= 0 || t.image.indexOf("#{") >= 0)
result.parseValue(token_source, outputFormat);
+ if (t.image.indexOf("${") >= 0) result.parseValue(token_source,
outputFormat);
}
return result;
}
@@ -2180,10 +2181,9 @@ ASTExpHashLiteral ASTExpHashLiteral() :
}
/**
- * A production representing the ${...}
- * that outputs a variable.
+ * ${exp}
*/
-ASTDollarInterpolation StringOutput() :
+ASTDollarInterpolation ASTDollarInterpolation() :
{
ASTExpression exp;
Token begin, end;
@@ -2206,86 +2206,6 @@ ASTDollarInterpolation StringOutput() :
}
}
-ASTHashInterpolation ASTHashInterpolation() :
-{
- ASTExpression exp;
- Token fmt = null, begin, end;
-}
-{
- begin = <HASH_INTERPOLATION_OPENING>
- exp = ASTExpression() { numberLiteralOnly(exp); }
- [
- <SEMICOLON>
- fmt = <ID>
- ]
- end = <CLOSING_CURLY_BRACKET>
- {
- MarkupOutputFormat<?> autoEscOF = autoEscaping && outputFormat
instanceof MarkupOutputFormat
- ? (MarkupOutputFormat<?>) outputFormat : null;
-
- ASTHashInterpolation result;
- if (fmt != null) {
- int minFrac = -1; // -1 indicates that the value has not been set
- int maxFrac = -1;
-
- StringTokenizer st = new StringTokenizer(fmt.image, "mM", true);
- char type = '-';
- while (st.hasMoreTokens()) {
- String token = st.nextToken();
- try {
- if (type != '-') {
- switch (type) {
- case 'm':
- if (minFrac != -1) throw new
ParseException("Invalid formatting string", template, fmt);
- minFrac = Integer.parseInt(token);
- break;
- case 'M':
- if (maxFrac != -1) throw new
ParseException("Invalid formatting string", template, fmt);
- maxFrac = Integer.parseInt(token);
- break;
- default:
- throw new ParseException("Invalid formatting
string", template, fmt);
- }
- type = '-';
- } else if (token.equals("m")) {
- type = 'm';
- } else if (token.equals("M")) {
- type = 'M';
- } else {
- throw new ParseException();
- }
- } catch (ParseException e) {
- throw new ParseException("Invalid format specifier " +
fmt.image, template, fmt);
- } catch (NumberFormatException e) {
- throw new ParseException("Invalid number in the format
specifier " + fmt.image, template, fmt);
- }
- }
-
- if (maxFrac == -1) {
- if (minFrac == -1) {
- throw new ParseException(
- "Invalid format specification, at least
one of m and M must be specified!", template, fmt);
- }
- maxFrac = minFrac;
- } else if (minFrac == -1) {
- minFrac = 0;
- }
- if (minFrac > maxFrac) {
- throw new ParseException(
- "Invalid format specification, min cannot be
greater than max!", template, fmt);
- }
- if (minFrac > 50 || maxFrac > 50) {// sanity check
- throw new ParseException("Cannot specify more than 50 fraction
digits", template, fmt);
- }
- result = new ASTHashInterpolation(exp, minFrac, maxFrac,
autoEscOF);
- } else { // if format != null
- result = new ASTHashInterpolation(exp, autoEscOF);
- }
- result.setLocation(template, begin, end);
- return result;
- }
-}
-
ASTElement If() :
{
Token start, end, t;
@@ -3724,9 +3644,7 @@ TemplateElements MixedContentElements() :
(
elem = PCData()
|
- elem = StringOutput()
- |
- elem = ASTHashInterpolation()
+ elem = ASTDollarInterpolation()
|
elem = FreemarkerDirective()
)
@@ -3770,9 +3688,7 @@ ASTImplicitParent ASTImplicitParent() :
(
elem = PCData()
|
- elem = StringOutput()
- |
- elem = ASTHashInterpolation()
+ elem = ASTDollarInterpolation()
|
elem = FreemarkerDirective()
)
@@ -3814,8 +3730,7 @@ ASTElement OptionalBlock() :
}
/**
- * A production freemarker text that may contain
- * ${...} and #{...} but no directives.
+ * A production freemarker text that may contain ${...}, but no directives.
*/
ASTElement FreeMarkerText() :
{
@@ -3827,9 +3742,7 @@ ASTElement FreeMarkerText() :
(
elem = PCData()
|
- elem = StringOutput()
- |
- elem = ASTHashInterpolation()
+ elem = ASTDollarInterpolation() // Find related: [interpolation
prefixes]
)
{
if (begin == null) {
@@ -4063,15 +3976,7 @@ List<Object> StaticTextAndInterpolations() :
}
|
(
- LOOKAHEAD(<DOLLAR_INTERPOLATION_OPENING>)
- (
- interpolation = StringOutput()
- )
- |
- LOOKAHEAD(<HASH_INTERPOLATION_OPENING>)
- (
- interpolation = ASTHashInterpolation()
- )
+ interpolation = ASTDollarInterpolation()
)
{
if (staticTextCollector != null) {