You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2016/05/31 18:53:45 UTC
[2/2] incubator-freemarker git commit: (Aesthetic method order
change.)
(Aesthetic method order change.)
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/b9b554aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/b9b554aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/b9b554aa
Branch: refs/heads/2.3-gae
Commit: b9b554aa3cf7fef97282871b741d7e9ce1ea8de2
Parents: fafc5fc
Author: ddekany <dd...@apache.org>
Authored: Tue May 31 20:53:31 2016 +0200
Committer: ddekany <dd...@apache.org>
Committed: Tue May 31 20:53:31 2016 +0200
----------------------------------------------------------------------
.../java/freemarker/core/IteratorBlock.java | 150 +++++++++----------
1 file changed, 75 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/b9b554aa/src/main/java/freemarker/core/IteratorBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/IteratorBlock.java b/src/main/java/freemarker/core/IteratorBlock.java
index d59d96b..07b0ef3 100644
--- a/src/main/java/freemarker/core/IteratorBlock.java
+++ b/src/main/java/freemarker/core/IteratorBlock.java
@@ -273,6 +273,81 @@ final class IteratorBlock extends TemplateElement {
: executedNestedContentForHashListing(env, childBuffer);
}
+ private boolean executedNestedContentForCollOrSeqListing(Environment env, TemplateElement[] childBuffer)
+ throws TemplateModelException, IOException, TemplateException,
+ NonSequenceOrCollectionException, InvalidReferenceException {
+ final boolean listNotEmpty;
+ if (listedValue instanceof TemplateCollectionModel) {
+ final TemplateCollectionModel collModel = (TemplateCollectionModel) listedValue;
+ final TemplateModelIterator iterModel
+ = openedIterator == null ? collModel.iterator()
+ : ((TemplateModelIterator) openedIterator);
+ listNotEmpty = iterModel.hasNext();
+ if (listNotEmpty) {
+ if (loopVarName != null) {
+ try {
+ do {
+ loopVar = iterModel.next();
+ hasNext = iterModel.hasNext();
+ env.visit(childBuffer);
+ index++;
+ } while (hasNext);
+ } catch (BreakInstruction.Break br) {
+ // Silently exit loop
+ }
+ openedIterator = null;
+ } else {
+ // We must reuse this later, because TemplateCollectionModel-s that wrap an Iterator only
+ // allow one iterator() call.
+ openedIterator = iterModel;
+ env.visit(childBuffer);
+ }
+ }
+ } else if (listedValue instanceof TemplateSequenceModel) {
+ final TemplateSequenceModel seqModel = (TemplateSequenceModel) listedValue;
+ final int size = seqModel.size();
+ listNotEmpty = size != 0;
+ if (listNotEmpty) {
+ if (loopVarName != null) {
+ try {
+ for (index = 0; index < size; index++) {
+ loopVar = seqModel.get(index);
+ hasNext = (size > index + 1);
+ env.visit(childBuffer);
+ }
+ } catch (BreakInstruction.Break br) {
+ // Silently exit loop
+ }
+ } else {
+ env.visit(childBuffer);
+ }
+ }
+ } else if (env.isClassicCompatible()) {
+ listNotEmpty = true;
+ if (loopVarName != null) {
+ loopVar = listedValue;
+ hasNext = false;
+ }
+ try {
+ env.visit(childBuffer);
+ } catch (BreakInstruction.Break br) {
+ // Silently exit "loop"
+ }
+ } else if (listedValue instanceof TemplateHashModelEx
+ && !NonSequenceOrCollectionException.isWrappedIterable(listedValue)) {
+ throw new NonSequenceOrCollectionException(env,
+ new _ErrorDescriptionBuilder("The value you try to list is ",
+ new _DelayedAOrAn(new _DelayedFTLTypeDescription(listedValue)),
+ ", thus you must specify two loop variables after the \"as\"; one for the key, and "
+ + "another for the value, like ", "<#... as k, v>", ")."
+ ));
+ } else {
+ throw new NonSequenceOrCollectionException(
+ listedExp, listedValue, env);
+ }
+ return listNotEmpty;
+ }
+
private boolean executedNestedContentForHashListing(Environment env, TemplateElement[] childBuffer)
throws TemplateModelException, IOException, TemplateException {
final boolean hashNotEmpty;
@@ -353,81 +428,6 @@ final class IteratorBlock extends TemplateElement {
return hashNotEmpty;
}
- private boolean executedNestedContentForCollOrSeqListing(Environment env, TemplateElement[] childBuffer)
- throws TemplateModelException, IOException, TemplateException,
- NonSequenceOrCollectionException, InvalidReferenceException {
- final boolean listNotEmpty;
- if (listedValue instanceof TemplateCollectionModel) {
- final TemplateCollectionModel collModel = (TemplateCollectionModel) listedValue;
- final TemplateModelIterator iterModel
- = openedIterator == null ? collModel.iterator()
- : ((TemplateModelIterator) openedIterator);
- listNotEmpty = iterModel.hasNext();
- if (listNotEmpty) {
- if (loopVarName != null) {
- try {
- do {
- loopVar = iterModel.next();
- hasNext = iterModel.hasNext();
- env.visit(childBuffer);
- index++;
- } while (hasNext);
- } catch (BreakInstruction.Break br) {
- // Silently exit loop
- }
- openedIterator = null;
- } else {
- // We must reuse this later, because TemplateCollectionModel-s that wrap an Iterator only
- // allow one iterator() call.
- openedIterator = iterModel;
- env.visit(childBuffer);
- }
- }
- } else if (listedValue instanceof TemplateSequenceModel) {
- final TemplateSequenceModel seqModel = (TemplateSequenceModel) listedValue;
- final int size = seqModel.size();
- listNotEmpty = size != 0;
- if (listNotEmpty) {
- if (loopVarName != null) {
- try {
- for (index = 0; index < size; index++) {
- loopVar = seqModel.get(index);
- hasNext = (size > index + 1);
- env.visit(childBuffer);
- }
- } catch (BreakInstruction.Break br) {
- // Silently exit loop
- }
- } else {
- env.visit(childBuffer);
- }
- }
- } else if (env.isClassicCompatible()) {
- listNotEmpty = true;
- if (loopVarName != null) {
- loopVar = listedValue;
- hasNext = false;
- }
- try {
- env.visit(childBuffer);
- } catch (BreakInstruction.Break br) {
- // Silently exit "loop"
- }
- } else if (listedValue instanceof TemplateHashModelEx
- && !NonSequenceOrCollectionException.isWrappedIterable(listedValue)) {
- throw new NonSequenceOrCollectionException(env,
- new _ErrorDescriptionBuilder("The value you try to list is ",
- new _DelayedAOrAn(new _DelayedFTLTypeDescription(listedValue)),
- ", thus you must specify two loop variables after the \"as\"; one for the key, and "
- + "another for the value, like ", "<#... as k, v>", ")."
- ));
- } else {
- throw new NonSequenceOrCollectionException(
- listedExp, listedValue, env);
- }
- return listNotEmpty;
- }
-
String getLoopVariableName() {
return this.loopVarName;
}