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