Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3BB51200B26 for ; Sun, 12 Jun 2016 18:53:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3A53C160A5C; Sun, 12 Jun 2016 16:53:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5BD83160A62 for ; Sun, 12 Jun 2016 18:53:49 +0200 (CEST) Received: (qmail 98795 invoked by uid 500); 12 Jun 2016 16:53:48 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 98759 invoked by uid 99); 12 Jun 2016 16:53:48 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jun 2016 16:53:48 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2B3771A0856 for ; Sun, 12 Jun 2016 16:53:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id oMQM58Qng1h4 for ; Sun, 12 Jun 2016 16:53:46 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id B76CA60E35 for ; Sun, 12 Jun 2016 16:53:44 +0000 (UTC) Received: (qmail 98116 invoked by uid 99); 12 Jun 2016 16:53:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jun 2016 16:53:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AFCCEED30F; Sun, 12 Jun 2016 16:53:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Sun, 12 Jun 2016 16:54:00 -0000 Message-Id: <3298da3c584844379c38c44c26812364@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [19/50] incubator-freemarker git commit: (Aesthetic method order change.) archived-at: Sun, 12 Jun 2016 16:53:50 -0000 (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 Commit: b9b554aa3cf7fef97282871b741d7e9ce1ea8de2 Parents: fafc5fc Author: ddekany Authored: Tue May 31 20:53:31 2016 +0200 Committer: ddekany 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; }