jaxws/src/share/classes/com/sun/codemodel/internal/JMethod.java
author tbell
Mon, 04 May 2009 21:10:41 -0700
changeset 2719 99d59312294b
parent 2678 57cf2a1c1a05
child 3530 18fb7507984b
permissions -rw-r--r--
6658158: Mutable statics in SAAJ (findbugs) 6658163: txw2.DatatypeWriter.BUILDIN is a mutable static (findbugs) Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
474761f14bca Initial load
duke
parents:
diff changeset
     1
/*
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
8
474761f14bca Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
474761f14bca Initial load
duke
parents:
diff changeset
     4
 *
474761f14bca Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
474761f14bca Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
474761f14bca Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
474761f14bca Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
474761f14bca Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
474761f14bca Initial load
duke
parents:
diff changeset
    10
 *
474761f14bca Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
474761f14bca Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
474761f14bca Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
474761f14bca Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
474761f14bca Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
474761f14bca Initial load
duke
parents:
diff changeset
    16
 *
474761f14bca Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
474761f14bca Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
474761f14bca Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
474761f14bca Initial load
duke
parents:
diff changeset
    20
 *
474761f14bca Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
474761f14bca Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
474761f14bca Initial load
duke
parents:
diff changeset
    23
 * have any questions.
474761f14bca Initial load
duke
parents:
diff changeset
    24
 */
474761f14bca Initial load
duke
parents:
diff changeset
    25
474761f14bca Initial load
duke
parents:
diff changeset
    26
package com.sun.codemodel.internal;
474761f14bca Initial load
duke
parents:
diff changeset
    27
474761f14bca Initial load
duke
parents:
diff changeset
    28
import java.lang.annotation.Annotation;
474761f14bca Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
474761f14bca Initial load
duke
parents:
diff changeset
    30
import java.util.List;
474761f14bca Initial load
duke
parents:
diff changeset
    31
import java.util.Set;
474761f14bca Initial load
duke
parents:
diff changeset
    32
import java.util.TreeSet;
474761f14bca Initial load
duke
parents:
diff changeset
    33
474761f14bca Initial load
duke
parents:
diff changeset
    34
import com.sun.codemodel.internal.util.ClassNameComparator;
474761f14bca Initial load
duke
parents:
diff changeset
    35
474761f14bca Initial load
duke
parents:
diff changeset
    36
/**
474761f14bca Initial load
duke
parents:
diff changeset
    37
 * Java method.
474761f14bca Initial load
duke
parents:
diff changeset
    38
 */
474761f14bca Initial load
duke
parents:
diff changeset
    39
public class JMethod extends JGenerifiableImpl implements JDeclaration, JAnnotatable {
474761f14bca Initial load
duke
parents:
diff changeset
    40
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    41
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    42
         * Modifiers for this method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    43
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    44
        private JMods mods;
8
474761f14bca Initial load
duke
parents:
diff changeset
    45
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    46
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    47
         * Return type for this method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    48
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    49
        private JType type = null;
8
474761f14bca Initial load
duke
parents:
diff changeset
    50
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    51
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    52
         * Name of this method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    53
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    54
        private String name = null;
8
474761f14bca Initial load
duke
parents:
diff changeset
    55
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    56
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    57
         * List of parameters for this method's declaration
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    58
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    59
        private final List<JVar> params = new ArrayList<JVar>();
8
474761f14bca Initial load
duke
parents:
diff changeset
    60
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    61
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    62
         * Set of exceptions that this method may throw.
8
474761f14bca Initial load
duke
parents:
diff changeset
    63
     * A set instance lazily created.
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    64
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    65
        private Set<JClass> _throws;
8
474761f14bca Initial load
duke
parents:
diff changeset
    66
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    67
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    68
         * JBlock of statements that makes up the body this method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    69
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    70
        private JBlock body = null;
8
474761f14bca Initial load
duke
parents:
diff changeset
    71
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    72
        private JDefinedClass outer;
8
474761f14bca Initial load
duke
parents:
diff changeset
    73
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    74
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    75
         * javadoc comments for this JMethod
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    76
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    77
        private JDocComment jdoc = null;
8
474761f14bca Initial load
duke
parents:
diff changeset
    78
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    79
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    80
         * Variable parameter for this method's varargs declaration
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    81
         * introduced in J2SE 1.5
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    82
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    83
        private JVar varParam = null;
8
474761f14bca Initial load
duke
parents:
diff changeset
    84
474761f14bca Initial load
duke
parents:
diff changeset
    85
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    86
     * Annotations on this variable. Lazily created.
474761f14bca Initial load
duke
parents:
diff changeset
    87
     */
474761f14bca Initial load
duke
parents:
diff changeset
    88
    private List<JAnnotationUse> annotations = null;
474761f14bca Initial load
duke
parents:
diff changeset
    89
474761f14bca Initial load
duke
parents:
diff changeset
    90
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    91
        private boolean isConstructor() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    92
                return type == null;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
    93
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
    94
474761f14bca Initial load
duke
parents:
diff changeset
    95
    /** To set the default value for the
474761f14bca Initial load
duke
parents:
diff changeset
    96
     *  annotation member
474761f14bca Initial load
duke
parents:
diff changeset
    97
     */
474761f14bca Initial load
duke
parents:
diff changeset
    98
    private JExpression defaultValue = null;
474761f14bca Initial load
duke
parents:
diff changeset
    99
474761f14bca Initial load
duke
parents:
diff changeset
   100
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   101
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   102
         * JMethod constructor
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   103
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   104
         * @param mods
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   105
         *        Modifiers for this method's declaration
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   106
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   107
         * @param type
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   108
         *        Return type for the method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   109
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   110
         * @param name
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   111
         *        Name of this method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   112
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   113
        JMethod(JDefinedClass outer, int mods, JType type, String name) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   114
                this.mods = JMods.forMethod(mods);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   115
                this.type = type;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   116
                this.name = name;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   117
                this.outer = outer;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   118
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   119
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   120
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   121
         * Constructor constructor
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   122
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   123
         * @param mods
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   124
         *        Modifiers for this constructor's declaration
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   125
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   126
         * @param _class
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   127
         *        JClass containing this constructor
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   128
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   129
        JMethod(int mods, JDefinedClass _class) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   130
                this.mods = JMods.forMethod(mods);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   131
                this.type = null;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   132
                this.name = _class.name();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   133
                this.outer = _class;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   134
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   135
474761f14bca Initial load
duke
parents:
diff changeset
   136
    private Set<JClass> getThrows() {
474761f14bca Initial load
duke
parents:
diff changeset
   137
        if(_throws==null)
474761f14bca Initial load
duke
parents:
diff changeset
   138
            _throws = new TreeSet<JClass>(ClassNameComparator.theInstance);
474761f14bca Initial load
duke
parents:
diff changeset
   139
        return _throws;
474761f14bca Initial load
duke
parents:
diff changeset
   140
    }
474761f14bca Initial load
duke
parents:
diff changeset
   141
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   142
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   143
         * Add an exception to the list of exceptions that this
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   144
         * method may throw.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   145
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   146
         * @param exception
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   147
         *        Name of an exception that this method may throw
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   148
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   149
        public JMethod _throws(JClass exception) {
8
474761f14bca Initial load
duke
parents:
diff changeset
   150
        getThrows().add(exception);
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   151
                return this;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   152
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   153
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   154
        public JMethod _throws(Class exception) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   155
                return _throws(outer.owner().ref(exception));
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   156
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   157
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   158
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   159
         * Add the specified variable to the list of parameters
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   160
         * for this method signature.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   161
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   162
         * @param type
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   163
         *        JType of the parameter being added
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   164
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   165
         * @param name
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   166
         *        Name of the parameter being added
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   167
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   168
         * @return New parameter variable
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   169
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   170
        public JVar param(int mods, JType type, String name) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   171
                JVar v = new JVar(JMods.forVar(mods), type, name, null);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   172
                params.add(v);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   173
                return v;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   174
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   175
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   176
        public JVar param(JType type, String name) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   177
                return param(JMod.NONE, type, name);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   178
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   179
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   180
        public JVar param(int mods, Class type, String name) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   181
                return param(mods, outer.owner()._ref(type), name);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   182
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   183
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   184
        public JVar param(Class type, String name) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   185
                return param(outer.owner()._ref(type), name);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   186
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   187
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   188
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   189
         * @see #varParam(JType, String)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   190
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   191
        public JVar varParam(Class type, String name) {
8
474761f14bca Initial load
duke
parents:
diff changeset
   192
        return varParam(outer.owner()._ref(type),name);
474761f14bca Initial load
duke
parents:
diff changeset
   193
    }
474761f14bca Initial load
duke
parents:
diff changeset
   194
474761f14bca Initial load
duke
parents:
diff changeset
   195
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   196
     * Add the specified variable argument to the list of parameters
474761f14bca Initial load
duke
parents:
diff changeset
   197
     * for this method signature.
474761f14bca Initial load
duke
parents:
diff changeset
   198
     *
474761f14bca Initial load
duke
parents:
diff changeset
   199
     * @param type
474761f14bca Initial load
duke
parents:
diff changeset
   200
     *      Type of the parameter being added.
474761f14bca Initial load
duke
parents:
diff changeset
   201
     *
474761f14bca Initial load
duke
parents:
diff changeset
   202
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   203
     *        Name of the parameter being added
474761f14bca Initial load
duke
parents:
diff changeset
   204
     *
474761f14bca Initial load
duke
parents:
diff changeset
   205
     * @return the variable parameter
474761f14bca Initial load
duke
parents:
diff changeset
   206
     *
474761f14bca Initial load
duke
parents:
diff changeset
   207
     * @throws IllegalStateException
474761f14bca Initial load
duke
parents:
diff changeset
   208
     *      If this method is called twice.
474761f14bca Initial load
duke
parents:
diff changeset
   209
     *      varargs in J2SE 1.5 can appear only once in the
474761f14bca Initial load
duke
parents:
diff changeset
   210
     *      method signature.
474761f14bca Initial load
duke
parents:
diff changeset
   211
     */
474761f14bca Initial load
duke
parents:
diff changeset
   212
    public JVar varParam(JType type, String name) {
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   213
                if (!hasVarArgs()) {
8
474761f14bca Initial load
duke
parents:
diff changeset
   214
474761f14bca Initial load
duke
parents:
diff changeset
   215
            varParam =
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   216
                                new JVar(
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   217
                                        JMods.forVar(JMod.NONE),
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   218
                                        type.array(),
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   219
                                        name,
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   220
                                        null);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   221
                        return varParam;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   222
                } else {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   223
                        throw new IllegalStateException(
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   224
                                "Cannot have two varargs in a method,\n"
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   225
                                        + "Check if varParam method of JMethod is"
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   226
                                        + " invoked more than once");
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   227
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   228
                }
8
474761f14bca Initial load
duke
parents:
diff changeset
   229
474761f14bca Initial load
duke
parents:
diff changeset
   230
        }
474761f14bca Initial load
duke
parents:
diff changeset
   231
474761f14bca Initial load
duke
parents:
diff changeset
   232
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   233
     * Adds an annotation to this variable.
474761f14bca Initial load
duke
parents:
diff changeset
   234
     * @param clazz
474761f14bca Initial load
duke
parents:
diff changeset
   235
     *          The annotation class to annotate the field with
474761f14bca Initial load
duke
parents:
diff changeset
   236
     */
474761f14bca Initial load
duke
parents:
diff changeset
   237
    public JAnnotationUse annotate(JClass clazz){
474761f14bca Initial load
duke
parents:
diff changeset
   238
        if(annotations==null)
474761f14bca Initial load
duke
parents:
diff changeset
   239
           annotations = new ArrayList<JAnnotationUse>();
474761f14bca Initial load
duke
parents:
diff changeset
   240
        JAnnotationUse a = new JAnnotationUse(clazz);
474761f14bca Initial load
duke
parents:
diff changeset
   241
        annotations.add(a);
474761f14bca Initial load
duke
parents:
diff changeset
   242
        return a;
474761f14bca Initial load
duke
parents:
diff changeset
   243
    }
474761f14bca Initial load
duke
parents:
diff changeset
   244
474761f14bca Initial load
duke
parents:
diff changeset
   245
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   246
     * Adds an annotation to this variable.
474761f14bca Initial load
duke
parents:
diff changeset
   247
     *
474761f14bca Initial load
duke
parents:
diff changeset
   248
     * @param clazz
474761f14bca Initial load
duke
parents:
diff changeset
   249
     *          The annotation class to annotate the field with
474761f14bca Initial load
duke
parents:
diff changeset
   250
     */
474761f14bca Initial load
duke
parents:
diff changeset
   251
    public JAnnotationUse annotate(Class <? extends Annotation> clazz){
474761f14bca Initial load
duke
parents:
diff changeset
   252
        return annotate(owner().ref(clazz));
474761f14bca Initial load
duke
parents:
diff changeset
   253
    }
474761f14bca Initial load
duke
parents:
diff changeset
   254
474761f14bca Initial load
duke
parents:
diff changeset
   255
    public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) {
474761f14bca Initial load
duke
parents:
diff changeset
   256
        return TypedAnnotationWriter.create(clazz,this);
474761f14bca Initial load
duke
parents:
diff changeset
   257
    }
474761f14bca Initial load
duke
parents:
diff changeset
   258
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   259
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   260
         * Check if there are any varargs declared
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   261
         * for this method signature.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   262
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   263
        public boolean hasVarArgs() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   264
                return this.varParam!=null;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   265
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   266
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   267
        public String name() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   268
                return name;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   269
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   270
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   271
    /**
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   272
     * Changes the name of the method.
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   273
     */
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   274
    public void name(String n) {
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   275
        this.name = n;
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   276
    }
8
474761f14bca Initial load
duke
parents:
diff changeset
   277
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   278
    /**
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   279
         * Returns the return type.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   280
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   281
        public JType type() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   282
                return type;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   283
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   284
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   285
    /**
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   286
     * Overrides the return type.
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   287
     */
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   288
    public void type(JType t) {
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   289
        this.type = t;
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   290
    }
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   291
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   292
    /**
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   293
         * Returns all the parameter types in an array.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   294
         * @return
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   295
         *      If there's no parameter, an empty array will be returned.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   296
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   297
        public JType[] listParamTypes() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   298
                JType[] r = new JType[params.size()];
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   299
                for (int i = 0; i < r.length; i++)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   300
                        r[i] = params.get(i).type();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   301
                return r;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   302
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   303
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   304
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   305
         * Returns  the varags parameter type.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   306
         * @return
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   307
         * If there's no vararg parameter type, null will be returned.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   308
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   309
        public JType listVarParamType() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   310
                if (varParam != null)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   311
                        return varParam.type();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   312
                else
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   313
                        return null;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   314
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   315
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   316
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   317
         * Returns all the parameters in an array.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   318
         * @return
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   319
         *      If there's no parameter, an empty array will be returned.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   320
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   321
        public JVar[] listParams() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   322
                return params.toArray(new JVar[params.size()]);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   323
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   324
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   325
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   326
         * Returns the variable parameter
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   327
         * @return
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   328
         *      If there's no parameter, null will be returned.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   329
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   330
        public JVar listVarParam() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   331
                return varParam;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   332
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   333
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   334
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   335
         * Returns true if the method has the specified signature.
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   336
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   337
        public boolean hasSignature(JType[] argTypes) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   338
                JVar[] p = listParams();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   339
                if (p.length != argTypes.length)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   340
                        return false;
8
474761f14bca Initial load
duke
parents:
diff changeset
   341
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   342
                for (int i = 0; i < p.length; i++)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   343
                        if (!p[i].type().equals(argTypes[i]))
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   344
                                return false;
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   345
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   346
                return true;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   347
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   348
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   349
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   350
         * Get the block that makes up body of this method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   351
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   352
         * @return Body of method
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   353
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   354
        public JBlock body() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   355
                if (body == null)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   356
                        body = new JBlock();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   357
                return body;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   358
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   359
474761f14bca Initial load
duke
parents:
diff changeset
   360
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   361
     * Specify the default value for this annotation member
474761f14bca Initial load
duke
parents:
diff changeset
   362
     * @param value
474761f14bca Initial load
duke
parents:
diff changeset
   363
     *           Default value for the annotation member
474761f14bca Initial load
duke
parents:
diff changeset
   364
     *
474761f14bca Initial load
duke
parents:
diff changeset
   365
     */
474761f14bca Initial load
duke
parents:
diff changeset
   366
    public void declareDefaultValue(JExpression value){
474761f14bca Initial load
duke
parents:
diff changeset
   367
        this.defaultValue = value;
474761f14bca Initial load
duke
parents:
diff changeset
   368
    }
474761f14bca Initial load
duke
parents:
diff changeset
   369
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   370
        /**
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   371
         * Creates, if necessary, and returns the class javadoc for this
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   372
         * JDefinedClass
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   373
         *
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   374
         * @return JDocComment containing javadocs for this class
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   375
         */
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   376
        public JDocComment javadoc() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   377
                if (jdoc == null)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   378
                        jdoc = new JDocComment(owner());
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   379
                return jdoc;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   380
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   381
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   382
        public void declare(JFormatter f) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   383
                if (jdoc != null)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   384
                        f.g(jdoc);
8
474761f14bca Initial load
duke
parents:
diff changeset
   385
474761f14bca Initial load
duke
parents:
diff changeset
   386
        if (annotations != null){
474761f14bca Initial load
duke
parents:
diff changeset
   387
            for (JAnnotationUse a : annotations)
474761f14bca Initial load
duke
parents:
diff changeset
   388
                f.g(a).nl();
474761f14bca Initial load
duke
parents:
diff changeset
   389
        }
474761f14bca Initial load
duke
parents:
diff changeset
   390
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   391
                // declare the generics parameters
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   392
                super.declare(f);
8
474761f14bca Initial load
duke
parents:
diff changeset
   393
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   394
                f.g(mods);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   395
                if (!isConstructor())
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   396
                        f.g(type);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   397
                f.id(name).p('(').i();
8
474761f14bca Initial load
duke
parents:
diff changeset
   398
        // when parameters are printed in new lines, we want them to be indented.
474761f14bca Initial load
duke
parents:
diff changeset
   399
        // there's a good chance no newlines happen, too, but just in case it does.
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   400
                boolean first = true;
8
474761f14bca Initial load
duke
parents:
diff changeset
   401
        for (JVar var : params) {
474761f14bca Initial load
duke
parents:
diff changeset
   402
            if (!first)
474761f14bca Initial load
duke
parents:
diff changeset
   403
                f.p(',');
474761f14bca Initial load
duke
parents:
diff changeset
   404
            if(var.isAnnotated())
474761f14bca Initial load
duke
parents:
diff changeset
   405
                f.nl();
474761f14bca Initial load
duke
parents:
diff changeset
   406
            f.b(var);
474761f14bca Initial load
duke
parents:
diff changeset
   407
            first = false;
474761f14bca Initial load
duke
parents:
diff changeset
   408
        }
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   409
                if (hasVarArgs()) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   410
                        if (!first)
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   411
                                f.p(',');
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   412
                        f.g(varParam.type().elementType());
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   413
                        f.p("... ");
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   414
                        f.id(varParam.name());
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   415
                }
8
474761f14bca Initial load
duke
parents:
diff changeset
   416
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   417
                f.o().p(')');
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   418
                if (_throws!=null && !_throws.isEmpty()) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   419
                        f.nl().i().p("throws").g(_throws).nl().o();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   420
                }
8
474761f14bca Initial load
duke
parents:
diff changeset
   421
474761f14bca Initial load
duke
parents:
diff changeset
   422
        if (defaultValue != null) {
474761f14bca Initial load
duke
parents:
diff changeset
   423
            f.p("default ");
474761f14bca Initial load
duke
parents:
diff changeset
   424
            f.g(defaultValue);
474761f14bca Initial load
duke
parents:
diff changeset
   425
        }
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   426
                if (body != null) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   427
                        f.s(body);
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   428
                } else if (
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   429
                        !outer.isInterface() && !outer.isAnnotationTypeDeclaration() && !mods.isAbstract() && !mods.isNative()) {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   430
                        // Print an empty body for non-native, non-abstract methods
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   431
                        f.s(new JBlock());
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   432
                } else {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   433
                        f.p(';').nl();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   434
                }
8
474761f14bca Initial load
duke
parents:
diff changeset
   435
        }
474761f14bca Initial load
duke
parents:
diff changeset
   436
474761f14bca Initial load
duke
parents:
diff changeset
   437
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   438
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   439
     *      the current modifiers of this method.
474761f14bca Initial load
duke
parents:
diff changeset
   440
     *      Always return non-null valid object.
474761f14bca Initial load
duke
parents:
diff changeset
   441
     */
474761f14bca Initial load
duke
parents:
diff changeset
   442
    public JMods mods() {
474761f14bca Initial load
duke
parents:
diff changeset
   443
        return mods;
474761f14bca Initial load
duke
parents:
diff changeset
   444
    }
474761f14bca Initial load
duke
parents:
diff changeset
   445
474761f14bca Initial load
duke
parents:
diff changeset
   446
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   447
     * @deprecated use {@link #mods()}
474761f14bca Initial load
duke
parents:
diff changeset
   448
     */
474761f14bca Initial load
duke
parents:
diff changeset
   449
    public JMods getMods() {
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   450
                return mods;
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   451
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   452
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   453
        protected JCodeModel owner() {
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   454
                return outer.owner();
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   455
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   456
}