Removing _TemplateAPI and fetting rid of most _CoreAPI methods, as now things that technically belong together tend to be in the same package usually. Some other minor cleanup.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/946a4237 Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/946a4237 Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/946a4237 Branch: refs/heads/3 Commit: 946a4237286046805b6766c2c8e54431540e7352 Parents: dcb0e06 Author: ddekany <ddek...@apache.org> Authored: Sun Feb 26 00:32:50 2017 +0100 Committer: ddekany <ddek...@apache.org> Committed: Sun Feb 26 01:17:00 2017 +0100 ---------------------------------------------------------------------- .../freemarker/core/ASTDirAssignment.java | 8 +- .../core/ASTDirAssignmentsContainer.java | 2 +- .../core/ASTDirAttemptRecoverContainer.java | 2 +- .../apache/freemarker/core/ASTDirAutoEsc.java | 2 +- .../org/apache/freemarker/core/ASTDirBreak.java | 2 +- .../core/ASTDirCapturingAssignment.java | 2 +- .../org/apache/freemarker/core/ASTDirCase.java | 2 +- .../apache/freemarker/core/ASTDirCompress.java | 2 +- .../freemarker/core/ASTDirElseOfList.java | 2 +- .../apache/freemarker/core/ASTDirEscape.java | 2 +- .../apache/freemarker/core/ASTDirFallback.java | 2 +- .../org/apache/freemarker/core/ASTDirFlush.java | 2 +- .../core/ASTDirIfElseIfElseContainer.java | 2 +- .../freemarker/core/ASTDirIfOrElseOrElseIf.java | 4 +- .../apache/freemarker/core/ASTDirImport.java | 2 +- .../apache/freemarker/core/ASTDirInclude.java | 2 +- .../org/apache/freemarker/core/ASTDirItems.java | 2 +- .../org/apache/freemarker/core/ASTDirList.java | 4 +- .../core/ASTDirListElseContainer.java | 2 +- .../org/apache/freemarker/core/ASTDirMacro.java | 2 +- .../apache/freemarker/core/ASTDirNested.java | 2 +- .../apache/freemarker/core/ASTDirNoAutoEsc.java | 2 +- .../apache/freemarker/core/ASTDirNoEscape.java | 2 +- .../freemarker/core/ASTDirOutputFormat.java | 2 +- .../apache/freemarker/core/ASTDirRecover.java | 2 +- .../apache/freemarker/core/ASTDirRecurse.java | 2 +- .../apache/freemarker/core/ASTDirReturn.java | 4 +- .../org/apache/freemarker/core/ASTDirSep.java | 2 +- .../apache/freemarker/core/ASTDirSetting.java | 6 +- .../org/apache/freemarker/core/ASTDirStop.java | 2 +- .../apache/freemarker/core/ASTDirSwitch.java | 2 +- .../apache/freemarker/core/ASTDirTOrTrOrTl.java | 2 +- .../apache/freemarker/core/ASTDirTransform.java | 2 +- .../freemarker/core/ASTDirUserDefined.java | 2 +- .../org/apache/freemarker/core/ASTDirVisit.java | 2 +- .../apache/freemarker/core/ASTDirective.java | 84 +++++++++ .../apache/freemarker/core/ASTExpBuiltIn.java | 2 +- .../freemarker/core/ASTImplicitParent.java | 2 +- .../apache/freemarker/core/ASTStaticText.java | 6 +- .../apache/freemarker/core/Configurable.java | 31 +++- .../apache/freemarker/core/Configuration.java | 71 +++++-- .../org/apache/freemarker/core/Environment.java | 2 +- .../org/apache/freemarker/core/MessageUtil.java | 2 + .../NestedContentNotSupportedException.java | 8 +- .../org/apache/freemarker/core/Template.java | 6 +- .../freemarker/core/TemplateConfiguration.java | 7 +- .../freemarker/core/TemplateException.java | 18 +- .../org/apache/freemarker/core/_ASTElement.java | 2 +- .../org/apache/freemarker/core/_CoreAPI.java | 184 +++---------------- .../core/_ErrorDescriptionBuilder.java | 4 +- .../apache/freemarker/core/_TemplateAPI.java | 119 ------------ .../impl/DefaultObjectWrapperConfiguration.java | 2 +- .../core/model/impl/beans/BeansWrapper.java | 10 +- .../impl/beans/BeansWrapperConfiguration.java | 4 +- .../freemarker/servlet/InitParamParser.java | 2 + src/main/javacc/FTL.jj | 12 +- .../org/apache/freemarker/core/ASTPrinter.java | 10 +- .../freemarker/core/ConfigurationTest.java | 2 +- .../model/impl/DefaultObjectWrapperTest.java | 8 +- .../freemarker/test/util/AssertDirective.java | 3 +- .../test/util/AssertEqualsDirective.java | 3 +- 61 files changed, 290 insertions(+), 400 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java b/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java index f34f0fb..16f7a37 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java @@ -30,7 +30,7 @@ import org.apache.freemarker.core.util._StringUtil; * This is also used as the child of {@link ASTDirAssignmentsContainer}, if there are multiple assignments in the same * tag, like in {@code <#local x=1 y=2>}. */ -final class ASTDirAssignment extends _ASTElement { +final class ASTDirAssignment extends ASTDirective { // These must not clash with ArithmeticExpression.TYPE_... constants: private static final int OPERATOR_TYPE_EQUALS = 0x10000; @@ -162,10 +162,10 @@ final class ASTDirAssignment extends _ASTElement { } if (operatorType == OPERATOR_TYPE_PLUS_PLUS) { - value = ASTExpAddOrConcat._evalOnNumbers(env, getParentElement(), lhoNumber, ONE); + value = ASTExpAddOrConcat._evalOnNumbers(env, getParent(), lhoNumber, ONE); } else if (operatorType == OPERATOR_TYPE_MINUS_MINUS) { value = ArithmeticExpression._eval( - env, getParentElement(), lhoNumber, ArithmeticExpression.TYPE_SUBSTRACTION, ONE); + env, getParent(), lhoNumber, ArithmeticExpression.TYPE_SUBSTRACTION, ONE); } else { // operatorType == ArithmeticExpression.TYPE_... Number rhoNumber = valueExp.evalToNumber(env); value = ArithmeticExpression._eval(env, this, lhoNumber, operatorType, rhoNumber); @@ -184,7 +184,7 @@ final class ASTDirAssignment extends _ASTElement { @Override protected String dump(boolean canonical) { StringBuilder buf = new StringBuilder(); - String dn = getParentElement() instanceof ASTDirAssignmentsContainer ? null : getNodeTypeSymbol(); + String dn = getParent() instanceof ASTDirAssignmentsContainer ? null : getNodeTypeSymbol(); if (dn != null) { if (canonical) buf.append("<"); buf.append(dn); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java b/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java index d0a1a2a..6f426cd 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java @@ -26,7 +26,7 @@ import java.io.IOException; * Each assignment is represented by a {@link ASTDirAssignment} child element. * If there's only one assignment, its usually just a {@link ASTDirAssignment} without parent {@link ASTDirAssignmentsContainer}. */ -final class ASTDirAssignmentsContainer extends _ASTElement { +final class ASTDirAssignmentsContainer extends ASTDirective { private int scope; private ASTExpression namespaceExp; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java b/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java index e1eeb61..8c41cb9 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java @@ -25,7 +25,7 @@ import java.io.IOException; * AST directive node: Holder for the attempted section of the {@code #attempt} element and of the nested * {@code #recover} element ({@link ASTDirRecover}). */ -final class ASTDirAttemptRecoverContainer extends _ASTElement { +final class ASTDirAttemptRecoverContainer extends ASTDirective { private _ASTElement attemptedSection; private ASTDirRecover recoverySection; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java b/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java index ed79109..d5fb6cb 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #autoEsc} */ -final class ASTDirAutoEsc extends _ASTElement { +final class ASTDirAutoEsc extends ASTDirective { ASTDirAutoEsc(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirBreak.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirBreak.java b/src/main/java/org/apache/freemarker/core/ASTDirBreak.java index df10697..522009c 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirBreak.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirBreak.java @@ -22,7 +22,7 @@ package org.apache.freemarker.core; /** * AST directive node: {@code #break} */ -final class ASTDirBreak extends _ASTElement { +final class ASTDirBreak extends ASTDirective { @Override _ASTElement[] accept(Environment env) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java b/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java index 0aa5647..f61df3b 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java @@ -33,7 +33,7 @@ import org.apache.freemarker.core.outputformat.MarkupOutputFormat; /** * AST directive node: Like {@code <#local x>...</#local>}. */ -final class ASTDirCapturingAssignment extends _ASTElement { +final class ASTDirCapturingAssignment extends ASTDirective { private final String varName; private final ASTExpression namespaceExp; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirCase.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirCase.java b/src/main/java/org/apache/freemarker/core/ASTDirCase.java index 7e8eff5..c3ff6b3 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirCase.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirCase.java @@ -22,7 +22,7 @@ package org.apache.freemarker.core; /** * AST directive node: {@code #case} (inside a {@code #switch}) */ -final class ASTDirCase extends _ASTElement { +final class ASTDirCase extends ASTDirective { final int TYPE_CASE = 0; final int TYPE_DEFAULT = 1; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirCompress.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirCompress.java b/src/main/java/org/apache/freemarker/core/ASTDirCompress.java index fb4c226..cd5f291 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirCompress.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirCompress.java @@ -30,7 +30,7 @@ import org.apache.freemarker.core.util.StandardCompress; * * @see org.apache.freemarker.core.util.StandardCompress */ -final class ASTDirCompress extends _ASTElement { +final class ASTDirCompress extends ASTDirective { ASTDirCompress(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java b/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java index 10e60c9..7a45c6b 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #else} inside a {@code #list}. */ -final class ASTDirElseOfList extends _ASTElement { +final class ASTDirElseOfList extends ASTDirective { ASTDirElseOfList(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirEscape.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirEscape.java b/src/main/java/org/apache/freemarker/core/ASTDirEscape.java index 721ddf6..f4fd208 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirEscape.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirEscape.java @@ -27,7 +27,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST directive node: {@code #escape}. */ -class ASTDirEscape extends _ASTElement { +class ASTDirEscape extends ASTDirective { private final String variable; private final ASTExpression expr; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirFallback.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirFallback.java b/src/main/java/org/apache/freemarker/core/ASTDirFallback.java index 2318325..ceb20c5 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirFallback.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirFallback.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #fallback}. */ -final class ASTDirFallback extends _ASTElement { +final class ASTDirFallback extends ASTDirective { @Override _ASTElement[] accept(Environment env) throws IOException, TemplateException { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirFlush.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirFlush.java b/src/main/java/org/apache/freemarker/core/ASTDirFlush.java index ed06d73..7a6a492 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirFlush.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirFlush.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #flush} */ -final class ASTDirFlush extends _ASTElement { +final class ASTDirFlush extends ASTDirective { @Override _ASTElement[] accept(Environment env) throws IOException { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java b/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java index fc803e6..09593ff 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java @@ -26,7 +26,7 @@ import java.io.IOException; * Each such block is a nested {@link ASTDirIfOrElseOrElseIf}. Note that if an {@code #if} stands alone, * {@link ASTDirIfOrElseOrElseIf} doesn't need this parent element. */ -final class ASTDirIfElseIfElseContainer extends _ASTElement { +final class ASTDirIfElseIfElseContainer extends ASTDirective { ASTDirIfElseIfElseContainer(ASTDirIfOrElseOrElseIf block) { setChildBufferCapacity(1); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java b/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java index d604fd5..3b85038 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java @@ -28,7 +28,7 @@ import org.apache.freemarker.core.util.BugException; * {@code #elseif}. Note that when an {@code #if} has related {@code #elseif}-s or {@code #else}, an * {@link ASTDirIfElseIfElseContainer} parent must be used. For a lonely {@code #if}, no such parent is needed. */ -final class ASTDirIfOrElseOrElseIf extends _ASTElement { +final class ASTDirIfOrElseOrElseIf extends ASTDirective { static final int TYPE_IF = 0; static final int TYPE_ELSE = 1; @@ -63,7 +63,7 @@ final class ASTDirIfOrElseOrElseIf extends _ASTElement { if (canonical) { buf.append(">"); buf.append(getChildrenCanonicalForm()); - if (!(getParentElement() instanceof ASTDirIfElseIfElseContainer)) { + if (!(getParent() instanceof ASTDirIfElseIfElseContainer)) { buf.append("</#if>"); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirImport.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirImport.java b/src/main/java/org/apache/freemarker/core/ASTDirImport.java index fb5b3c9..c7fb94c 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirImport.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirImport.java @@ -27,7 +27,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST directive node: {@code #import} */ -final class ASTDirImport extends _ASTElement { +final class ASTDirImport extends ASTDirective { private ASTExpression importedTemplateNameExp; private String targetNsVarName; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirInclude.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirInclude.java b/src/main/java/org/apache/freemarker/core/ASTDirInclude.java index 4f6053d..33f0c32 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirInclude.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirInclude.java @@ -31,7 +31,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST directive node: {@code #include} */ -final class ASTDirInclude extends _ASTElement { +final class ASTDirInclude extends ASTDirective { private final ASTExpression includedTemplateNameExp, encodingExp, parseExp, ignoreMissingExp; private final String encoding; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirItems.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirItems.java b/src/main/java/org/apache/freemarker/core/ASTDirItems.java index a716c6d..d517c79 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirItems.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirItems.java @@ -26,7 +26,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST directive node: {@code #items} */ -class ASTDirItems extends _ASTElement { +class ASTDirItems extends ASTDirective { private final String loopVarName; private final String loopVar2Name; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirList.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirList.java b/src/main/java/org/apache/freemarker/core/ASTDirList.java index df4bbd8..34a4d74 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirList.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirList.java @@ -41,7 +41,7 @@ import org.apache.freemarker.core.util._StringUtil; * AST directive node: {@code #list} (or {@code #foreach}) element, or pre-{@code #else} section of it inside a * {@link ASTDirListElseContainer}. */ -final class ASTDirList extends _ASTElement { +final class ASTDirList extends ASTDirective { private final ASTExpression listedExp; private final String loopVarName; @@ -150,7 +150,7 @@ final class ASTDirList extends _ASTElement { if (canonical) { buf.append(">"); buf.append(getChildrenCanonicalForm()); - if (!(getParentElement() instanceof ASTDirListElseContainer)) { + if (!(getParent() instanceof ASTDirListElseContainer)) { buf.append("</"); buf.append(getNodeTypeSymbol()); buf.append('>'); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java b/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java index dd3985a..2a0b4fb 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java @@ -23,7 +23,7 @@ import java.io.IOException; /** * AST directive node: When a {@code #list} has an {@code #else}, this is the parent of the two nodes. */ -class ASTDirListElseContainer extends _ASTElement { +class ASTDirListElseContainer extends ASTDirective { private final ASTDirList listPart; private final ASTDirElseOfList elsePart; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirMacro.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirMacro.java b/src/main/java/org/apache/freemarker/core/ASTDirMacro.java index 4b22428..c2e5b37 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirMacro.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirMacro.java @@ -33,7 +33,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST directive node: {@code #macro} */ -final class ASTDirMacro extends _ASTElement implements TemplateModel { +final class ASTDirMacro extends ASTDirective implements TemplateModel { static final ASTDirMacro DO_NOTHING_MACRO = new ASTDirMacro(".pass", Collections.EMPTY_LIST, http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirNested.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirNested.java b/src/main/java/org/apache/freemarker/core/ASTDirNested.java index c9270b8..8f7a619 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirNested.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirNested.java @@ -30,7 +30,7 @@ import org.apache.freemarker.core.model.TemplateModelException; /** * AST directive node: {@code #nested}. */ -final class ASTDirNested extends _ASTElement { +final class ASTDirNested extends ASTDirective { private List bodyParameters; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java b/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java index 72f6928..7da9d2b 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #noautoesc}. */ -final class ASTDirNoAutoEsc extends _ASTElement { +final class ASTDirNoAutoEsc extends ASTDirective { ASTDirNoAutoEsc(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java b/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java index c914280..65da614 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #noescape}. */ -class ASTDirNoEscape extends _ASTElement { +class ASTDirNoEscape extends ASTDirective { ASTDirNoEscape(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java b/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java index 162ec1e..a7ed89f 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #outputformat}. */ -final class ASTDirOutputFormat extends _ASTElement { +final class ASTDirOutputFormat extends ASTDirective { private final ASTExpression paramExp; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirRecover.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirRecover.java b/src/main/java/org/apache/freemarker/core/ASTDirRecover.java index 33ef932..d94b871 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirRecover.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirRecover.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #recover}. */ -final class ASTDirRecover extends _ASTElement { +final class ASTDirRecover extends ASTDirective { ASTDirRecover(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java b/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java index 8597e92..f134214 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java @@ -32,7 +32,7 @@ import org.apache.freemarker.core.model.impl.SimpleSequence; /** * AST directive node: {@code #recurse}. */ -final class ASTDirRecurse extends _ASTElement { +final class ASTDirRecurse extends ASTDirective { ASTExpression targetNode, namespaces; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirReturn.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirReturn.java b/src/main/java/org/apache/freemarker/core/ASTDirReturn.java index 86aa91e..6f41805 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirReturn.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirReturn.java @@ -22,7 +22,7 @@ package org.apache.freemarker.core; /** * AST directive node: {@code #return}. */ -final class ASTDirReturn extends _ASTElement { +final class ASTDirReturn extends ASTDirective { private ASTExpression exp; @@ -35,7 +35,7 @@ final class ASTDirReturn extends _ASTElement { if (exp != null) { env.setLastReturnValue(exp.eval(env)); } - if (nextSibling() == null && getParentElement() instanceof ASTDirMacro) { + if (nextSibling() == null && getParent() instanceof ASTDirMacro) { // Avoid unnecessary exception throwing return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirSep.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirSep.java b/src/main/java/org/apache/freemarker/core/ASTDirSep.java index fe181ab..1ef8b2c 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirSep.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirSep.java @@ -25,7 +25,7 @@ import org.apache.freemarker.core.ASTDirList.IterationContext; /** * AST directive node: {@code #sep}. */ -class ASTDirSep extends _ASTElement { +class ASTDirSep extends ASTDirective { public ASTDirSep(TemplateElements children) { setChildren(children); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirSetting.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirSetting.java b/src/main/java/org/apache/freemarker/core/ASTDirSetting.java index 5554599..74ea78b 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirSetting.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirSetting.java @@ -30,7 +30,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST directive node: {@code #setting}. */ -final class ASTDirSetting extends _ASTElement { +final class ASTDirSetting extends ASTDirective { private final String key; private final ASTExpression value; @@ -63,8 +63,8 @@ final class ASTDirSetting extends _ASTElement { String key = keyTk.image; if (Arrays.binarySearch(SETTING_NAMES, key) < 0) { StringBuilder sb = new StringBuilder(); - if (_TemplateAPI.getConfigurationSettingNames(cfg, true).contains(key) - || _TemplateAPI.getConfigurationSettingNames(cfg, false).contains(key)) { + if (cfg.getSettingNames(true).contains(key) + || cfg.getSettingNames(false).contains(key)) { sb.append("The setting name is recognized, but changing this setting from inside a template isn't " + "supported."); } else { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirStop.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirStop.java b/src/main/java/org/apache/freemarker/core/ASTDirStop.java index 54397b4..4520665 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirStop.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirStop.java @@ -22,7 +22,7 @@ package org.apache.freemarker.core; /** * AST directive node: {@code #stop}. */ -final class ASTDirStop extends _ASTElement { +final class ASTDirStop extends ASTDirective { private ASTExpression exp; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java b/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java index 4fe32c2..1090b43 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java @@ -24,7 +24,7 @@ import java.io.IOException; /** * AST directive node: {@code #switch}. */ -final class ASTDirSwitch extends _ASTElement { +final class ASTDirSwitch extends ASTDirective { private ASTDirCase defaultCase; private final ASTExpression searched; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java b/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java index 7efccf4..b666f06 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java @@ -22,7 +22,7 @@ package org.apache.freemarker.core; /** * AST directive node: {@code #t}, {@code #tr}, {@code #tl}. */ -final class ASTDirTOrTrOrTl extends _ASTElement { +final class ASTDirTOrTrOrTl extends ASTDirective { private static final int TYPE_T = 0; private static final int TYPE_LT = 1; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirTransform.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirTransform.java b/src/main/java/org/apache/freemarker/core/ASTDirTransform.java index cd22b97..bf793d3 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirTransform.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirTransform.java @@ -34,7 +34,7 @@ import org.apache.freemarker.core.model.TemplateTransformModel; /** * AST directive node: {@code #transform}. */ -final class ASTDirTransform extends _ASTElement { +final class ASTDirTransform extends ASTDirective { private ASTExpression transformExpression; Map namedArgs; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java b/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java index 3eaa6bb..28d29a2 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java @@ -40,7 +40,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; * AST directive node: {@code <@exp .../>} or {@code <@exp ...>...</@...>}. Calls an user-defined directive (like a * macro). */ -final class ASTDirUserDefined extends _ASTElement implements DirectiveCallPlace { +final class ASTDirUserDefined extends ASTDirective implements DirectiveCallPlace { private ASTExpression nameExp; private Map namedArgs; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirVisit.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirVisit.java b/src/main/java/org/apache/freemarker/core/ASTDirVisit.java index e68cf72..61d58a6 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirVisit.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirVisit.java @@ -31,7 +31,7 @@ import org.apache.freemarker.core.model.impl.SimpleSequence; /** * AST directive node: {@code #visit}. */ -final class ASTDirVisit extends _ASTElement { +final class ASTDirVisit extends ASTDirective { ASTExpression targetNode, namespaces; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTDirective.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDirective.java b/src/main/java/org/apache/freemarker/core/ASTDirective.java new file mode 100644 index 0000000..f0e06ab --- /dev/null +++ b/src/main/java/org/apache/freemarker/core/ASTDirective.java @@ -0,0 +1,84 @@ +package org.apache.freemarker.core; + +import java.util.Collections; +import java.util.Set; +import java.util.TreeSet; + +/** + * AST directive node superclass. + */ +abstract class ASTDirective extends _ASTElement { + + private static void addName(Set<String> allNames, Set<String> lcNames, Set<String> ccNames, + String commonName) { + allNames.add(commonName); + lcNames.add(commonName); + ccNames.add(commonName); + } + + private static void addName(Set<String> allNames, Set<String> lcNames, Set<String> ccNames, + String lcName, String ccName) { + allNames.add(lcName); + allNames.add(ccName); + lcNames.add(lcName); + ccNames.add(ccName); + } + + static final Set<String> ALL_BUILT_IN_DIRECTIVE_NAMES; + static final Set<String> LEGACY_BUILT_IN_DIRECTIVE_NAMES; + static final Set<String> CAMEL_CASE_BUILT_IN_DIRECTIVE_NAMES; + static { + Set<String> allNames = new TreeSet(); + Set<String> lcNames = new TreeSet(); + Set<String> ccNames = new TreeSet(); + + addName(allNames, lcNames, ccNames, "assign"); + addName(allNames, lcNames, ccNames, "attempt"); + addName(allNames, lcNames, ccNames, "autoesc", "autoEsc"); + addName(allNames, lcNames, ccNames, "break"); + addName(allNames, lcNames, ccNames, "call"); + addName(allNames, lcNames, ccNames, "case"); + addName(allNames, lcNames, ccNames, "comment"); + addName(allNames, lcNames, ccNames, "compress"); + addName(allNames, lcNames, ccNames, "default"); + addName(allNames, lcNames, ccNames, "else"); + addName(allNames, lcNames, ccNames, "elseif", "elseIf"); + addName(allNames, lcNames, ccNames, "escape"); + addName(allNames, lcNames, ccNames, "fallback"); + addName(allNames, lcNames, ccNames, "flush"); + addName(allNames, lcNames, ccNames, "foreach", "forEach"); + addName(allNames, lcNames, ccNames, "ftl"); + addName(allNames, lcNames, ccNames, "function"); + addName(allNames, lcNames, ccNames, "global"); + addName(allNames, lcNames, ccNames, "if"); + addName(allNames, lcNames, ccNames, "import"); + addName(allNames, lcNames, ccNames, "include"); + addName(allNames, lcNames, ccNames, "items"); + addName(allNames, lcNames, ccNames, "list"); + addName(allNames, lcNames, ccNames, "local"); + addName(allNames, lcNames, ccNames, "lt"); + addName(allNames, lcNames, ccNames, "macro"); + addName(allNames, lcNames, ccNames, "nested"); + addName(allNames, lcNames, ccNames, "noautoesc", "noAutoEsc"); + addName(allNames, lcNames, ccNames, "noescape", "noEscape"); + addName(allNames, lcNames, ccNames, "noparse", "noParse"); + addName(allNames, lcNames, ccNames, "nt"); + addName(allNames, lcNames, ccNames, "outputformat", "outputFormat"); + addName(allNames, lcNames, ccNames, "recover"); + addName(allNames, lcNames, ccNames, "recurse"); + addName(allNames, lcNames, ccNames, "return"); + addName(allNames, lcNames, ccNames, "rt"); + addName(allNames, lcNames, ccNames, "sep"); + addName(allNames, lcNames, ccNames, "setting"); + addName(allNames, lcNames, ccNames, "stop"); + addName(allNames, lcNames, ccNames, "switch"); + addName(allNames, lcNames, ccNames, "t"); + addName(allNames, lcNames, ccNames, "transform"); + addName(allNames, lcNames, ccNames, "visit"); + + ALL_BUILT_IN_DIRECTIVE_NAMES = Collections.unmodifiableSet(allNames); + LEGACY_BUILT_IN_DIRECTIVE_NAMES = Collections.unmodifiableSet(lcNames); + CAMEL_CASE_BUILT_IN_DIRECTIVE_NAMES = Collections.unmodifiableSet(ccNames); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java b/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java index c42a7b6..ed39aa7 100644 --- a/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java +++ b/src/main/java/org/apache/freemarker/core/ASTExpBuiltIn.java @@ -481,5 +481,5 @@ abstract class ASTExpBuiltIn extends ASTExpression implements Cloneable { default: throw new IndexOutOfBoundsException(); } } - + } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java b/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java index 63b0f77..c370ff5 100644 --- a/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java +++ b/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java @@ -51,7 +51,7 @@ final class ASTImplicitParent extends _ASTElement { if (canonical) { return getChildrenCanonicalForm(); } else { - if (getParentElement() == null) { + if (getParent() == null) { return "root"; } return getNodeTypeSymbol(); // ASTImplicitParent is uninteresting in a stack trace. http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/ASTStaticText.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTStaticText.java b/src/main/java/org/apache/freemarker/core/ASTStaticText.java index 2d68e30..8e8c8a3 100644 --- a/src/main/java/org/apache/freemarker/core/ASTStaticText.java +++ b/src/main/java/org/apache/freemarker/core/ASTStaticText.java @@ -111,7 +111,7 @@ final class ASTStaticText extends _ASTElement { if (!stripWhitespace || text.length == 0 ) { return this; } - _ASTElement parentElement = getParentElement(); + _ASTElement parentElement = getParent(); if (isTopLevelTextIfParentIs(parentElement) && previousSibling() == null) { return this; } @@ -352,7 +352,7 @@ final class ASTStaticText extends _ASTElement { if (!_StringUtil.isTrimmableToEmpty(text)) { return false; } - _ASTElement parentElement = getParentElement(); + _ASTElement parentElement = getParent(); boolean atTopLevel = isTopLevelTextIfParentIs(parentElement); _ASTElement prevSibling = previousSibling(); _ASTElement nextSibling = nextSibling(); @@ -365,7 +365,7 @@ final class ASTStaticText extends _ASTElement { private boolean isTopLevelTextIfParentIs(_ASTElement parentElement) { return parentElement == null - || parentElement.getParentElement() == null && parentElement instanceof ASTImplicitParent; + || parentElement.getParent() == null && parentElement instanceof ASTImplicitParent; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/Configurable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/Configurable.java b/src/main/java/org/apache/freemarker/core/Configurable.java index 000f4bb..6f3ec00 100644 --- a/src/main/java/org/apache/freemarker/core/Configurable.java +++ b/src/main/java/org/apache/freemarker/core/Configurable.java @@ -355,7 +355,7 @@ public class Configurable { * Called by the {@link Configuration} constructor. */ protected Configurable(Version incompatibleImprovements) { - _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); + _CoreAPI.checkVersionNotNullAndSupported(incompatibleImprovements); parent = null; locale = Locale.getDefault(); timeZone = TimeZone.getDefault(); @@ -364,8 +364,7 @@ public class Configurable { timeFormat = ""; dateFormat = ""; dateTimeFormat = ""; - templateExceptionHandler = _TemplateAPI.getDefaultTemplateExceptionHandler( - incompatibleImprovements); + templateExceptionHandler = Configuration.getDefaultTemplateExceptionHandler(); arithmeticEngine = BigDecimalArithmeticEngine.INSTANCE; objectWrapper = Configuration.getDefaultObjectWrapper(incompatibleImprovements); autoFlush = Boolean.TRUE; @@ -2144,8 +2143,8 @@ public class Configurable { || CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE.equals(name)) { Map map = (Map) _ObjectBuilderSettingEvaluator.eval( value, Map.class, false, _SettingEvaluationEnvironment.getCurrent()); - _CoreAPI.checkSettingValueItemsType("Map keys", String.class, map.keySet()); - _CoreAPI.checkSettingValueItemsType("Map values", TemplateNumberFormatFactory.class, map.values()); + checkSettingValueItemsType("Map keys", String.class, map.keySet()); + checkSettingValueItemsType("Map values", TemplateNumberFormatFactory.class, map.values()); setCustomNumberFormats(map); } else if (TIME_FORMAT_KEY_SNAKE_CASE.equals(name) || TIME_FORMAT_KEY_CAMEL_CASE.equals(name)) { setTimeFormat(value); @@ -2157,8 +2156,8 @@ public class Configurable { || CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE.equals(name)) { Map map = (Map) _ObjectBuilderSettingEvaluator.eval( value, Map.class, false, _SettingEvaluationEnvironment.getCurrent()); - _CoreAPI.checkSettingValueItemsType("Map keys", String.class, map.keySet()); - _CoreAPI.checkSettingValueItemsType("Map values", TemplateDateFormatFactory.class, map.values()); + checkSettingValueItemsType("Map keys", String.class, map.keySet()); + checkSettingValueItemsType("Map values", TemplateDateFormatFactory.class, map.values()); setCustomDateFormats(map); } else if (TIME_ZONE_KEY_SNAKE_CASE.equals(name) || TIME_ZONE_KEY_CAMEL_CASE.equals(name)) { setTimeZone(parseTimeZoneSettingValue(value)); @@ -2286,7 +2285,23 @@ public class Configurable { throw unknownSettingException(name); } } - + + /** + * @throws IllegalArgumentException + * if the type of the some of the values isn't as expected + */ + private void checkSettingValueItemsType(String somethingsSentenceStart, Class<?> expectedClass, + Collection<?> values) { + if (values == null) return; + for (Object value : values) { + if (!expectedClass.isInstance(value)) { + throw new IllegalArgumentException(somethingsSentenceStart + " must be instances of " + + _ClassUtil.getShortClassName(expectedClass) + ", but one of them was a(n) " + + _ClassUtil.getShortClassNameOfObject(value) + "."); + } + } + } + /** * Returns the valid setting names that aren't {@link Configuration}-only. * http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/Configuration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/Configuration.java b/src/main/java/org/apache/freemarker/core/Configuration.java index 4ddc98a..3fd6a23 100644 --- a/src/main/java/org/apache/freemarker/core/Configuration.java +++ b/src/main/java/org/apache/freemarker/core/Configuration.java @@ -554,19 +554,14 @@ public class Configuration extends Configurable implements Cloneable, ParserConf // Nothing to override } - private TemplateExceptionHandler getDefaultTemplateExceptionHandler() { - return getDefaultTemplateExceptionHandler(getIncompatibleImprovements()); + static TemplateExceptionHandler getDefaultTemplateExceptionHandler() { + return TemplateExceptionHandler.DEBUG_HANDLER; // [FM3] RETHROW } - + private ObjectWrapper getDefaultObjectWrapper() { return getDefaultObjectWrapper(getIncompatibleImprovements()); } - // Package visible as Configurable needs this to initialize the field defaults. - static TemplateExceptionHandler getDefaultTemplateExceptionHandler(Version incompatibleImprovements) { - return TemplateExceptionHandler.DEBUG_HANDLER; - } - @Override public Object clone() { try { @@ -1199,7 +1194,7 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * @since 2.3.20 */ public void setIncompatibleImprovements(Version incompatibleImprovements) { - _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); + _CoreAPI.checkVersionNotNullAndSupported(incompatibleImprovements); if (!this.incompatibleImprovements.equals(incompatibleImprovements)) { this.incompatibleImprovements = incompatibleImprovements; @@ -1318,7 +1313,7 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * @since 2.3.24 */ public void setAutoEscapingPolicy(int autoEscapingPolicy) { - _TemplateAPI.validateAutoEscapingPolicyValue(autoEscapingPolicy); + validateAutoEscapingPolicyValue(autoEscapingPolicy); int prevAutoEscaping = getAutoEscapingPolicy(); this.autoEscapingPolicy = autoEscapingPolicy; @@ -1327,6 +1322,18 @@ public class Configuration extends Configurable implements Cloneable, ParserConf } } + // [FM3] Use enum; won't be needed + static void validateAutoEscapingPolicyValue(int autoEscaping) { + if (autoEscaping != Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY + && autoEscaping != Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY + && autoEscaping != Configuration.DISABLE_AUTO_ESCAPING_POLICY) { + throw new IllegalArgumentException("\"auto_escaping\" can only be set to one of these: " + + "Configuration.ENABLE_AUTO_ESCAPING_IF_DEFAULT, " + + "or Configuration.ENABLE_AUTO_ESCAPING_IF_SUPPORTED" + + "or Configuration.DISABLE_AUTO_ESCAPING"); + } + } + /** * Getter pair of {@link #setAutoEscapingPolicy(int)} * @@ -1661,10 +1668,21 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * the syntax. */ public void setTagSyntax(int tagSyntax) { - _TemplateAPI.valideTagSyntaxValue(tagSyntax); + valideTagSyntaxValue(tagSyntax); this.tagSyntax = tagSyntax; } + // [FM3] Use enum; won't be needed + static void valideTagSyntaxValue(int tagSyntax) { + if (tagSyntax != Configuration.AUTO_DETECT_TAG_SYNTAX + && tagSyntax != Configuration.SQUARE_BRACKET_TAG_SYNTAX + && tagSyntax != Configuration.ANGLE_BRACKET_TAG_SYNTAX) { + throw new IllegalArgumentException("\"tag_syntax\" can only be set to one of these: " + + "Configuration.AUTO_DETECT_TAG_SYNTAX, Configuration.ANGLE_BRACKET_SYNTAX, " + + "or Configuration.SQUARE_BRACKET_SYNTAX"); + } + } + /** * The getter pair of {@link #setTagSyntax(int)}. */ @@ -1719,10 +1737,21 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * @since 2.3.23 */ public void setNamingConvention(int namingConvention) { - _TemplateAPI.validateNamingConventionValue(namingConvention); + validateNamingConventionValue(namingConvention); this.namingConvention = namingConvention; } + // [FM3] Use enum; won't be needed + static void validateNamingConventionValue(int namingConvention) { + if (namingConvention != Configuration.AUTO_DETECT_NAMING_CONVENTION + && namingConvention != Configuration.LEGACY_NAMING_CONVENTION + && namingConvention != Configuration.CAMEL_CASE_NAMING_CONVENTION) { + throw new IllegalArgumentException("\"naming_convention\" can only be set to one of these: " + + "Configuration.AUTO_DETECT_NAMING_CONVENTION, " + + "or Configuration.LEGACY_NAMING_CONVENTION" + + "or Configuration.CAMEL_CASE_NAMING_CONVENTION"); + } + } /** * The getter pair of {@link #setNamingConvention(int)}. * @@ -2695,7 +2724,17 @@ public class Configuration extends Configurable implements Cloneable, ParserConf * @since 2.3.24 */ public Set<String> getSupportedBuiltInNames(int namingConvention) { - return _CoreAPI.getSupportedBuiltInNames(namingConvention); + Set<String> names; + if (namingConvention == Configuration.AUTO_DETECT_NAMING_CONVENTION) { + names = ASTExpBuiltIn.BUILT_INS_BY_NAME.keySet(); + } else if (namingConvention == Configuration.LEGACY_NAMING_CONVENTION) { + names = ASTExpBuiltIn.SNAKE_CASE_NAMES; + } else if (namingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION) { + names = ASTExpBuiltIn.CAMEL_CASE_NAMES; + } else { + throw new IllegalArgumentException("Unsupported naming convention constant: " + namingConvention); + } + return Collections.unmodifiableSet(names); } /** @@ -2720,11 +2759,11 @@ public class Configuration extends Configurable implements Cloneable, ParserConf */ public Set<String> getSupportedBuiltInDirectiveNames(int namingConvention) { if (namingConvention == AUTO_DETECT_NAMING_CONVENTION) { - return _CoreAPI.ALL_BUILT_IN_DIRECTIVE_NAMES; + return ASTDirective.ALL_BUILT_IN_DIRECTIVE_NAMES; } else if (namingConvention == LEGACY_NAMING_CONVENTION) { - return _CoreAPI.LEGACY_BUILT_IN_DIRECTIVE_NAMES; + return ASTDirective.LEGACY_BUILT_IN_DIRECTIVE_NAMES; } else if (namingConvention == CAMEL_CASE_NAMING_CONVENTION) { - return _CoreAPI.CAMEL_CASE_BUILT_IN_DIRECTIVE_NAMES; + return ASTDirective.CAMEL_CASE_BUILT_IN_DIRECTIVE_NAMES; } else { throw new IllegalArgumentException("Unsupported naming convention constant: " + namingConvention); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/Environment.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/Environment.java b/src/main/java/org/apache/freemarker/core/Environment.java index 300b765..895a2b6 100644 --- a/src/main/java/org/apache/freemarker/core/Environment.java +++ b/src/main/java/org/apache/freemarker/core/Environment.java @@ -2086,7 +2086,7 @@ public final class Environment extends Configurable { static private ASTDirMacro getEnclosingMacro(_ASTElement stackEl) { while (stackEl != null) { if (stackEl instanceof ASTDirMacro) return (ASTDirMacro) stackEl; - stackEl = stackEl.getParentElement(); + stackEl = stackEl.getParent(); } return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/MessageUtil.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/MessageUtil.java b/src/main/java/org/apache/freemarker/core/MessageUtil.java index 4e658db..0a2f350 100644 --- a/src/main/java/org/apache/freemarker/core/MessageUtil.java +++ b/src/main/java/org/apache/freemarker/core/MessageUtil.java @@ -51,6 +51,8 @@ class MessageUtil { static final String EMBEDDED_MESSAGE_END = "\n---end-message---"; + static final String ERROR_MESSAGE_HR = "----"; + // Can't be instantiated private MessageUtil() { } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java b/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java index 26504bd..3ae7db8 100644 --- a/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java +++ b/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java @@ -25,11 +25,11 @@ import org.apache.freemarker.core.model.TemplateDirectiveBody; import org.apache.freemarker.core.util._StringUtil; /** - * [2.4] Should become public somehow; this is more intelligent than a {@code null} check, for example, when the body - * only contains a thread interruption check, it treats it as valid. Indicates that the directive shouldn't have - * nested content, but it had. This will probably become public when the directive/method stuff was reworked. + * Used in custom {@link org.apache.freemarker.core.model.TemplateDirectiveModel}-s to check if the directive invocation + * has no body. This is more intelligent than a {@code null} check; for example, when the body + * only contains a thread interruption check node, it treats it as valid. */ -class NestedContentNotSupportedException extends TemplateException { +public class NestedContentNotSupportedException extends TemplateException { public static void check(TemplateDirectiveBody body) throws NestedContentNotSupportedException { if (body == null) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/Template.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/Template.java b/src/main/java/org/apache/freemarker/core/Template.java index 7fb0483..76053ee 100644 --- a/src/main/java/org/apache/freemarker/core/Template.java +++ b/src/main/java/org/apache/freemarker/core/Template.java @@ -252,7 +252,7 @@ public class Template extends Configurable { reader = ltbReader; try { - FMParser parser = _CoreAPI.newFMParser( + FMParser parser = new FMParser( this, reader, actualParserConfiguration, streamToUnmarkWhenEncEstabd); try { rootElement = parser.Root(); @@ -314,13 +314,13 @@ public class Template extends Configurable { } catch (IOException e) { throw new BugException("Plain text template creation failed", e); } - _CoreAPI.replaceText((ASTStaticText) template.rootElement, content); + ((ASTStaticText) template.rootElement).replaceText(content); DebuggerService.registerTemplate(template); return template; } private static Version normalizeTemplateLanguageVersion(Version incompatibleImprovements) { - _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); + _CoreAPI.checkVersionNotNullAndSupported(incompatibleImprovements); return Configuration.VERSION_3_0_0; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java b/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java index 7b34a70..ed8f514 100644 --- a/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java +++ b/src/main/java/org/apache/freemarker/core/TemplateConfiguration.java @@ -372,7 +372,7 @@ public final class TemplateConfiguration extends Configurable implements ParserC * See {@link Configuration#setTagSyntax(int)}. */ public void setTagSyntax(int tagSyntax) { - _TemplateAPI.valideTagSyntaxValue(tagSyntax); + Configuration.valideTagSyntaxValue(tagSyntax); this.tagSyntax = Integer.valueOf(tagSyntax); } @@ -395,7 +395,7 @@ public final class TemplateConfiguration extends Configurable implements ParserC * See {@link Configuration#setNamingConvention(int)}. */ public void setNamingConvention(int namingConvention) { - _TemplateAPI.validateNamingConventionValue(namingConvention); + Configuration.validateNamingConventionValue(namingConvention); this.namingConvention = Integer.valueOf(namingConvention); } @@ -442,7 +442,8 @@ public final class TemplateConfiguration extends Configurable implements ParserC * Sets the output format of the template; see {@link Configuration#setAutoEscapingPolicy(int)} for more. */ public void setAutoEscapingPolicy(int autoEscapingPolicy) { - _TemplateAPI.validateAutoEscapingPolicyValue(autoEscapingPolicy); + Configuration.validateAutoEscapingPolicyValue(autoEscapingPolicy); + this.autoEscapingPolicy = Integer.valueOf(autoEscapingPolicy); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/TemplateException.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/TemplateException.java b/src/main/java/org/apache/freemarker/core/TemplateException.java index d40d828..9721447 100644 --- a/src/main/java/org/apache/freemarker/core/TemplateException.java +++ b/src/main/java/org/apache/freemarker/core/TemplateException.java @@ -153,7 +153,9 @@ public class TemplateException extends Exception { this.descriptionBuilder = descriptionBuilder; description = renderedDescription; - if (env != null) ftlInstructionStackSnapshot = _CoreAPI.getInstructionStackSnapshot(env); + if (env != null) { + ftlInstructionStackSnapshot = env.getInstructionStackSnapshot(); + } } private void renderMessages() { @@ -171,10 +173,10 @@ public class TemplateException extends Exception { String stackTopFew = getFTLInstructionStackTopFew(); if (stackTopFew != null) { message = messageWithoutStackTop + "\n\n" - + _CoreAPI.ERROR_MESSAGE_HR + "\n" + + MessageUtil.ERROR_MESSAGE_HR + "\n" + FTL_INSTRUCTION_STACK_TRACE_TITLE + "\n" + stackTopFew - + _CoreAPI.ERROR_MESSAGE_HR; + + MessageUtil.ERROR_MESSAGE_HR; messageWithoutStackTop = message.substring(0, messageWithoutStackTop.length()); // to reuse backing char[] } else { message = messageWithoutStackTop; @@ -214,7 +216,7 @@ public class TemplateException extends Exception { if (renderedFtlInstructionStackSnapshot == null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - _CoreAPI.outputInstructionStack(ftlInstructionStackSnapshot, false, pw); + Environment.outputInstructionStack(ftlInstructionStackSnapshot, false, pw); pw.close(); if (renderedFtlInstructionStackSnapshot == null) { renderedFtlInstructionStackSnapshot = sw.toString(); @@ -238,7 +240,7 @@ public class TemplateException extends Exception { s = ""; } else { StringWriter sw = new StringWriter(); - _CoreAPI.outputInstructionStack(ftlInstructionStackSnapshot, true, sw); + Environment.outputInstructionStack(ftlInstructionStackSnapshot, true, sw); s = sw.toString(); } if (renderedFtlInstructionStackSnapshotTop == null) { @@ -343,10 +345,10 @@ public class TemplateException extends Exception { if (stackTrace != null) { out.println(getMessageWithoutStackTop()); // Not getMessage()! out.println(); - out.println(_CoreAPI.ERROR_MESSAGE_HR); + out.println(MessageUtil.ERROR_MESSAGE_HR); out.println(FTL_INSTRUCTION_STACK_TRACE_TITLE); out.print(stackTrace); - out.println(_CoreAPI.ERROR_MESSAGE_HR); + out.println(MessageUtil.ERROR_MESSAGE_HR); } else { ftlStackTrace = false; javaStackTrace = true; @@ -357,7 +359,7 @@ public class TemplateException extends Exception { if (ftlStackTrace) { // We are after an FTL stack trace out.println(); out.println("Java stack trace (for programmers):"); - out.println(_CoreAPI.ERROR_MESSAGE_HR); + out.println(MessageUtil.ERROR_MESSAGE_HR); synchronized (lock) { if (messageWasAlreadyPrintedForThisTrace == null) { messageWasAlreadyPrintedForThisTrace = new ThreadLocal(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/_ASTElement.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/_ASTElement.java b/src/main/java/org/apache/freemarker/core/_ASTElement.java index af7e9c1..1c9ca58 100644 --- a/src/main/java/org/apache/freemarker/core/_ASTElement.java +++ b/src/main/java/org/apache/freemarker/core/_ASTElement.java @@ -217,7 +217,7 @@ abstract public class _ASTElement extends ASTNode { /** * The element whose child this element is, or {@code null} if this is the root node. */ - final _ASTElement getParentElement() { + final _ASTElement getParent() { return parent; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/_CoreAPI.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/_CoreAPI.java b/src/main/java/org/apache/freemarker/core/_CoreAPI.java index 5fb8de2..3c40a79 100644 --- a/src/main/java/org/apache/freemarker/core/_CoreAPI.java +++ b/src/main/java/org/apache/freemarker/core/_CoreAPI.java @@ -19,141 +19,25 @@ package org.apache.freemarker.core; -import java.io.InputStream; -import java.io.Reader; -import java.io.Writer; import java.util.Collection; -import java.util.Collections; -import java.util.Set; -import java.util.TreeSet; -import org.apache.freemarker.core.model.TemplateDirectiveBody; import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.util._ClassUtil; - +import org.apache.freemarker.core.util._NullArgumentException; /** * 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. */ -public class _CoreAPI { - - public static final String ERROR_MESSAGE_HR = "----"; +public final class _CoreAPI { + + public static final int VERSION_INT_3_0_0 = Configuration.VERSION_3_0_0.intValue(); // Can't be instantiated private _CoreAPI() { } - private static void addName(Set<String> allNames, Set<String> lcNames, Set<String> ccNames, - String commonName) { - allNames.add(commonName); - lcNames.add(commonName); - ccNames.add(commonName); - } - - private static void addName(Set<String> allNames, Set<String> lcNames, Set<String> ccNames, - String lcName, String ccName) { - allNames.add(lcName); - allNames.add(ccName); - lcNames.add(lcName); - ccNames.add(ccName); - } - - public static final Set<String> ALL_BUILT_IN_DIRECTIVE_NAMES; - public static final Set<String> LEGACY_BUILT_IN_DIRECTIVE_NAMES; - public static final Set<String> CAMEL_CASE_BUILT_IN_DIRECTIVE_NAMES; - static { - Set<String> allNames = new TreeSet(); - Set<String> lcNames = new TreeSet(); - Set<String> ccNames = new TreeSet(); - - addName(allNames, lcNames, ccNames, "assign"); - addName(allNames, lcNames, ccNames, "attempt"); - addName(allNames, lcNames, ccNames, "autoesc", "autoEsc"); - addName(allNames, lcNames, ccNames, "break"); - addName(allNames, lcNames, ccNames, "call"); - addName(allNames, lcNames, ccNames, "case"); - addName(allNames, lcNames, ccNames, "comment"); - addName(allNames, lcNames, ccNames, "compress"); - addName(allNames, lcNames, ccNames, "default"); - addName(allNames, lcNames, ccNames, "else"); - addName(allNames, lcNames, ccNames, "elseif", "elseIf"); - addName(allNames, lcNames, ccNames, "escape"); - addName(allNames, lcNames, ccNames, "fallback"); - addName(allNames, lcNames, ccNames, "flush"); - addName(allNames, lcNames, ccNames, "foreach", "forEach"); - addName(allNames, lcNames, ccNames, "ftl"); - addName(allNames, lcNames, ccNames, "function"); - addName(allNames, lcNames, ccNames, "global"); - addName(allNames, lcNames, ccNames, "if"); - addName(allNames, lcNames, ccNames, "import"); - addName(allNames, lcNames, ccNames, "include"); - addName(allNames, lcNames, ccNames, "items"); - addName(allNames, lcNames, ccNames, "list"); - addName(allNames, lcNames, ccNames, "local"); - addName(allNames, lcNames, ccNames, "lt"); - addName(allNames, lcNames, ccNames, "macro"); - addName(allNames, lcNames, ccNames, "nested"); - addName(allNames, lcNames, ccNames, "noautoesc", "noAutoEsc"); - addName(allNames, lcNames, ccNames, "noescape", "noEscape"); - addName(allNames, lcNames, ccNames, "noparse", "noParse"); - addName(allNames, lcNames, ccNames, "nt"); - addName(allNames, lcNames, ccNames, "outputformat", "outputFormat"); - addName(allNames, lcNames, ccNames, "recover"); - addName(allNames, lcNames, ccNames, "recurse"); - addName(allNames, lcNames, ccNames, "return"); - addName(allNames, lcNames, ccNames, "rt"); - addName(allNames, lcNames, ccNames, "sep"); - addName(allNames, lcNames, ccNames, "setting"); - addName(allNames, lcNames, ccNames, "stop"); - addName(allNames, lcNames, ccNames, "switch"); - addName(allNames, lcNames, ccNames, "t"); - addName(allNames, lcNames, ccNames, "transform"); - addName(allNames, lcNames, ccNames, "visit"); - - ALL_BUILT_IN_DIRECTIVE_NAMES = Collections.unmodifiableSet(allNames); - LEGACY_BUILT_IN_DIRECTIVE_NAMES = Collections.unmodifiableSet(lcNames); - CAMEL_CASE_BUILT_IN_DIRECTIVE_NAMES = Collections.unmodifiableSet(ccNames); - } - - /** - * Returns the names of the currently supported "built-ins" ({@code expr?builtin_name}-like things). - * - * @param namingConvention - * One of {@link Configuration#AUTO_DETECT_NAMING_CONVENTION}, - * {@link Configuration#LEGACY_NAMING_CONVENTION}, and - * {@link Configuration#CAMEL_CASE_NAMING_CONVENTION}. If it's - * {@link Configuration#AUTO_DETECT_NAMING_CONVENTION} then the union of the names in all the naming - * conventions is returned. - */ - public static Set<String> getSupportedBuiltInNames(int namingConvention) { - Set<String> names; - if (namingConvention == Configuration.AUTO_DETECT_NAMING_CONVENTION) { - names = ASTExpBuiltIn.BUILT_INS_BY_NAME.keySet(); - } else if (namingConvention == Configuration.LEGACY_NAMING_CONVENTION) { - names = ASTExpBuiltIn.SNAKE_CASE_NAMES; - } else if (namingConvention == Configuration.CAMEL_CASE_NAMING_CONVENTION) { - names = ASTExpBuiltIn.CAMEL_CASE_NAMES; - } else { - throw new IllegalArgumentException("Unsupported naming convention constant: " + namingConvention); - } - return Collections.unmodifiableSet(names); - } - - public static void appendInstructionStackItem(_ASTElement stackEl, StringBuilder sb) { - Environment.appendInstructionStackItem(stackEl, sb); - } - - public static _ASTElement[] getInstructionStackSnapshot(Environment env) { - return env.getInstructionStackSnapshot(); - } - - public static void outputInstructionStack( - _ASTElement[] instructionStackSnapshot, boolean terseMode, Writer pw) { - Environment.outputInstructionStack(instructionStackSnapshot, terseMode, pw); - } - /** * ATTENTION: This is used by https://github.com/kenshoo/freemarker-online. Don't break backward * compatibility without updating that project too! @@ -165,64 +49,52 @@ public class _CoreAPI { throw new RuntimeException("Template post-processing failed", e); } } - - static public void checkHasNoNestedContent(TemplateDirectiveBody body) - throws NestedContentNotSupportedException { - NestedContentNotSupportedException.check(body); - } - - static public void replaceText(ASTStaticText textBlock, String text) { - textBlock.replaceText(text); - } /** - * @throws IllegalArgumentException - * if the type of the some of the values isn't as expected - */ - public static void checkSettingValueItemsType(String somethingsSentenceStart, Class<?> expectedClass, - Collection<?> values) { - if (values == null) return; - for (Object value : values) { - if (!expectedClass.isInstance(value)) { - throw new IllegalArgumentException(somethingsSentenceStart + " must be instances of " - + _ClassUtil.getShortClassName(expectedClass) + ", but one of them was a(n) " - + _ClassUtil.getShortClassNameOfObject(value) + "."); - } - } - } - - /** * The work around the problematic cases where we should throw a {@link TemplateException}, but we are inside * a {@link TemplateModel} method and so we can only throw {@link TemplateModelException}-s. */ + // [FM3] Get rid of this problem, then delete this method public static TemplateModelException ensureIsTemplateModelException(String modelOpMsg, TemplateException e) { if (e instanceof TemplateModelException) { return (TemplateModelException) e; } else { return new _TemplateModelException( - _TemplateAPI.getBlamedExpression(e), e.getCause(), e.getEnvironment(), modelOpMsg); + e.getBlamedExpression(), e.getCause(), e.getEnvironment(), modelOpMsg); } } - + + // Because of debug... public static _ASTElement getParentElement(_ASTElement te) { - return te.getParentElement(); + return te.getParent(); } + // Because of debug... public static _ASTElement getChildElement(_ASTElement te, int index) { return te.getChild(index); } - - public static FMParser newFMParser(Template template, Reader reader, ParserConfiguration pCfg, - InputStream streamToUnmarkWhenEncEstabd) { - return new FMParser(template, reader, pCfg, streamToUnmarkWhenEncEstabd); - } - + + // [FM3] Should become unnecessary as custom directive classes are reworked public static boolean isMacroOrFunction(TemplateModel m) { return m instanceof ASTDirMacro; } - + + // [FM3] Should become unnecessary as custom directive classes are reworked public static boolean isFunction(TemplateModel m) { return m instanceof ASTDirMacro && ((ASTDirMacro) m).isFunction(); } - + + public static void checkVersionNotNullAndSupported(Version incompatibleImprovements) { + _NullArgumentException.check("incompatibleImprovements", incompatibleImprovements); + int iciV = incompatibleImprovements.intValue(); + if (iciV > Configuration.getVersion().intValue()) { + throw new IllegalArgumentException("The FreeMarker version requested by \"incompatibleImprovements\" was " + + incompatibleImprovements + ", but the installed FreeMarker version is only " + + Configuration.getVersion() + ". You may need to upgrade FreeMarker in your project."); + } + if (iciV < VERSION_INT_3_0_0) { + throw new IllegalArgumentException("\"incompatibleImprovements\" must be at least 3.0.0, but was " + + incompatibleImprovements); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java b/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java index d9fd3a0..afefcd5 100644 --- a/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java +++ b/src/main/java/org/apache/freemarker/core/_ErrorDescriptionBuilder.java @@ -149,7 +149,7 @@ public class _ErrorDescriptionBuilder { sb.append("\n\n"); for (int i = 0; i < allTips.length; i++) { if (i != 0) sb.append('\n'); - sb.append(_CoreAPI.ERROR_MESSAGE_HR).append('\n'); + sb.append(MessageUtil.ERROR_MESSAGE_HR).append('\n'); sb.append("Tip: "); Object tip = allTips[i]; if (!(tip instanceof Object[])) { @@ -158,7 +158,7 @@ public class _ErrorDescriptionBuilder { appendParts(sb, (Object[]) tip); } } - sb.append('\n').append(_CoreAPI.ERROR_MESSAGE_HR); + sb.append('\n').append(MessageUtil.ERROR_MESSAGE_HR); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/_TemplateAPI.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/_TemplateAPI.java b/src/main/java/org/apache/freemarker/core/_TemplateAPI.java deleted file mode 100644 index c8b712c..0000000 --- a/src/main/java/org/apache/freemarker/core/_TemplateAPI.java +++ /dev/null @@ -1,119 +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.Set; - -import org.apache.freemarker.core.outputformat.OutputFormat; -import org.apache.freemarker.core.templateresolver.CacheStorage; -import org.apache.freemarker.core.util._NullArgumentException; - -/** - * 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. - */ -public class _TemplateAPI { - - public static final int VERSION_INT_3_0_0 = Configuration.VERSION_3_0_0.intValue(); - - public static void checkVersionNotNullAndSupported(Version incompatibleImprovements) { - _NullArgumentException.check("incompatibleImprovements", incompatibleImprovements); - int iciV = incompatibleImprovements.intValue(); - if (iciV > Configuration.getVersion().intValue()) { - throw new IllegalArgumentException("The FreeMarker version requested by \"incompatibleImprovements\" was " - + incompatibleImprovements + ", but the installed FreeMarker version is only " - + Configuration.getVersion() + ". You may need to upgrade FreeMarker in your project."); - } - if (iciV < VERSION_INT_3_0_0) { - throw new IllegalArgumentException("\"incompatibleImprovements\" must be at least 3.0.0, but was " - + incompatibleImprovements); - } - } - - public static int getTemplateLanguageVersionAsInt(ASTNode to) { - return getTemplateLanguageVersionAsInt(to.getTemplate()); - } - - public static int getTemplateLanguageVersionAsInt(Template t) { - return t.getTemplateLanguageVersion().intValue(); - } - - public static TemplateExceptionHandler getDefaultTemplateExceptionHandler( - Version incompatibleImprovements) { - return Configuration.getDefaultTemplateExceptionHandler(incompatibleImprovements); - } - - public static CacheStorage createDefaultCacheStorage(Version incompatibleImprovements) { - return Configuration.createDefaultCacheStorage(incompatibleImprovements); - } - - /** - * [2.4] getSettingNames() becomes to public; remove this. - */ - public static Set/*<String>*/ getConfigurationSettingNames(Configuration cfg, boolean camelCase) { - return cfg.getSettingNames(camelCase); - } - - public static void setAutoEscaping(Template t, boolean autoEscaping) { - t.setAutoEscaping(autoEscaping); - } - - public static void setOutputFormat(Template t, OutputFormat outputFormat) { - t.setOutputFormat(outputFormat); - } - - public static void validateAutoEscapingPolicyValue(int autoEscaping) { - if (autoEscaping != Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY - && autoEscaping != Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY - && autoEscaping != Configuration.DISABLE_AUTO_ESCAPING_POLICY) { - throw new IllegalArgumentException("\"auto_escaping\" can only be set to one of these: " - + "Configuration.ENABLE_AUTO_ESCAPING_IF_DEFAULT, " - + "or Configuration.ENABLE_AUTO_ESCAPING_IF_SUPPORTED" - + "or Configuration.DISABLE_AUTO_ESCAPING"); - } - } - - public static void validateNamingConventionValue(int namingConvention) { - if (namingConvention != Configuration.AUTO_DETECT_NAMING_CONVENTION - && namingConvention != Configuration.LEGACY_NAMING_CONVENTION - && namingConvention != Configuration.CAMEL_CASE_NAMING_CONVENTION) { - throw new IllegalArgumentException("\"naming_convention\" can only be set to one of these: " - + "Configuration.AUTO_DETECT_NAMING_CONVENTION, " - + "or Configuration.LEGACY_NAMING_CONVENTION" - + "or Configuration.CAMEL_CASE_NAMING_CONVENTION"); - } - } - - public static void valideTagSyntaxValue(int tagSyntax) { - if (tagSyntax != Configuration.AUTO_DETECT_TAG_SYNTAX - && tagSyntax != Configuration.SQUARE_BRACKET_TAG_SYNTAX - && tagSyntax != Configuration.ANGLE_BRACKET_TAG_SYNTAX) { - throw new IllegalArgumentException("\"tag_syntax\" can only be set to one of these: " - + "Configuration.AUTO_DETECT_TAG_SYNTAX, Configuration.ANGLE_BRACKET_SYNTAX, " - + "or Configuration.SQAUARE_BRACKET_SYNTAX"); - } - } - - public static ASTExpression getBlamedExpression(TemplateException e) { - return e.getBlamedExpression(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperConfiguration.java b/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperConfiguration.java index a32f7c8..df97ce6 100644 --- a/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperConfiguration.java +++ b/src/main/java/org/apache/freemarker/core/model/impl/DefaultObjectWrapperConfiguration.java @@ -35,7 +35,7 @@ import org.apache.freemarker.core.model.impl.beans.BeansWrapperConfiguration; public abstract class DefaultObjectWrapperConfiguration extends BeansWrapperConfiguration { private boolean useAdaptersForContainers = true; - private boolean forceLegacyNonListCollections = true; // [FM3] [2.4]: = IcI < _TemplateAPI.VERSION_INT_2_4_0; + private boolean forceLegacyNonListCollections = true; // [FM3] [2.4]: = IcI < _CoreAPI.VERSION_INT_2_4_0; private boolean iterableSupport; protected DefaultObjectWrapperConfiguration(Version incompatibleImprovements) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/946a4237/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java b/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java index 47c7f38..b9b9a7a 100644 --- a/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java +++ b/src/main/java/org/apache/freemarker/core/model/impl/beans/BeansWrapper.java @@ -38,13 +38,7 @@ import java.util.Map; import java.util.ResourceBundle; import java.util.Set; -import org.apache.freemarker.core.Configuration; -import org.apache.freemarker.core.Version; -import org.apache.freemarker.core._CoreLogs; -import org.apache.freemarker.core._DelayedFTLTypeDescription; -import org.apache.freemarker.core._DelayedShortClassName; -import org.apache.freemarker.core._TemplateAPI; -import org.apache.freemarker.core._TemplateModelException; +import org.apache.freemarker.core.*; import org.apache.freemarker.core.model.AdapterTemplateModel; import org.apache.freemarker.core.model.ObjectWrapper; import org.apache.freemarker.core.model.ObjectWrapperAndUnwrapper; @@ -707,7 +701,7 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable { * @since 2.3.21 */ protected static Version normalizeIncompatibleImprovementsVersion(Version incompatibleImprovements) { - _TemplateAPI.checkVersionNotNullAndSupported(incompatibleImprovements); + _CoreAPI.checkVersionNotNullAndSupported(incompatibleImprovements); return Configuration.VERSION_3_0_0; }