(Could make some more classes and members package private now.)
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/d74ccf3c Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/d74ccf3c Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/d74ccf3c Branch: refs/heads/3 Commit: d74ccf3ccc73b5db29356f4a18481dcb1a6f962e Parents: 8346c1f Author: ddekany <ddek...@apache.org> Authored: Sun Feb 26 02:30:49 2017 +0100 Committer: ddekany <ddek...@apache.org> Committed: Sun Feb 26 02:30:49 2017 +0100 ---------------------------------------------------------------------- .../org/apache/freemarker/core/ASTComment.java | 4 +- .../apache/freemarker/core/ASTDebugBreak.java | 89 ++++ .../freemarker/core/ASTDirAssignment.java | 2 +- .../core/ASTDirAssignmentsContainer.java | 2 +- .../core/ASTDirAttemptRecoverContainer.java | 6 +- .../apache/freemarker/core/ASTDirAutoEsc.java | 2 +- .../org/apache/freemarker/core/ASTDirBreak.java | 2 +- .../core/ASTDirCapturingAssignment.java | 4 +- .../org/apache/freemarker/core/ASTDirCase.java | 2 +- .../apache/freemarker/core/ASTDirCompress.java | 4 +- .../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 | 4 +- .../freemarker/core/ASTDirIfOrElseOrElseIf.java | 2 +- .../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 | 10 +- .../core/ASTDirListElseContainer.java | 4 +- .../org/apache/freemarker/core/ASTDirMacro.java | 6 +- .../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 | 2 +- .../org/apache/freemarker/core/ASTDirSep.java | 2 +- .../apache/freemarker/core/ASTDirSetting.java | 2 +- .../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 | 2 +- .../freemarker/core/ASTDollarInterpolation.java | 2 +- .../org/apache/freemarker/core/ASTElement.java | 473 +++++++++++++++++++ .../freemarker/core/ASTHashInterpolation.java | 2 +- .../freemarker/core/ASTImplicitParent.java | 10 +- .../freemarker/core/ASTInterpolation.java | 2 +- .../org/apache/freemarker/core/ASTNode.java | 8 +- .../apache/freemarker/core/ASTStaticText.java | 28 +- .../org/apache/freemarker/core/Environment.java | 80 ++-- .../NestedContentNotSupportedException.java | 2 +- .../org/apache/freemarker/core/Template.java | 95 +--- .../core/TemplateElementArrayBuilder.java | 18 +- .../core/TemplateElementsToVisit.java | 14 +- .../freemarker/core/TemplateException.java | 4 +- ...nterruptionSupportTemplatePostProcessor.java | 10 +- .../apache/freemarker/core/_ASTDebugBreak.java | 90 ---- .../org/apache/freemarker/core/_ASTElement.java | 473 ------------------- .../java/org/apache/freemarker/core/_Debug.java | 36 +- .../core/_ErrorDescriptionBuilder.java | 2 +- .../impl/DefaultTemplateResolver.java | 4 +- src/main/javacc/FTL.jj | 46 +- .../org/apache/freemarker/core/ASTPrinter.java | 16 +- .../core/OptInTemplateClassResolverTest.java | 46 +- .../freemarker/core/OutputFormatTest.java | 4 +- .../freemarker/core/TemplatGetEncodingTest.java | 2 +- .../core/TemplateConstructorsTest.java | 2 +- 63 files changed, 803 insertions(+), 855 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/src/main/java/org/apache/freemarker/core/ASTComment.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTComment.java b/src/main/java/org/apache/freemarker/core/ASTComment.java index 439bc81..d1a4a1f 100644 --- a/src/main/java/org/apache/freemarker/core/ASTComment.java +++ b/src/main/java/org/apache/freemarker/core/ASTComment.java @@ -24,7 +24,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST comment node */ -final class ASTComment extends _ASTElement { +final class ASTComment extends ASTElement { private final String text; @@ -33,7 +33,7 @@ final class ASTComment extends _ASTElement { } @Override - _ASTElement[] accept(Environment env) { + ASTElement[] accept(Environment env) { // do nothing, skip the body return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/src/main/java/org/apache/freemarker/core/ASTDebugBreak.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDebugBreak.java b/src/main/java/org/apache/freemarker/core/ASTDebugBreak.java new file mode 100644 index 0000000..ae2711b --- /dev/null +++ b/src/main/java/org/apache/freemarker/core/ASTDebugBreak.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.freemarker.core; + +import java.io.IOException; + +import org.apache.freemarker.core.debug.impl.DebuggerService; + +/** + * AST node: A debug breakpoint + */ +class ASTDebugBreak extends ASTElement { + public ASTDebugBreak(ASTElement nestedBlock) { + addChild(nestedBlock); + copyLocationFrom(nestedBlock); + } + + @Override + protected ASTElement[] accept(Environment env) throws TemplateException, IOException { + if (!DebuggerService.suspendEnvironment( + env, getTemplate().getSourceName(), getChild(0).getBeginLine())) { + return getChild(0).accept(env); + } else { + throw new StopException(env, "Stopped by debugger"); + } + } + + @Override + protected String dump(boolean canonical) { + if (canonical) { + StringBuilder sb = new StringBuilder(); + sb.append("<#-- "); + sb.append("debug break"); + if (getChildCount() == 0) { + sb.append(" /-->"); + } else { + sb.append(" -->"); + sb.append(getChild(0).getCanonicalForm()); + sb.append("<#--/ debug break -->"); + } + return sb.toString(); + } else { + return "debug break"; + } + } + + @Override + String getNodeTypeSymbol() { + return "#debug_break"; + } + + @Override + int getParameterCount() { + return 0; + } + + @Override + Object getParameterValue(int idx) { + throw new IndexOutOfBoundsException(); + } + + @Override + ParameterRole getParameterRole(int idx) { + throw new IndexOutOfBoundsException(); + } + + @Override + boolean isNestedBlockRepeater() { + return false; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 16f7a37..d95ee62 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAssignment.java @@ -102,7 +102,7 @@ final class ASTDirAssignment extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException { + ASTElement[] accept(Environment env) throws TemplateException { final Environment.Namespace namespace; if (namespaceExp == null) { switch (scope) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 6f426cd..b2b67ea 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAssignmentsContainer.java @@ -49,7 +49,7 @@ final class ASTDirAssignmentsContainer extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 8c41cb9..d2c7835 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAttemptRecoverContainer.java @@ -27,11 +27,11 @@ import java.io.IOException; */ final class ASTDirAttemptRecoverContainer extends ASTDirective { - private _ASTElement attemptedSection; + private ASTElement attemptedSection; private ASTDirRecover recoverySection; ASTDirAttemptRecoverContainer(TemplateElements attemptedSectionChildren, ASTDirRecover recoverySection) { - _ASTElement attemptedSection = attemptedSectionChildren.asSingleElement(); + ASTElement attemptedSection = attemptedSectionChildren.asSingleElement(); this.attemptedSection = attemptedSection; this.recoverySection = recoverySection; setChildBufferCapacity(2); @@ -40,7 +40,7 @@ final class ASTDirAttemptRecoverContainer extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { env.visitAttemptRecover(this, attemptedSection, recoverySection); return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 d5fb6cb..ec4e11b 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirAutoEsc.java @@ -31,7 +31,7 @@ final class ASTDirAutoEsc extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 522009c..58c7a06 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirBreak.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirBreak.java @@ -25,7 +25,7 @@ package org.apache.freemarker.core; final class ASTDirBreak extends ASTDirective { @Override - _ASTElement[] accept(Environment env) { + ASTElement[] accept(Environment env) { throw Break.INSTANCE; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 f61df3b..82c2e4c 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirCapturingAssignment.java @@ -49,8 +49,8 @@ final class ASTDirCapturingAssignment extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { - _ASTElement[] children = getChildBuffer(); + ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] children = getChildBuffer(); if (children != null) { env.visitAndTransform(children, new CaptureOutput(env), null); } else { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 c3ff6b3..88f4419 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirCase.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirCase.java @@ -35,7 +35,7 @@ final class ASTDirCase extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) { + ASTElement[] accept(Environment env) { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 cd5f291..7d5e3ac 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirCompress.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirCompress.java @@ -37,8 +37,8 @@ final class ASTDirCompress extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { - _ASTElement[] childBuffer = getChildBuffer(); + ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] childBuffer = getChildBuffer(); if (childBuffer != null) { env.visitAndTransform(childBuffer, StandardCompress.INSTANCE, null); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 7a45c6b..612efa8 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirElseOfList.java @@ -31,7 +31,7 @@ final class ASTDirElseOfList extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 f4fd208..eff29e0 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirEscape.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirEscape.java @@ -47,7 +47,7 @@ class ASTDirEscape extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 ceb20c5..655ac08 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirFallback.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirFallback.java @@ -27,7 +27,7 @@ import java.io.IOException; final class ASTDirFallback extends ASTDirective { @Override - _ASTElement[] accept(Environment env) throws IOException, TemplateException { + ASTElement[] accept(Environment env) throws IOException, TemplateException { env.fallback(); return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 7a6a492..9fb5d9d 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirFlush.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirFlush.java @@ -27,7 +27,7 @@ import java.io.IOException; final class ASTDirFlush extends ASTDirective { @Override - _ASTElement[] accept(Environment env) throws IOException { + ASTElement[] accept(Environment env) throws IOException { env.getOut().flush(); return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 09593ff..71146e2 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirIfElseIfElseContainer.java @@ -38,7 +38,7 @@ final class ASTDirIfElseIfElseContainer extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { int ln = getChildCount(); for (int i = 0; i < ln; i++) { ASTDirIfOrElseOrElseIf cblock = (ASTDirIfOrElseOrElseIf) getChild(i); @@ -52,7 +52,7 @@ final class ASTDirIfElseIfElseContainer extends ASTDirective { } @Override - _ASTElement postParseCleanup(boolean stripWhitespace) + ASTElement postParseCleanup(boolean stripWhitespace) throws ParseException { if (getChildCount() == 1) { ASTDirIfOrElseOrElseIf cblock = (ASTDirIfOrElseOrElseIf) getChild(0); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 3b85038..2398219 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirIfOrElseOrElseIf.java @@ -44,7 +44,7 @@ final class ASTDirIfOrElseOrElseIf extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { if (condition == null || condition.evalToBoolean(env)) { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 c7fb94c..e883f3b 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirImport.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirImport.java @@ -45,7 +45,7 @@ final class ASTDirImport extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { final String importedTemplateName = importedTemplateNameExp.evalAndCoerceToPlainText(env); final String fullImportedTemplateName; try { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 33f0c32..9796cb6 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirInclude.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirInclude.java @@ -116,7 +116,7 @@ final class ASTDirInclude extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { final String includedTemplateName = includedTemplateNameExp.evalAndCoerceToPlainText(env); final String fullIncludedTemplateName; try { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 d517c79..f7b4ae0 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirItems.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirItems.java @@ -43,7 +43,7 @@ class ASTDirItems extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { final IterationContext iterCtx = ASTDirList.findEnclosingIterationContext(env, null); if (iterCtx == null) { // The parser should prevent this situation http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 34a4d74..9f05ca7 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirList.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirList.java @@ -88,7 +88,7 @@ final class ASTDirList extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { acceptWithResult(env); return null; } @@ -237,7 +237,7 @@ final class ASTDirList extends ASTDirective { return executeNestedContent(env, getChildBuffer()); } - void loopForItemsElement(Environment env, _ASTElement[] childBuffer, String loopVarName, String loopVar2Name) + void loopForItemsElement(Environment env, ASTElement[] childBuffer, String loopVarName, String loopVar2Name) throws TemplateException, IOException { try { @@ -259,14 +259,14 @@ final class ASTDirList extends ASTDirective { * Executes the given block for the {@link #listedValue}: if {@link #loopVarName} is non-{@code null}, then for * each list item once, otherwise once if {@link #listedValue} isn't empty. */ - private boolean executeNestedContent(Environment env, _ASTElement[] childBuffer) + private boolean executeNestedContent(Environment env, ASTElement[] childBuffer) throws TemplateException, IOException { return !hashListing ? executedNestedContentForCollOrSeqListing(env, childBuffer) : executedNestedContentForHashListing(env, childBuffer); } - private boolean executedNestedContentForCollOrSeqListing(Environment env, _ASTElement[] childBuffer) + private boolean executedNestedContentForCollOrSeqListing(Environment env, ASTElement[] childBuffer) throws IOException, TemplateException { final boolean listNotEmpty; if (listedValue instanceof TemplateCollectionModel) { @@ -329,7 +329,7 @@ final class ASTDirList extends ASTDirective { return listNotEmpty; } - private boolean executedNestedContentForHashListing(Environment env, _ASTElement[] childBuffer) + private boolean executedNestedContentForHashListing(Environment env, ASTElement[] childBuffer) throws IOException, TemplateException { final boolean hashNotEmpty; if (listedValue instanceof TemplateHashModelEx) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 2a0b4fb..52ba9f5 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirListElseContainer.java @@ -37,7 +37,7 @@ class ASTDirListElseContainer extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { if (!listPart.acceptWithResult(env)) { return elsePart.accept(env); } @@ -55,7 +55,7 @@ class ASTDirListElseContainer extends ASTDirective { StringBuilder buf = new StringBuilder(); int ln = getChildCount(); for (int i = 0; i < ln; i++) { - _ASTElement element = getChild(i); + ASTElement element = getChild(i); buf.append(element.dump(canonical)); } buf.append("</#list>"); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 c2e5b37..d5a8f15 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirMacro.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirMacro.java @@ -84,7 +84,7 @@ final class ASTDirMacro extends ASTDirective implements TemplateModel { } @Override - _ASTElement[] accept(Environment env) { + ASTElement[] accept(Environment env) { env.visitMacroDef(this); return null; } @@ -149,14 +149,14 @@ final class ASTDirMacro extends ASTDirective implements TemplateModel { class Context implements LocalContext { final Environment.Namespace localVars; - final _ASTElement[] nestedContentBuffer; + final ASTElement[] nestedContentBuffer; final Environment.Namespace nestedContentNamespace; final List nestedContentParameterNames; final LocalContextStack prevLocalContextStack; final Context prevMacroContext; Context(Environment env, - _ASTElement[] nestedContentBuffer, + ASTElement[] nestedContentBuffer, List nestedContentParameterNames) { localVars = env.new Namespace(); this.nestedContentBuffer = nestedContentBuffer; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 8f7a619..ec4eeb7 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirNested.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirNested.java @@ -54,7 +54,7 @@ final class ASTDirNested extends ASTDirective { * I (JR) realized this thanks to some incisive comments from Daniel Dekany. */ @Override - _ASTElement[] accept(Environment env) throws IOException, TemplateException { + ASTElement[] accept(Environment env) throws IOException, TemplateException { Context bodyContext = new Context(env); env.invokeNestedContent(bodyContext); return null; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 7da9d2b..93750fc 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirNoAutoEsc.java @@ -31,7 +31,7 @@ final class ASTDirNoAutoEsc extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 65da614..4973fdb 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirNoEscape.java @@ -31,7 +31,7 @@ class ASTDirNoEscape extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 a7ed89f..b418371 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirOutputFormat.java @@ -34,7 +34,7 @@ final class ASTDirOutputFormat extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 d94b871..1ee7cd9 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirRecover.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirRecover.java @@ -31,7 +31,7 @@ final class ASTDirRecover extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 f134214..17f7230 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirRecurse.java @@ -42,7 +42,7 @@ final class ASTDirRecurse extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws IOException, TemplateException { + ASTElement[] accept(Environment env) throws IOException, TemplateException { TemplateModel node = targetNode == null ? null : targetNode.eval(env); if (node != null && !(node instanceof TemplateNodeModel)) { throw new NonNodeException(targetNode, node, "node", env); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 6f41805..04023a4 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirReturn.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirReturn.java @@ -31,7 +31,7 @@ final class ASTDirReturn extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException { + ASTElement[] accept(Environment env) throws TemplateException { if (exp != null) { env.setLastReturnValue(exp.eval(env)); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 1ef8b2c..c1f4bb5 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirSep.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirSep.java @@ -32,7 +32,7 @@ class ASTDirSep extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { final IterationContext iterCtx = ASTDirList.findEnclosingIterationContext(env, null); if (iterCtx == null) { // The parser should prevent this situation http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 74ea78b..0fd9e7a 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirSetting.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirSetting.java @@ -103,7 +103,7 @@ final class ASTDirSetting extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException { + ASTElement[] accept(Environment env) throws TemplateException { TemplateModel mval = value.eval(env); String strval; if (mval instanceof TemplateScalarModel) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 4520665..c2d1eb0 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirStop.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirStop.java @@ -31,7 +31,7 @@ final class ASTDirStop extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws TemplateException { + ASTElement[] accept(Environment env) throws TemplateException { if (exp == null) { throw new StopException(env); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 1090b43..5c56edc 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirSwitch.java @@ -45,7 +45,7 @@ final class ASTDirSwitch extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) + ASTElement[] accept(Environment env) throws TemplateException, IOException { boolean processedCase = false; int ln = getChildCount(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 b666f06..b589ce7 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirTOrTrOrTl.java @@ -37,7 +37,7 @@ final class ASTDirTOrTrOrTl extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) { + ASTElement[] accept(Environment env) { // This instruction does nothing at render-time, only parse-time. return null; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 bf793d3..be46876 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirTransform.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirTransform.java @@ -49,7 +49,7 @@ final class ASTDirTransform extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) + ASTElement[] accept(Environment env) throws TemplateException, IOException { TemplateTransformModel ttm = env.getTransform(transformExpression); if (ttm != null) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 28d29a2..f526ba6 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirUserDefined.java @@ -70,7 +70,7 @@ final class ASTDirUserDefined extends ASTDirective implements DirectiveCallPlace } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { TemplateModel tm = nameExp.eval(env); if (tm == ASTDirMacro.DO_NOTHING_MACRO) return null; // shortcut here. if (tm instanceof ASTDirMacro) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 61d58a6..8732db1 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirVisit.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirVisit.java @@ -41,7 +41,7 @@ final class ASTDirVisit extends ASTDirective { } @Override - _ASTElement[] accept(Environment env) throws IOException, TemplateException { + ASTElement[] accept(Environment env) throws IOException, TemplateException { TemplateModel node = targetNode.eval(env); if (!(node instanceof TemplateNodeModel)) { throw new NonNodeException(targetNode, node, env); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 index f0e06ab..b622dd2 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDirective.java +++ b/src/main/java/org/apache/freemarker/core/ASTDirective.java @@ -7,7 +7,7 @@ import java.util.TreeSet; /** * AST directive node superclass. */ -abstract class ASTDirective extends _ASTElement { +abstract class ASTDirective extends ASTElement { private static void addName(Set<String> allNames, Set<String> lcNames, Set<String> ccNames, String commonName) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/src/main/java/org/apache/freemarker/core/ASTDollarInterpolation.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTDollarInterpolation.java b/src/main/java/org/apache/freemarker/core/ASTDollarInterpolation.java index 882b680..141fa8d 100644 --- a/src/main/java/org/apache/freemarker/core/ASTDollarInterpolation.java +++ b/src/main/java/org/apache/freemarker/core/ASTDollarInterpolation.java @@ -57,7 +57,7 @@ final class ASTDollarInterpolation extends ASTInterpolation { * Outputs the string value of the enclosed expression. */ @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { final Object moOrStr = calculateInterpolatedStringOrMarkup(env); final Writer out = env.getOut(); if (moOrStr instanceof String) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 new file mode 100644 index 0000000..40788aa --- /dev/null +++ b/src/main/java/org/apache/freemarker/core/ASTElement.java @@ -0,0 +1,473 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.freemarker.core; + +import java.io.IOException; +import java.util.Collections; +import java.util.Enumeration; + +import org.apache.freemarker.core.model.TemplateNodeModel; +import org.apache.freemarker.core.model.TemplateSequenceModel; +import org.apache.freemarker.core.model.impl.SimpleSequence; +import org.apache.freemarker.core.util._ArrayEnumeration; + +/** + * AST non-expression node superclass: Superclass of directive calls, interpolations, static text, top-level comments, + * or other such non-expression node in the parsed template. Some information that can be found here can be accessed + * through the {@link Environment#getCurrentDirectiveCallPlace()}, which is a published API, and thus promises backward + * compatibility. + */ +// TODO [FM3] Get rid of "public" and thus the "_" prefix +abstract class ASTElement extends ASTNode { + + private static final int INITIAL_CHILD_BUFFER_CAPACITY = 6; + + private ASTElement parent; + + /** + * Contains 1 or more nested elements with optional trailing {@code null}-s, or is {@code null} exactly if there are + * no nested elements. + */ + private ASTElement[] childBuffer; + + /** + * Contains the number of elements in the {@link #childBuffer}, not counting the trailing {@code null}-s. If this is + * 0, then and only then {@link #childBuffer} must be {@code null}. + */ + private int childCount; + + /** + * The index of the element in the parent's {@link #childBuffer} array. + * + * @since 2.3.23 + */ + private int index; + + /** + * Executes this {@link ASTElement}. Usually should not be called directly, but through + * {@link Environment#visit(ASTElement)} or a similar {@link Environment} method. + * + * @param env + * The runtime environment + * + * @return The template elements to execute (meant to be used for nested elements), or {@code null}. Can have + * <em>trailing</em> {@code null}-s (unused buffer capacity). Returning the nested elements instead of + * executing them inside this method is a trick used for decreasing stack usage when there's nothing to do + * after the children was processed anyway. + */ + abstract ASTElement[] accept(Environment env) throws TemplateException, IOException; + + /** + * One-line description of the element, that contain all the information that is used in {@link #getCanonicalForm()} + * , except the nested content (elements) of the element. The expressions inside the element (the parameters) has to + * be shown. Meant to be used for stack traces, also for tree views that don't go down to the expression-level. + * There are no backward-compatibility guarantees regarding the format used ATM, but it must be regular enough to be + * machine-parseable, and it must contain all information necessary for restoring an AST equivalent to the original. + * + * This final implementation calls {@link #dump(boolean) dump(false)}. + * + * @see #getCanonicalForm() + * @see #getNodeTypeSymbol() + */ + public final String getDescription() { + return dump(false); + } + + /** + * This final implementation calls {@link #dump(boolean) dump(false)}. + */ + @Override + public final String getCanonicalForm() { + return dump(true); + } + + final String getChildrenCanonicalForm() { + return getChildrenCanonicalForm(childBuffer); + } + + static String getChildrenCanonicalForm(ASTElement[] children) { + if (children == null) { + return ""; + } + StringBuilder sb = new StringBuilder(); + for (ASTElement child : children) { + if (child == null) { + break; + } + sb.append(child.getCanonicalForm()); + } + return sb.toString(); + } + + /** + * Tells if the element should show up in error stack traces. Note that this will be ignored for the top (current) + * element of a stack trace, as that's always shown. + */ + boolean isShownInStackTrace() { + return false; + } + + /** + * Tells if this element possibly executes its nested content for many times. This flag is useful when a template + * AST is modified for running time limiting (see {@link ThreadInterruptionSupportTemplatePostProcessor}). Elements + * that use {@link #childBuffer} should not need this, as the insertion of the timeout checks is impossible there, + * given their rigid nested element schema. + */ + abstract boolean isNestedBlockRepeater(); + + /** + * Brings the implementation of {@link #getCanonicalForm()} and {@link #getDescription()} to a single place. Don't + * call those methods in method on {@code this}, because that will result in infinite recursion! + * + * @param canonical + * if {@code true}, it calculates the return value of {@link #getCanonicalForm()}, otherwise of + * {@link #getDescription()}. + */ + abstract protected String dump(boolean canonical); + + // Methods to implement TemplateNodeModel + + public TemplateNodeModel getParentNode() { + // return parent; + return null; + } + + public String getNodeNamespace() { + return null; + } + + public String getNodeType() { + return "element"; + } + + public TemplateSequenceModel getChildNodes() { + if (childBuffer != null) { + final SimpleSequence seq = new SimpleSequence(childCount); + for (int i = 0; i < childCount; i++) { + seq.add(childBuffer[i]); + } + return seq; + } else { + return new SimpleSequence(0); + } + } + + public String getNodeName() { + String className = getClass().getName(); + int shortNameOffset = className.lastIndexOf('.') + 1; + return className.substring(shortNameOffset); + } + + // Methods so that we can implement the Swing TreeNode API. + + public boolean isLeaf() { + return childCount == 0; + } + + public int getIndex(ASTElement node) { + for (int i = 0; i < childCount; i++) { + if (childBuffer[i].equals(node)) { + return i; + } + } + return -1; + } + + public int getChildCount() { + return childCount; + } + + /** + * Note: For element with {@code #nestedBlock}, this will hide the {@code #nestedBlock} when that's a + * {@link ASTImplicitParent}. + */ + public Enumeration children() { + return childBuffer != null + ? new _ArrayEnumeration(childBuffer, childCount) + : Collections.enumeration(Collections.EMPTY_LIST); + } + + public void setChildAt(int index, ASTElement element) { + if (index < childCount && index >= 0) { + childBuffer[index] = element; + element.index = index; + element.parent = this; + } else { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + childCount); + } + } + + /** + * The element whose child this element is, or {@code null} if this is the root node. + */ + final ASTElement getParent() { + return parent; + } + + final void setChildBufferCapacity(int capacity) { + int ln = childCount; + ASTElement[] newChildBuffer = new ASTElement[capacity]; + for (int i = 0; i < ln; i++) { + newChildBuffer[i] = childBuffer[i]; + } + childBuffer = newChildBuffer; + } + + /** + * Inserts a new nested element after the last nested element. + */ + final void addChild(ASTElement nestedElement) { + addChild(childCount, nestedElement); + } + + /** + * Inserts a new nested element at the given index, which can also be one higher than the current highest index. + */ + final void addChild(int index, ASTElement nestedElement) { + final int lChildCount = childCount; + + ASTElement[] lChildBuffer = childBuffer; + if (lChildBuffer == null) { + lChildBuffer = new ASTElement[INITIAL_CHILD_BUFFER_CAPACITY]; + childBuffer = lChildBuffer; + } else if (lChildCount == lChildBuffer.length) { + setChildBufferCapacity(lChildCount != 0 ? lChildCount * 2 : 1); + lChildBuffer = childBuffer; + } + // At this point: nestedElements == this.nestedElements, and has sufficient capacity. + + for (int i = lChildCount; i > index; i--) { + ASTElement movedElement = lChildBuffer[i - 1]; + movedElement.index = i; + lChildBuffer[i] = movedElement; + } + nestedElement.index = index; + nestedElement.parent = this; + lChildBuffer[index] = nestedElement; + childCount = lChildCount + 1; + } + + final ASTElement getChild(int index) { + return childBuffer[index]; + } + + /** + * @return Array containing 1 or more nested elements with optional trailing {@code null}-s, or is {@code null} + * exactly if there are no nested elements. + */ + final ASTElement[] getChildBuffer() { + return childBuffer; + } + + /** + * @param buffWithCnt Maybe {@code null} + * + * @since 2.3.24 + */ + final void setChildren(TemplateElements buffWithCnt) { + ASTElement[] childBuffer = buffWithCnt.getBuffer(); + int childCount = buffWithCnt.getCount(); + for (int i = 0; i < childCount; i++) { + ASTElement child = childBuffer[i]; + child.index = i; + child.parent = this; + } + this.childBuffer = childBuffer; + this.childCount = childCount; + } + + final int getIndex() { + return index; + } + + /** + * This is a special case, because a root element is not contained in another element, so we couldn't set the + * private fields. + */ + final void setFieldsForRootElement() { + index = 0; + parent = null; + } + + /** + * Walk the AST subtree rooted by this element, and do simplifications where possible, also removes superfluous + * whitespace. + * + * @param stripWhitespace + * whether to remove superfluous whitespace + * + * @return The element this element should be replaced with in the parent. If it's the same as this element, no + * actual replacement will happen. Note that adjusting the {@link #parent} and {@link #index} of the result + * is the duty of the caller, not of this method. + */ + ASTElement postParseCleanup(boolean stripWhitespace) throws ParseException { + int childCount = this.childCount; + if (childCount != 0) { + for (int i = 0; i < childCount; i++) { + ASTElement te = childBuffer[i]; + + /* + // Assertion: + if (te.getIndex() != i) { + throw new BugException("Invalid index " + te.getIndex() + " (expected: " + + i + ") for: " + te.dump(false)); + } + if (te.getParent() != this) { + throw new BugException("Invalid parent " + te.getParent() + " (expected: " + + this.dump(false) + ") for: " + te.dump(false)); + } + */ + + te = te.postParseCleanup(stripWhitespace); + childBuffer[i] = te; + te.parent = this; + te.index = i; + } + for (int i = 0; i < childCount; i++) { + ASTElement te = childBuffer[i]; + if (te.isIgnorable(stripWhitespace)) { + childCount--; + // As later isIgnorable calls might investigates the siblings, we have to move all the items now. + for (int j = i; j < childCount; j++) { + final ASTElement te2 = childBuffer[j + 1]; + childBuffer[j] = te2; + te2.index = j; + } + childBuffer[childCount] = null; + this.childCount = childCount; + i--; + } + } + if (childCount == 0) { + childBuffer = null; + } else if (childCount < childBuffer.length + && childCount <= childBuffer.length * 3 / 4) { + ASTElement[] trimmedChildBuffer = new ASTElement[childCount]; + for (int i = 0; i < childCount; i++) { + trimmedChildBuffer[i] = childBuffer[i]; + } + childBuffer = trimmedChildBuffer; + } + } + return this; + } + + boolean isIgnorable(boolean stripWhitespace) { + return false; + } + + // The following methods exist to support some fancier tree-walking + // and were introduced to support the whitespace cleanup feature in 2.2 + + ASTElement prevTerminalNode() { + ASTElement prev = previousSibling(); + if (prev != null) { + return prev.getLastLeaf(); + } else if (parent != null) { + return parent.prevTerminalNode(); + } + return null; + } + + ASTElement nextTerminalNode() { + ASTElement next = nextSibling(); + if (next != null) { + return next.getFirstLeaf(); + } else if (parent != null) { + return parent.nextTerminalNode(); + } + return null; + } + + ASTElement previousSibling() { + if (parent == null) { + return null; + } + return index > 0 ? parent.childBuffer[index - 1] : null; + } + + ASTElement nextSibling() { + if (parent == null) { + return null; + } + return index + 1 < parent.childCount ? parent.childBuffer[index + 1] : null; + } + + private ASTElement getFirstChild() { + return childCount == 0 ? null : childBuffer[0]; + } + + private ASTElement getLastChild() { + final int childCount = this.childCount; + return childCount == 0 ? null : childBuffer[childCount - 1]; + } + + private ASTElement getFirstLeaf() { + ASTElement te = this; + while (!te.isLeaf() && !(te instanceof ASTDirMacro) && !(te instanceof ASTDirCapturingAssignment)) { + // A macro or macro invocation is treated as a leaf here for special reasons + te = te.getFirstChild(); + } + return te; + } + + private ASTElement getLastLeaf() { + ASTElement te = this; + while (!te.isLeaf() && !(te instanceof ASTDirMacro) && !(te instanceof ASTDirCapturingAssignment)) { + // A macro or macro invocation is treated as a leaf here for special reasons + te = te.getLastChild(); + } + return te; + } + + /** + * Tells if executing this element has output that only depends on the template content and that has no side + * effects. + */ + boolean isOutputCacheable() { + return false; + } + + boolean isChildrenOutputCacheable() { + int ln = childCount; + for (int i = 0; i < ln; i++) { + if (!childBuffer[i].isOutputCacheable()) { + return false; + } + } + return true; + } + + /** + * determines whether this element's presence on a line indicates that we should not strip opening whitespace in the + * post-parse whitespace gobbling step. + */ + boolean heedsOpeningWhitespace() { + return false; + } + + /** + * determines whether this element's presence on a line indicates that we should not strip trailing whitespace in + * the post-parse whitespace gobbling step. + */ + boolean heedsTrailingWhitespace() { + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java b/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java index 4c5a127..ad77934 100644 --- a/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java +++ b/src/main/java/org/apache/freemarker/core/ASTHashInterpolation.java @@ -59,7 +59,7 @@ final class ASTHashInterpolation extends ASTInterpolation { } @Override - _ASTElement[] accept(Environment env) throws TemplateException, IOException { + ASTElement[] accept(Environment env) throws TemplateException, IOException { String s = calculateInterpolatedStringOrMarkup(env); Writer out = env.getOut(); if (autoEscapeOutputFormat != null) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 c370ff5..27662e3 100644 --- a/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java +++ b/src/main/java/org/apache/freemarker/core/ASTImplicitParent.java @@ -22,26 +22,26 @@ package org.apache.freemarker.core; import java.io.IOException; /** - * AST directive-like node, used where there's no other parent for a list of {@link _ASTElement}-s. Most often occurs as + * AST directive-like node, used where there's no other parent for a list of {@link ASTElement}-s. Most often occurs as * the root node of the AST. */ -final class ASTImplicitParent extends _ASTElement { +final class ASTImplicitParent extends ASTElement { ASTImplicitParent() { } @Override - _ASTElement postParseCleanup(boolean stripWhitespace) + ASTElement postParseCleanup(boolean stripWhitespace) throws ParseException { super.postParseCleanup(stripWhitespace); return getChildCount() == 1 ? getChild(0) : this; } /** - * Processes the contents of the internal <tt>_ASTElement</tt> list, + * Processes the contents of the internal <tt>ASTElement</tt> list, * and outputs the resulting text. */ @Override - _ASTElement[] accept(Environment env) + ASTElement[] accept(Environment env) throws TemplateException, IOException { return getChildBuffer(); } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/src/main/java/org/apache/freemarker/core/ASTInterpolation.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTInterpolation.java b/src/main/java/org/apache/freemarker/core/ASTInterpolation.java index 3d958d0..e377c8f 100644 --- a/src/main/java/org/apache/freemarker/core/ASTInterpolation.java +++ b/src/main/java/org/apache/freemarker/core/ASTInterpolation.java @@ -23,7 +23,7 @@ import org.apache.freemarker.core.model.TemplateMarkupOutputModel; /** * AST interpolation node superclass. */ -abstract class ASTInterpolation extends _ASTElement { +abstract class ASTInterpolation extends ASTElement { protected abstract String dump(boolean canonical, boolean inStringLiteral); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/src/main/java/org/apache/freemarker/core/ASTNode.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/core/ASTNode.java b/src/main/java/org/apache/freemarker/core/ASTNode.java index 19dd62d..6511c80 100644 --- a/src/main/java/org/apache/freemarker/core/ASTNode.java +++ b/src/main/java/org/apache/freemarker/core/ASTNode.java @@ -37,7 +37,7 @@ abstract class ASTNode { } final void setLocation(Template template, Token tagBegin, Token tagEnd, TemplateElements children) { - _ASTElement lastChild = children.getLast(); + ASTElement lastChild = children.getLast(); if (lastChild != null) { // [<#if exp>children]<#else> setLocation(template, tagBegin, lastChild); @@ -172,7 +172,7 @@ abstract class ASTNode { * FTL generated from the AST of the node, which must be parseable to an AST that does the same as the original * source, assuming we turn off automatic white-space removal when parsing the canonical form. * - * @see _ASTElement#getDescription() + * @see ASTElement#getDescription() * @see #getNodeTypeSymbol() */ abstract public String getCanonicalForm(); @@ -184,11 +184,11 @@ abstract class ASTNode { * that is equivalent with the original could be reconstructed from the tree view. Thus, for literal values that are * leaf nodes the symbols should be the canonical form of value. * - * Note that {@link _ASTElement#getDescription()} has similar role, only it doesn't go under the element level + * Note that {@link ASTElement#getDescription()} has similar role, only it doesn't go under the element level * (i.e. down to the expression level), instead it always prints the embedded expressions itself. * * @see #getCanonicalForm() - * @see _ASTElement#getDescription() + * @see ASTElement#getDescription() */ abstract String getNodeTypeSymbol(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 8e8c8a3..39e5b39 100644 --- a/src/main/java/org/apache/freemarker/core/ASTStaticText.java +++ b/src/main/java/org/apache/freemarker/core/ASTStaticText.java @@ -27,7 +27,7 @@ import org.apache.freemarker.core.util._StringUtil; /** * AST node representing static text. */ -final class ASTStaticText extends _ASTElement { +final class ASTStaticText extends ASTElement { // We're using char[] instead of String for storing the text block because // Writer.write(String) involves copying the String contents to a char[] @@ -61,7 +61,7 @@ final class ASTStaticText extends _ASTElement { */ @Deprecated @Override - public _ASTElement[] accept(Environment env) + public ASTElement[] accept(Environment env) throws IOException { env.getOut().write(text); return null; @@ -103,7 +103,7 @@ final class ASTStaticText extends _ASTElement { } @Override - _ASTElement postParseCleanup(boolean stripWhitespace) { + ASTElement postParseCleanup(boolean stripWhitespace) { if (text.length == 0) return this; int openingCharsToStrip = 0, trailingCharsToStrip = 0; boolean deliberateLeftTrim = deliberateLeftTrim(); @@ -111,7 +111,7 @@ final class ASTStaticText extends _ASTElement { if (!stripWhitespace || text.length == 0 ) { return this; } - _ASTElement parentElement = getParent(); + ASTElement parentElement = getParent(); if (isTopLevelTextIfParentIs(parentElement) && previousSibling() == null) { return this; } @@ -141,7 +141,7 @@ final class ASTStaticText extends _ASTElement { */ private boolean deliberateLeftTrim() { boolean result = false; - for (_ASTElement elem = nextTerminalNode(); + for (ASTElement elem = nextTerminalNode(); elem != null && elem.beginLine == endLine; elem = elem.nextTerminalNode()) { if (elem instanceof ASTDirTOrTrOrTl) { @@ -179,7 +179,7 @@ final class ASTStaticText extends _ASTElement { */ private boolean deliberateRightTrim() { boolean result = false; - for (_ASTElement elem = prevTerminalNode(); + for (ASTElement elem = prevTerminalNode(); elem != null && elem.endLine == beginLine; elem = elem.prevTerminalNode()) { if (elem instanceof ASTDirTOrTrOrTl) { @@ -213,7 +213,7 @@ final class ASTStaticText extends _ASTElement { if (_StringUtil.isTrimmableToEmpty(trailingPart)) { // THIS BLOCK IS HEINOUS! THERE MUST BE A BETTER WAY! REVISIT (JR) boolean trimTrailingPart = true; - for (_ASTElement te = nextTerminalNode(); + for (ASTElement te = nextTerminalNode(); te != null && te.beginLine == endLine; te = te.nextTerminalNode()) { if (te.heedsOpeningWhitespace()) { @@ -276,7 +276,7 @@ final class ASTStaticText extends _ASTElement { } // We look at the preceding elements on the line to see if we should // strip the opening newline and any whitespace preceding it. - for (_ASTElement elem = prevTerminalNode(); + for (ASTElement elem = prevTerminalNode(); elem != null && elem.endLine == beginLine; elem = elem.prevTerminalNode()) { if (elem.heedsOpeningWhitespace()) { @@ -300,7 +300,7 @@ final class ASTStaticText extends _ASTElement { } // We look at the elements afterward on the same line to see if we should // strip any whitespace after the last newline - for (_ASTElement elem = nextTerminalNode(); + for (ASTElement elem = nextTerminalNode(); elem != null && elem.beginLine == endLine; elem = elem.nextTerminalNode()) { if (elem.heedsTrailingWhitespace()) { @@ -352,10 +352,10 @@ final class ASTStaticText extends _ASTElement { if (!_StringUtil.isTrimmableToEmpty(text)) { return false; } - _ASTElement parentElement = getParent(); + ASTElement parentElement = getParent(); boolean atTopLevel = isTopLevelTextIfParentIs(parentElement); - _ASTElement prevSibling = previousSibling(); - _ASTElement nextSibling = nextSibling(); + ASTElement prevSibling = previousSibling(); + ASTElement nextSibling = nextSibling(); return ((prevSibling == null && atTopLevel) || nonOutputtingType(prevSibling)) && ((nextSibling == null && atTopLevel) || nonOutputtingType(nextSibling)); } else { @@ -363,13 +363,13 @@ final class ASTStaticText extends _ASTElement { } } - private boolean isTopLevelTextIfParentIs(_ASTElement parentElement) { + private boolean isTopLevelTextIfParentIs(ASTElement parentElement) { return parentElement == null || parentElement.getParent() == null && parentElement instanceof ASTImplicitParent; } - private boolean nonOutputtingType(_ASTElement element) { + private boolean nonOutputtingType(ASTElement element) { return (element instanceof ASTDirMacro || element instanceof ASTDirAssignment || element instanceof ASTDirAssignmentsContainer || http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 895a2b6..8deff30 100644 --- a/src/main/java/org/apache/freemarker/core/Environment.java +++ b/src/main/java/org/apache/freemarker/core/Environment.java @@ -113,7 +113,7 @@ public final class Environment extends Configurable { private final Configuration configuration; private final TemplateHashModel rootDataModel; - private _ASTElement[] instructionStack = new _ASTElement[16]; + private ASTElement[] instructionStack = new ASTElement[16]; private int instructionStackSize = 0; private final ArrayList recoveredErrorStack = new ArrayList(); @@ -248,7 +248,7 @@ public final class Environment extends Configurable { public DirectiveCallPlace getCurrentDirectiveCallPlace() { int ln = instructionStackSize; if (ln == 0) return null; - _ASTElement te = instructionStack[ln - 1]; + ASTElement te = instructionStack[ln - 1]; if (te instanceof ASTDirUserDefined) return (ASTDirUserDefined) te; if (te instanceof ASTDirMacro && ln > 1 && instructionStack[ln - 2] instanceof ASTDirUserDefined) { return (ASTDirUserDefined) instructionStack[ln - 2]; @@ -282,7 +282,7 @@ public final class Environment extends Configurable { clearCachedValues(); try { doAutoImportsAndIncludes(this); - visit(getMainTemplate().getRootTreeNode()); + visit(getMainTemplate().getRootASTNode()); // It's here as we must not flush if there was an exception. if (getAutoFlush()) { out.flush(); @@ -299,13 +299,13 @@ public final class Environment extends Configurable { /** * "Visit" the template element. */ - void visit(_ASTElement element) throws IOException, TemplateException { - // ATTENTION: This method body is manually "inlined" into visit(_ASTElement[]); keep them in sync! + void visit(ASTElement element) throws IOException, TemplateException { + // ATTENTION: This method body is manually "inlined" into visit(ASTElement[]); keep them in sync! pushElement(element); try { - _ASTElement[] templateElementsToVisit = element.accept(this); + ASTElement[] templateElementsToVisit = element.accept(this); if (templateElementsToVisit != null) { - for (_ASTElement el : templateElementsToVisit) { + for (ASTElement el : templateElementsToVisit) { if (el == null) { break; // Skip unused trailing buffer capacity } @@ -317,7 +317,7 @@ public final class Environment extends Configurable { } finally { popElement(); } - // ATTENTION: This method body above is manually "inlined" into visit(_ASTElement[]); keep them in sync! + // ATTENTION: This method body above is manually "inlined" into visit(ASTElement[]); keep them in sync! } /** @@ -326,22 +326,22 @@ public final class Environment extends Configurable { * * @since 2.3.24 */ - final void visit(_ASTElement[] elementBuffer) throws IOException, TemplateException { + final void visit(ASTElement[] elementBuffer) throws IOException, TemplateException { if (elementBuffer == null) { return; } - for (_ASTElement element : elementBuffer) { + for (ASTElement element : elementBuffer) { if (element == null) { break; // Skip unused trailing buffer capacity } - // ATTENTION: This part is the manually "inlining" of visit(_ASTElement[]); keep them in sync! + // ATTENTION: This part is the manually "inlining" of visit(ASTElement[]); keep them in sync! // We don't just let Hotspot to do it, as we want a hard guarantee regarding maximum stack usage. pushElement(element); try { - _ASTElement[] templateElementsToVisit = element.accept(this); + ASTElement[] templateElementsToVisit = element.accept(this); if (templateElementsToVisit != null) { - for (_ASTElement el : templateElementsToVisit) { + for (ASTElement el : templateElementsToVisit) { if (el == null) { break; // Skip unused trailing buffer capacity } @@ -353,24 +353,24 @@ public final class Environment extends Configurable { } finally { popElement(); } - // ATTENTION: This part above is the manually "inlining" of visit(_ASTElement[]); keep them in sync! + // ATTENTION: This part above is the manually "inlining" of visit(ASTElement[]); keep them in sync! } } @SuppressFBWarnings(value = "RANGE_ARRAY_INDEX", justification = "Not called when stack is empty") - private _ASTElement replaceTopElement(_ASTElement element) { + private ASTElement replaceTopElement(ASTElement element) { return instructionStack[instructionStackSize - 1] = element; } private static final TemplateModel[] NO_OUT_ARGS = new TemplateModel[0]; - void visit(final _ASTElement element, + void visit(final ASTElement element, TemplateDirectiveModel directiveModel, Map args, final List bodyParameterNames) throws TemplateException, IOException { - visit(new _ASTElement[] { element }, directiveModel, args, bodyParameterNames); + visit(new ASTElement[] { element }, directiveModel, args, bodyParameterNames); } - void visit(final _ASTElement[] childBuffer, + void visit(final ASTElement[] childBuffer, TemplateDirectiveModel directiveModel, Map args, final List bodyParameterNames) throws TemplateException, IOException { TemplateDirectiveBody nested; @@ -419,7 +419,7 @@ public final class Environment extends Configurable { * @param args * optional arguments fed to the transform */ - void visitAndTransform(_ASTElement[] elementBuffer, + void visitAndTransform(ASTElement[] elementBuffer, TemplateTransformModel transform, Map args) throws TemplateException, IOException { @@ -469,7 +469,7 @@ public final class Environment extends Configurable { * Visit a block using buffering/recovery */ void visitAttemptRecover( - ASTDirAttemptRecoverContainer attemptBlock, _ASTElement attemptedSection, ASTDirRecover recoverySection) + ASTDirAttemptRecoverContainer attemptBlock, ASTElement attemptedSection, ASTDirRecover recoverySection) throws TemplateException, IOException { Writer prevOut = out; StringWriter sw = new StringWriter(); @@ -527,7 +527,7 @@ public final class Environment extends Configurable { void invokeNestedContent(ASTDirNested.Context bodyCtx) throws TemplateException, IOException { ASTDirMacro.Context invokingMacroContext = getCurrentMacroContext(); LocalContextStack prevLocalContextStack = localContextStack; - _ASTElement[] nestedContentBuffer = invokingMacroContext.nestedContentBuffer; + ASTElement[] nestedContentBuffer = invokingMacroContext.nestedContentBuffer; if (nestedContentBuffer != null) { currentMacroContext = invokingMacroContext.prevMacroContext; currentNamespace = invokingMacroContext.nestedContentNamespace; @@ -654,7 +654,7 @@ public final class Environment extends Configurable { */ void invoke(ASTDirMacro macro, Map namedArgs, List positionalArgs, - List bodyParameterNames, _ASTElement[] childBuffer) throws TemplateException, IOException { + List bodyParameterNames, ASTElement[] childBuffer) throws TemplateException, IOException { if (macro == ASTDirMacro.DO_NOTHING_MACRO) { return; } @@ -1959,7 +1959,7 @@ public final class Environment extends Configurable { * @since 2.3.21 */ static void outputInstructionStack( - _ASTElement[] instructionStackSnapshot, boolean terseMode, Writer w) { + ASTElement[] instructionStackSnapshot, boolean terseMode, Writer w) { final PrintWriter pw = (PrintWriter) (w instanceof PrintWriter ? w : null); try { if (instructionStackSnapshot != null) { @@ -1974,7 +1974,7 @@ public final class Environment extends Configurable { int trailingFramesHidden = 0; int framesPrinted = 0; for (int frameIdx = 0; frameIdx < totalFrames; frameIdx++) { - _ASTElement stackEl = instructionStackSnapshot[frameIdx]; + ASTElement stackEl = instructionStackSnapshot[frameIdx]; final boolean nestingRelatedElement = (frameIdx > 0 && stackEl instanceof ASTDirNested) || (frameIdx > 1 && instructionStackSnapshot[frameIdx - 1] instanceof ASTDirNested); if (framesPrinted < framesToPrint) { @@ -2037,12 +2037,12 @@ public final class Environment extends Configurable { * * @since 2.3.20 */ - _ASTElement[] getInstructionStackSnapshot() { + ASTElement[] getInstructionStackSnapshot() { int requiredLength = 0; int ln = instructionStackSize; for (int i = 0; i < ln; i++) { - _ASTElement stackEl = instructionStack[i]; + ASTElement stackEl = instructionStack[i]; if (i == ln - 1 || stackEl.isShownInStackTrace()) { requiredLength++; } @@ -2050,10 +2050,10 @@ public final class Environment extends Configurable { if (requiredLength == 0) return null; - _ASTElement[] result = new _ASTElement[requiredLength]; + ASTElement[] result = new ASTElement[requiredLength]; int dstIdx = requiredLength - 1; for (int i = 0; i < ln; i++) { - _ASTElement stackEl = instructionStack[i]; + ASTElement stackEl = instructionStack[i]; if (i == ln - 1 || stackEl.isShownInStackTrace()) { result[dstIdx--] = stackEl; } @@ -2062,13 +2062,13 @@ public final class Environment extends Configurable { return result; } - static String instructionStackItemToString(_ASTElement stackEl) { + static String instructionStackItemToString(ASTElement stackEl) { StringBuilder sb = new StringBuilder(); appendInstructionStackItem(stackEl, sb); return sb.toString(); } - static void appendInstructionStackItem(_ASTElement stackEl, StringBuilder sb) { + static void appendInstructionStackItem(ASTElement stackEl, StringBuilder sb) { sb.append(MessageUtil.shorten(stackEl.getDescription(), 40)); sb.append(" ["); @@ -2083,7 +2083,7 @@ public final class Environment extends Configurable { sb.append("]"); } - static private ASTDirMacro getEnclosingMacro(_ASTElement stackEl) { + static private ASTDirMacro getEnclosingMacro(ASTElement stackEl) { while (stackEl != null) { if (stackEl instanceof ASTDirMacro) return (ASTDirMacro) stackEl; stackEl = stackEl.getParent(); @@ -2228,11 +2228,11 @@ public final class Environment extends Configurable { }; } - private void pushElement(_ASTElement element) { + private void pushElement(ASTElement element) { final int newSize = ++instructionStackSize; - _ASTElement[] instructionStack = this.instructionStack; + ASTElement[] instructionStack = this.instructionStack; if (newSize > instructionStack.length) { - final _ASTElement[] newInstructionStack = new _ASTElement[newSize * 2]; + final ASTElement[] newInstructionStack = new ASTElement[newSize * 2]; for (int i = 0; i < instructionStack.length; i++) { newInstructionStack[i] = instructionStack[i]; } @@ -2246,7 +2246,7 @@ public final class Environment extends Configurable { instructionStackSize--; } - void replaceElementStackTop(_ASTElement instr) { + void replaceElementStackTop(ASTElement instr) { instructionStack[instructionStackSize - 1] = instr; } @@ -2449,7 +2449,7 @@ public final class Environment extends Configurable { final Template prevTemplate; importMacros(includedTemplate); - visit(includedTemplate.getRootTreeNode()); + visit(includedTemplate.getRootASTNode()); } /** @@ -2630,7 +2630,7 @@ public final class Environment extends Configurable { return _CacheAPI.toRootBasedName(configuration.getTemplateNameFormat(), baseName, targetName); } - String renderElementToString(_ASTElement te) throws IOException, TemplateException { + String renderElementToString(ASTElement te) throws IOException, TemplateException { Writer prevOut = out; try { StringWriter sw = new StringWriter(); @@ -2709,9 +2709,9 @@ public final class Environment extends Configurable { final class NestedElementTemplateDirectiveBody implements TemplateDirectiveBody { - private final _ASTElement[] childBuffer; + private final ASTElement[] childBuffer; - private NestedElementTemplateDirectiveBody(_ASTElement[] childBuffer) { + private NestedElementTemplateDirectiveBody(ASTElement[] childBuffer) { this.childBuffer = childBuffer; } @@ -2726,7 +2726,7 @@ public final class Environment extends Configurable { } } - _ASTElement[] getChildrenBuffer() { + ASTElement[] getChildrenBuffer() { return childBuffer; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d74ccf3c/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 3ae7db8..9f54af9 100644 --- a/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java +++ b/src/main/java/org/apache/freemarker/core/NestedContentNotSupportedException.java @@ -36,7 +36,7 @@ public class NestedContentNotSupportedException extends TemplateException { return; } if (body instanceof NestedElementTemplateDirectiveBody) { - _ASTElement[] tes = ((NestedElementTemplateDirectiveBody) body).getChildrenBuffer(); + ASTElement[] tes = ((NestedElementTemplateDirectiveBody) body).getChildrenBuffer(); if (tes == null || tes.length == 0 || tes[0] instanceof ASTThreadInterruptionCheck && (tes.length == 1 || tes[1] == null)) { return;