Mon, 04 May 2009 21:10:41 -0700
6658158: Mutable statics in SAAJ (findbugs)
6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs)
Reviewed-by: darcy
1 /*
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25 package com.sun.codemodel.internal;
27 /**
28 * ForEach Statement
29 * This will generate the code for statement based on the new
30 * j2se 1.5 j.l.s.
31 *
32 * @author Bhakti
33 */
34 public final class JForEach implements JStatement {
36 private final JType type;
37 private final String var;
38 private JBlock body = null; // lazily created
39 private final JExpression collection;
40 private final JVar loopVar;
42 public JForEach(JType vartype, String variable, JExpression collection) {
44 this.type = vartype;
45 this.var = variable;
46 this.collection = collection;
47 loopVar = new JVar(JMods.forVar(JMod.NONE), type, var, collection);
48 }
51 /**
52 * Returns a reference to the loop variable.
53 */
54 public JVar var() {
55 return loopVar;
56 }
58 public JBlock body() {
59 if (body == null)
60 body = new JBlock();
61 return body;
62 }
64 public void state(JFormatter f) {
65 f.p("for (");
66 f.g(type).id(var).p(": ").g(collection);
67 f.p(')');
68 if (body != null)
69 f.g(body).nl();
70 else
71 f.p(';').nl();
72 }
74 }