freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [1/2] incubator-freemarker git commit: Removed the long deprecated `?exists`; it's converted to the `??` operator.
Date Mon, 23 Oct 2017 19:36:16 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 ba722858c -> d357910a5


Removed the long deprecated `?exists`; it's converted to the `??` operator.


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

Branch: refs/heads/3
Commit: 372cc486a547586df853b3fe49de0117b3e2a08a
Parents: ba72285
Author: ddekany <ddekany@apache.org>
Authored: Mon Oct 23 21:35:16 2017 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Mon Oct 23 21:35:16 2017 +0200

----------------------------------------------------------------------
 FM3-CHANGE-LOG.txt                              |  2 +-
 .../core/FM2ASTToFM3SourceConverter.java        | 89 +++++++++++++-------
 .../freemarker/converter/ConverterUtils.java    | 10 +++
 .../converter/FM2ToFM3ConverterTest.java        | 10 +++
 .../core/ParsingErrorMessagesTest.java          |  1 +
 .../src/test/resources/__conversion-markers.txt |  0
 .../core/templatesuite/templates/boolean.ftl    |  8 +-
 .../core/templatesuite/templates/comment.ftl    |  2 +-
 .../templates/default-object-wrapper.ftl        |  6 +-
 .../templates/existence-operators.ftl           | 22 ++---
 .../core/templatesuite/templates/import.ftl     |  2 +-
 .../core/templatesuite/templates/import_lib.ftl |  2 +-
 .../core/templatesuite/templates/include.ftl    |  2 +-
 .../core/templatesuite/templates/included.ftl   |  2 +-
 .../core/templatesuite/templates/macros.ftl     |  2 +-
 .../core/templatesuite/templates/noparse.ftl    |  2 +-
 .../core/templatesuite/templates/precedence.ftl |  2 +-
 .../core/templatesuite/templates/var-layers.ftl |  6 +-
 .../apache/freemarker/core/ASTExpBuiltIn.java   |  3 +-
 .../core/BuiltInsForExistenceHandling.java      | 12 ---
 .../core/model/impl/DefaultObjectWrapper.java   |  4 +-
 21 files changed, 113 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/FM3-CHANGE-LOG.txt
----------------------------------------------------------------------
diff --git a/FM3-CHANGE-LOG.txt b/FM3-CHANGE-LOG.txt
index 494b7eb..d0f3821 100644
--- a/FM3-CHANGE-LOG.txt
+++ b/FM3-CHANGE-LOG.txt
@@ -92,7 +92,7 @@ Node: Changes already mentioned above aren't repeated here!
   invocation of the function or macro.
 - Removed some long deprecated built-ins:
   - `webSafe` (converted to `html`)
-  - TODO Add the further ones here as they are removed
+  - `exists` (converted to the `??` operator)
 - Comma is now required between sequence literal items (such as `[a, b, c]`). It's not well
known, but in FM2 the comma
   could be omitted.
 - #include has no "encoding" parameter anymore (as now only the Configuration is responsible
ofr deciding the encoding)

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/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 0242882..fc85424 100644
--- a/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
+++ b/freemarker-converter/src/main/java/freemarker/core/FM2ASTToFM3SourceConverter.java
@@ -33,8 +33,8 @@ import java.util.Set;
 import org.apache.commons.io.IOUtils;
 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.converter.ConverterUtils;
 import org.apache.freemarker.core.util.TemplateLanguageUtils;
 import org.apache.freemarker.core.util._ClassUtils;
 import org.apache.freemarker.core.util._NullArgumentException;
@@ -1819,36 +1819,47 @@ public class FM2ASTToFM3SourceConverter {
         // <lho>?biName
         printExp(lho);
         int pos = getEndPositionExclusive(lho);
-
-        // lho<?>biName
-        pos = printSeparatorAndWSAndExpComments(pos, "?");
-
-        // lho?<biName>
-        print(convertBuiltInName(rho));
-
-        if (node instanceof BuiltInWithParseTimeParameters) {
-            // lho?biName<(>
-            pos = getPositionAfterIdentifier(pos);
-            pos = printSeparatorAndWSAndExpComments(pos, "(");
-            int paramCnt = node.getParameterCount();
-            for (int paramIdx = 2; paramIdx < paramCnt; paramIdx++) {
-                Expression argValue = getParam(node, paramIdx, ParameterRole.ARGUMENT_VALUE,
Expression.class);
-                printExp(argValue);
-                pos = getEndPositionExclusive(argValue);
-
-                if (paramIdx + 1 < paramCnt) {
-                    printSeparatorAndWSAndExpComments(pos, ",");
+        
+        if (rho.equals("exists")) {
+            // lho?exists -> lho??
+
+            pos = printWSAndExpCommentsIfContainsComment(pos); // lho< >?exists
+            pos = skipRequiredString(pos, "?"); // lho<?>exists
+            print("??");
+            pos = printWSAndExpCommentsIfContainsComment(pos); // lho?< >exists
+            pos = getPositionAfterIdentifier(pos); // lho?<exists>
+            assertParamCount(node, 2);
+        } else {
+            // lho<?>biName
+            pos = printSeparatorAndWSAndExpComments(pos, "?");
+    
+            // lho?<biName>
+            print(convertBuiltInName(rho));
+    
+            if (node instanceof BuiltInWithParseTimeParameters) {
+                // lho?biName<(>
+                pos = getPositionAfterIdentifier(pos);
+                pos = printSeparatorAndWSAndExpComments(pos, "(");
+                int paramCnt = node.getParameterCount();
+                for (int paramIdx = 2; paramIdx < paramCnt; paramIdx++) {
+                    Expression argValue = getParam(node, paramIdx, ParameterRole.ARGUMENT_VALUE,
Expression.class);
+                    printExp(argValue);
+                    pos = getEndPositionExclusive(argValue);
+    
+                    if (paramIdx + 1 < paramCnt) {
+                        printSeparatorAndWSAndExpComments(pos, ",");
+                    }
                 }
+                pos = printWSAndExpComments(pos);
+                boolean endChar = src.charAt(pos) == ')';
+                assertNodeContent(pos == getEndPositionInclusive(node), node,
+                        "Actual end position doesn't match node end position.");
+                assertNodeContent(endChar, node,
+                        "Expected ')' but found {}.");
+                print(')');
+            } else {
+                assertParamCount(node, 2);
             }
-            pos = printWSAndExpComments(pos);
-            boolean endChar = src.charAt(pos) == ')';
-            assertNodeContent(pos == getEndPositionInclusive(node), node,
-                    "Actual end position doesn't match node end position.");
-            assertNodeContent(endChar, node,
-                    "Expected ')' but found {}.");
-            print(')');
-        } else {
-            assertParamCount(node, 2);
         }
     }
 
@@ -2248,7 +2259,7 @@ public class FM2ASTToFM3SourceConverter {
         int parameterCount = node.getParameterCount();
         assertNodeContent(parameterCount == 1, node,
                 "Node expected to have exactly 1 parameter, but had {}.", parameterCount);
-        return (T) getParam(node, 0, role, valueClass);
+        return getParam(node, 0, role, valueClass);
     }
 
     @SuppressWarnings("unchecked")
@@ -2397,6 +2408,15 @@ public class FM2ASTToFM3SourceConverter {
         return pos;
     }
 
+    private int printWSAndExpCommentsIfContainsComment(int pos) throws ConverterException
{
+        String sep = readWSAndExpComments(pos);
+        if (!ConverterUtils.isWhitespaceOnly(sep)) {
+            printWithConvertedExpComments(sep);
+        }
+        pos += sep.length();
+        return pos;
+    }
+    
     private int printSeparatorAndWSAndExpComments(int pos, String separator) throws ConverterException
{
         return printSeparatorAndWSAndExpComments(pos, separator, false, null);
     }
@@ -2412,7 +2432,7 @@ public class FM2ASTToFM3SourceConverter {
             throws ConverterException {
         return printSeparatorAndWSAndExpComments(pos, separator, true, separatorPosInOutput);
     }
-
+    
     private int printSeparatorAndWSAndExpComments(int startPos, String separatorSymbol, boolean
separatorOptional,
             _ObjectHolder<Integer> separatorPosInOutput)
             throws ConverterException {
@@ -2442,6 +2462,13 @@ public class FM2ASTToFM3SourceConverter {
             return pos;
         }
     }
+    
+    private int skipRequiredString(int pos, String s) throws ConverterException {
+        if (!src.startsWith(s, pos)) {
+            throw new ConverterException("Expected " + _StringUtils.jQuote(s) + " at position
" + pos + ".");
+        }
+        return pos + s.length();
+    }
 
     private int getPositionAfterIdentifier(int startPos) throws ConverterException {
         return getPositionAfterIdentifier(startPos, false);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-converter/src/main/java/org/apache/freemarker/converter/ConverterUtils.java
----------------------------------------------------------------------
diff --git a/freemarker-converter/src/main/java/org/apache/freemarker/converter/ConverterUtils.java
b/freemarker-converter/src/main/java/org/apache/freemarker/converter/ConverterUtils.java
index cbe3866..c8c9a24 100644
--- a/freemarker-converter/src/main/java/org/apache/freemarker/converter/ConverterUtils.java
+++ b/freemarker-converter/src/main/java/org/apache/freemarker/converter/ConverterUtils.java
@@ -19,6 +19,7 @@
 
 package org.apache.freemarker.converter;
 
+/** Don't use this; used internally by FreeMarker, might changes without notice. */
 public final class ConverterUtils {
 
     private ConverterUtils() {
@@ -44,4 +45,13 @@ public final class ConverterUtils {
     public static boolean isQuotationChar(char q) {
         return q == '\'' || q == '\"';
     }
+    
+    public static boolean isWhitespaceOnly(String s) {
+        for (int i = 0; i < s.length(); i++) {
+            if (!Character.isWhitespace(s.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
----------------------------------------------------------------------
diff --git a/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
b/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
index 632fb08..2fc387f 100644
--- a/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
+++ b/freemarker-converter/src/test/java/org/freemarker/converter/FM2ToFM3ConverterTest.java
@@ -44,6 +44,7 @@ import freemarker.template.Configuration;
 
 public class FM2ToFM3ConverterTest extends ConverterTest {
 
+    @Override
     protected void createSourceFiles() throws IOException {
         //
     }
@@ -494,6 +495,15 @@ public class FM2ToFM3ConverterTest extends ConverterTest {
     }
 
     @Test
+    public void testRemovedExistenceBuiltIns() throws IOException, ConverterException {
+        assertConverted("${s??}", "${s?exists}");
+        assertConverted("${s??}", "${s\n\t\t?exists}");
+        assertConverted("${s <#-- c --> ??}", "${s <#-- c --> ?exists}");
+        assertConverted("${s?? <#-- c --> }", "${s? <#-- c --> exists}");
+        assertConverted("${s?? <#-- c --> }", "${s?exists <#-- c --> }");
+    }
+    
+    @Test
     public void testTagEndCharGlitch() throws IOException, ConverterException {
         assertConverted("<#assign x = 1>x", "<#assign x = 1]x");
         assertConverted("<#if x[0] == 1>x<#else>y</#if>", "<#if x[0]
== 1]x<#else]y</#if]");

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
b/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
index 731a063..e788dd8 100644
--- a/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
+++ b/freemarker-core-test/src/test/java/org/apache/freemarker/core/ParsingErrorMessagesTest.java
@@ -86,6 +86,7 @@ public class ParsingErrorMessagesTest {
         assertErrorContains("${x?datetime}", "The correct name is: dateTime");
         assertErrorContains("${x?datetimeIfUnknown}", "The correct name is: dateTimeIfUnknown");
         assertErrorContains("${x?datetime_if_unknown}", "The correct name is: dateTimeIfUnknown");
+        assertErrorContains("${x?exists}", "someExpression??");
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/__conversion-markers.txt
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/__conversion-markers.txt b/freemarker-core-test/src/test/resources/__conversion-markers.txt
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/boolean.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/boolean.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/boolean.ftl
index ae2c399..9780377 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/boolean.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/boolean.ftl
@@ -78,13 +78,13 @@
  
 <p>Now test list models:</p>
 
-<p><#if list1?exists>
+<p><#if list1??>
     list1 succeeded.<br />
 <#else>
     list1 failed.<br />
 </#if></p>
 
-<p><#if list2?exists>
+<p><#if list2??>
     list2 succeeded.<br />
 <#else>
     list2 failed.<br />
@@ -92,13 +92,13 @@
 
 <p>Test hash models:</p>
 
-<p><#if hash1?exists>
+<p><#if hash1??>
     hash1 succeeded: ${hash1.temp}<br />
 <#else>
     hash1 failed: ${hash1.temp}<br />
 </#if></p>
 
-<p><#if hash2?exists>
+<p><#if hash2??>
     hash2 succeeded.<br />
 <#else>
     hash2 failed.<br />

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/comment.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/comment.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/comment.ftl
index c5cb54b..8cd45c5 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/comment.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/comment.ftl
@@ -32,7 +32,7 @@ A more rigorous test, showing that we're not faking it:
 ${message@#$%&}
 
 --><#-- > --><#-- -> --><#-- -- --><#-- -- > -->
-<#if message?exists>
+<#if message??>
 	<p>Message exists!
 	<#--
 		...and even generates output!

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/default-object-wrapper.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/default-object-wrapper.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/default-object-wrapper.ftl
index 21efc05..44295b3 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/default-object-wrapper.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/default-object-wrapper.ftl
@@ -31,8 +31,8 @@ ${list[0]}
 ${map.key}
 ${map?api.get(objKey)}
 ${obj.foo}
-<#if obj.foo?exists>hasfoo<#else>nofoo</#if>
-<#if obj.baz?exists>hasbaz<#else>nobaz</#if>
+<#if obj.foo??>hasfoo<#else>nofoo</#if>
+<#if obj.baz??>hasbaz<#else>nobaz</#if>
 ${obj.bar[0]}
 ${obj.getFoo()}
 ${obj.overloaded(1?int)}
@@ -51,7 +51,7 @@ ${enum.TWO}
 ${enum.THREE}
 ${(enum.ONE == enum.ONE)?string("true", "false")}
 ${(enum.ONE == enum.TWO)?string("true", "false")}
-${enums["org.apache.freemarker.core.templatesuite.models.BeanTestClass"]?exists?string("true",
"false")}
+${enums["org.apache.freemarker.core.templatesuite.models.BeanTestClass"]???string("true",
"false")}
 ${obj.something}
 ${obj.publicInner.x}
 ${obj.publicInner.m()}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/existence-operators.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/existence-operators.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/existence-operators.ftl
index 916d91e..f8bc788 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/existence-operators.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/existence-operators.ftl
@@ -30,8 +30,8 @@
 <@assertEquals actual=v?default('-') expected='-' />
 <@assertEquals actual=(v)?default('-') expected='-' />
 <@isNonFastIRE>${v}</@> <#-- To check that it isn't an IRE.FAST_INSTANCE -->
-<@assertEquals actual=v?exists expected=false />
-<@assertEquals actual=(v)?exists expected=false />
+<@assertEquals actual=v?? expected=false />
+<@assertEquals actual=(v)?? expected=false />
 <@assertEquals actual=v?ifExists expected='' />
 <@assertEquals actual=(v)?ifExists expected='' />
 <@assertEquals actual=v?hasContent expected=false />
@@ -50,15 +50,15 @@
 	<@assert (v)?? />
 	<@assertEquals actual=v?default('-') expected=v />
 	<@assertEquals actual=(v)?default('-') expected=v />
-	<@assert v?exists />
-	<@assert (v)?exists />
+	<@assert v?? />
+	<@assert (v)?? />
 	<@assertEquals actual=v?ifExists expected=v />
 	<@assertEquals actual=(v)?ifExists expected=v />
 	<@assert v?hasContent />
 	<@assert (v)?hasContent />
 </#list>
 <@assert !v?? />
-<@assert !v?exists />
+<@assert !v?? />
 <@isNonFastIRE>${v}</@> <#-- To check that it isn't an IRE.FAST_INSTANCE -->
 
 <@isIRE>${u.v!'-'}</@>
@@ -67,8 +67,8 @@
 <@assertEquals actual=(u.v)?? expected=false />
 <@isIRE>${u.v?default('-')}</@>
 <@assertEquals actual=(u.v)?default('-') expected='-' />
-<@isIRE>${u.v?exists}</@>
-<@assertEquals actual=(u.v)?exists expected=false />
+<@isIRE>${u.v??}</@>
+<@assertEquals actual=(u.v)?? expected=false />
 <@isIRE>${u.v?ifExists}</@>
 <@assertEquals actual=(u.v)?ifExists expected='' />
 <@isIRE>${u.v?hasContent}</@>
@@ -81,8 +81,8 @@
 <@assertEquals actual=(u.v)?? expected=false />
 <@assertEquals actual=u.v?default('-') expected='-' />
 <@assertEquals actual=(u.v)?default('-') expected='-' />
-<@assertEquals actual=u.v?exists expected=false />
-<@assertEquals actual=(u.v)?exists expected=false />
+<@assertEquals actual=u.v?? expected=false />
+<@assertEquals actual=(u.v)?? expected=false />
 <@assertEquals actual=u.v?ifExists expected='' />
 <@assertEquals actual=(u.v)?ifExists expected='' />
 <@assertEquals actual=u.v?hasContent expected=false />
@@ -95,8 +95,8 @@
 <@assert (u.v)?? />
 <@assertEquals actual=u.v?default('-') expected='V' />
 <@assertEquals actual=(u.v)?default('-') expected='V' />
-<@assert u.v?exists />
-<@assert (u.v)?exists />
+<@assert u.v?? />
+<@assert (u.v)?? />
 <@assertEquals actual=u.v?ifExists expected='V' />
 <@assertEquals actual=(u.v)?ifExists expected='V' />
 <@assert u.v?hasContent />

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import.ftl
index bddd857..0e80271 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import.ftl
@@ -20,7 +20,7 @@
 <#-- import "/import_lib.ftl" as my -->
 --
 
-<#if mail?exists || test?exists>
+<#if mail?? || test??>
   <#stop "mail or test should not exist">
 </#if>
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import_lib.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import_lib.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import_lib.ftl
index 68ba07f..84ef6c6 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import_lib.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/import_lib.ftl
@@ -19,7 +19,7 @@
 <#macro test foo>
   Test ${foo}.
   Email: ${mail}
-  <#if .main.mail?exists>
+  <#if .main.mail??>
     Email in the root: ${.main.mail}
   </#if>
 </#macro>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/include.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/include.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/include.ftl
index 3e997e7..971e972 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/include.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/include.ftl
@@ -26,7 +26,7 @@
 
 ${message}
 
-<#if message?exists>
+<#if message??>
 	<p>Message exists!
 </#if>
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/included.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/included.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/included.ftl
index f711a67..ba9beb8 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/included.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/included.ftl
@@ -18,7 +18,7 @@
 -->
 <p>A test of included files:</p>
 
-<#if .globals.message?exists>
+<#if .globals.message??>
 	<p>Message exists!:<br />
         ${.globals.message}</p>
 <#else>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/macros.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/macros.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/macros.ftl
index 7ef6395..a8c8d54 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/macros.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/macros.ftl
@@ -55,7 +55,7 @@
    alt="About Us"
 />
 
-<#if var?exists>
+<#if var??>
    Something is wrong here.
 <#else>
    Good.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/noparse.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/noparse.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/noparse.ftl
index cc85c9c..d9e6438 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/noparse.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/noparse.ftl
@@ -32,7 +32,7 @@ A more rigorous test, showing that we're not faking it:
 ${message@#$%&}
 
 </#noParse>
-<#if message?exists>
+<#if message??>
 	<p>Message exists!
 	<#noParse>
 		...and even generates output!

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/precedence.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/precedence.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/precedence.ftl
index 472b076..1bf3434 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/precedence.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/precedence.ftl
@@ -32,7 +32,7 @@
 <br />
 <br />
 
-<#if patate1?exists && patate2 == patate3>
+<#if patate1?? && patate2 == patate3>
 ##########
 </#if>
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl
----------------------------------------------------------------------
diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl
b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl
index 80e5c2a..e11e602 100644
--- a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl
+++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl
@@ -24,9 +24,9 @@ ${x} = ${.main.x} = ${.namespace.x}
 <#global x = 6>
 ${.globals.x} but ${.dataModel.x} = 4
 ${y} = ${.globals.y} = ${.dataModel.y?default("ERROR")}
-Invisiblity test 1.: <#if .main.y?exists || .namespace.y?exists>failed<#else>passed</#if>
-Invisiblity test 2.: <#if .main.z?exists || .namespace.z?exists>failed<#else>passed</#if>
-Invisiblity test 3.: <#global q = 1><#if .main.q?exists || .namespace.q?exists ||
.dataModel.q?exists>failed<#else>passed</#if>
+Invisiblity test 1.: <#if .main.y?? || .namespace.y??>failed<#else>passed</#if>
+Invisiblity test 2.: <#if .main.z?? || .namespace.z??>failed<#else>passed</#if>
+Invisiblity test 3.: <#global q = 1><#if .main.q?? || .namespace.q?? || .dataModel.q??>failed<#else>passed</#if>
 --
 <@lib.foo/>
 --

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java
index 322d662..055632b 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java
@@ -104,7 +104,6 @@ abstract class ASTExpBuiltIn extends ASTExpression implements Cloneable
{
         putBI("ensureStartsWith", new BuiltInsForStringsBasic.ensure_starts_withBI());
         putBI("esc", new escBI());
         putBI("eval", new evalBI());
-        putBI("exists", new BuiltInsForExistenceHandling.existsBI());
         putBI("first", new firstBI());
         putBI("float", new floatBI());
         putBI("floor", new floorBI());
@@ -329,6 +328,8 @@ abstract class ASTExpBuiltIn extends ASTExpression implements Cloneable
{
 
             if (correctedKey != null) {
                 sb.append("\nThe correct name is: ").append(correctedKey);
+            } else if (key.equals("exists")) {
+                sb.append("\nUse someExpression?? instead of someExpression?exists.");
             } else {
                 sb.append(
                         "\nHelp (latest version): http://freemarker.org/docs/ref_builtins.html;
"

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForExistenceHandling.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForExistenceHandling.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForExistenceHandling.java
index f7c5258..61d33dd 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForExistenceHandling.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForExistenceHandling.java
@@ -107,18 +107,6 @@ class BuiltInsForExistenceHandling {
         };
     }
     
-    static class existsBI extends BuiltInsForExistenceHandling.ExistenceBuiltIn {
-        @Override
-        TemplateModel _eval(Environment env) throws TemplateException {
-            return evalMaybeNonexistentTarget(env) == null ? TemplateBooleanModel.FALSE :
TemplateBooleanModel.TRUE;
-        }
-    
-        @Override
-        boolean evalToBoolean(Environment env) throws TemplateException {
-            return _eval(env) == TemplateBooleanModel.TRUE;
-        }
-    }
-
     static class has_contentBI extends BuiltInsForExistenceHandling.ExistenceBuiltIn {
         @Override
         TemplateModel _eval(Environment env) throws TemplateException {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/372cc486/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 2d78119..b5b3441 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
@@ -1617,7 +1617,7 @@ public class DefaultObjectWrapper implements RichObjectWrapper {
          * <p>If this property is <tt>false</tt> (the default) then an
attempt to read
          * a missing bean property is the same as reading an existing bean property whose
          * value is <tt>null</tt>. The template can't tell the difference, and
thus always
-         * can use <tt>?default('something')</tt> and <tt>?exists</tt>
and similar built-ins
+         * can use <tt>?default('something')</tt> and <tt>??</tt>
and similar expressions
          * to handle the situation.
          *
          * <p>If this property is <tt>true</tt> then an attempt to read
a bean propertly in
@@ -1625,7 +1625,7 @@ public class DefaultObjectWrapper implements RichObjectWrapper {
          * object (as opposed to just holding <tt>null</tt> value) will cause
          * {@link InvalidPropertyException}, which can't be suppressed in the template
          * (not even with <tt>myBean.noSuchProperty?default('something')</tt>).
This way
-         * <tt>?default('something')</tt> and <tt>?exists</tt> and
similar built-ins can be used to
+         * <tt>?default('something')</tt> and <tt>??</tt> and similar
expressions can be used to
          * handle existing properties whose value is <tt>null</tt>, without the
risk of
          * hiding typos in the property names. Typos will always cause error. But mind you,
it
          * goes against the basic approach of FreeMarker, so use this feature only if you
really


Mime
View raw message