jaxws/src/share/classes/com/sun/codemodel/internal/JDefinedClass.java
author tbell
Mon, 04 May 2009 21:10:41 -0700
changeset 2719 99d59312294b
parent 2678 57cf2a1c1a05
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.Collection;
474761f14bca Initial load
duke
parents:
diff changeset
    31
import java.util.Collections;
474761f14bca Initial load
duke
parents:
diff changeset
    32
import java.util.Iterator;
474761f14bca Initial load
duke
parents:
diff changeset
    33
import java.util.LinkedHashMap;
474761f14bca Initial load
duke
parents:
diff changeset
    34
import java.util.List;
474761f14bca Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
474761f14bca Initial load
duke
parents:
diff changeset
    36
import java.util.Set;
474761f14bca Initial load
duke
parents:
diff changeset
    37
import java.util.TreeMap;
474761f14bca Initial load
duke
parents:
diff changeset
    38
import java.util.TreeSet;
474761f14bca Initial load
duke
parents:
diff changeset
    39
474761f14bca Initial load
duke
parents:
diff changeset
    40
/**
474761f14bca Initial load
duke
parents:
diff changeset
    41
 * A generated Java class/interface/enum/....
474761f14bca Initial load
duke
parents:
diff changeset
    42
 *
474761f14bca Initial load
duke
parents:
diff changeset
    43
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    44
 * This class models a declaration, and since a declaration can be always
474761f14bca Initial load
duke
parents:
diff changeset
    45
 * used as a reference, it inherits {@link JClass}.
474761f14bca Initial load
duke
parents:
diff changeset
    46
 *
474761f14bca Initial load
duke
parents:
diff changeset
    47
 * <h2>Where to go from here?</h2>
474761f14bca Initial load
duke
parents:
diff changeset
    48
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    49
 * You'd want to generate fields and methods on a class.
474761f14bca Initial load
duke
parents:
diff changeset
    50
 * See {@link #method(int, JType, String)} and {@link #field(int, JType, String)}.
474761f14bca Initial load
duke
parents:
diff changeset
    51
 */
474761f14bca Initial load
duke
parents:
diff changeset
    52
public class JDefinedClass
474761f14bca Initial load
duke
parents:
diff changeset
    53
    extends JClass
474761f14bca Initial load
duke
parents:
diff changeset
    54
    implements JDeclaration, JClassContainer, JGenerifiable, JAnnotatable {
474761f14bca Initial load
duke
parents:
diff changeset
    55
474761f14bca Initial load
duke
parents:
diff changeset
    56
    /** Name of this class. Null if anonymous. */
474761f14bca Initial load
duke
parents:
diff changeset
    57
    private String name = null;
474761f14bca Initial load
duke
parents:
diff changeset
    58
474761f14bca Initial load
duke
parents:
diff changeset
    59
474761f14bca Initial load
duke
parents:
diff changeset
    60
    /** Modifiers for the class declaration */
474761f14bca Initial load
duke
parents:
diff changeset
    61
    private JMods mods;
474761f14bca Initial load
duke
parents:
diff changeset
    62
474761f14bca Initial load
duke
parents:
diff changeset
    63
    /** Name of the super class of this class. */
474761f14bca Initial load
duke
parents:
diff changeset
    64
    private JClass superClass;
474761f14bca Initial load
duke
parents:
diff changeset
    65
474761f14bca Initial load
duke
parents:
diff changeset
    66
    /** List of interfaces that this class implements */
474761f14bca Initial load
duke
parents:
diff changeset
    67
    private final Set<JClass> interfaces = new TreeSet<JClass>();
474761f14bca Initial load
duke
parents:
diff changeset
    68
474761f14bca Initial load
duke
parents:
diff changeset
    69
    /** Fields keyed by their names. */
474761f14bca Initial load
duke
parents:
diff changeset
    70
    /*package*/ final Map<String,JFieldVar> fields = new LinkedHashMap<String,JFieldVar>();
474761f14bca Initial load
duke
parents:
diff changeset
    71
474761f14bca Initial load
duke
parents:
diff changeset
    72
    /** Static initializer, if this class has one */
474761f14bca Initial load
duke
parents:
diff changeset
    73
    private JBlock init = null;
474761f14bca Initial load
duke
parents:
diff changeset
    74
474761f14bca Initial load
duke
parents:
diff changeset
    75
    /** class javadoc */
474761f14bca Initial load
duke
parents:
diff changeset
    76
    private JDocComment jdoc = null;
474761f14bca Initial load
duke
parents:
diff changeset
    77
474761f14bca Initial load
duke
parents:
diff changeset
    78
    /** Set of constructors for this class, if any */
474761f14bca Initial load
duke
parents:
diff changeset
    79
    private final List<JMethod> constructors = new ArrayList<JMethod>();
474761f14bca Initial load
duke
parents:
diff changeset
    80
474761f14bca Initial load
duke
parents:
diff changeset
    81
    /** Set of methods that are members of this class */
474761f14bca Initial load
duke
parents:
diff changeset
    82
    private final List<JMethod> methods = new ArrayList<JMethod>();
474761f14bca Initial load
duke
parents:
diff changeset
    83
474761f14bca Initial load
duke
parents:
diff changeset
    84
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    85
     * Nested classes as a map from name to JDefinedClass.
474761f14bca Initial load
duke
parents:
diff changeset
    86
     * The name is all capitalized in a case sensitive file system
474761f14bca Initial load
duke
parents:
diff changeset
    87
     * ({@link JCodeModel#isCaseSensitiveFileSystem}) to avoid conflicts.
474761f14bca Initial load
duke
parents:
diff changeset
    88
     *
474761f14bca Initial load
duke
parents:
diff changeset
    89
     * Lazily created to save footprint.
474761f14bca Initial load
duke
parents:
diff changeset
    90
     *
474761f14bca Initial load
duke
parents:
diff changeset
    91
     * @see #getClasses()
474761f14bca Initial load
duke
parents:
diff changeset
    92
     */
474761f14bca Initial load
duke
parents:
diff changeset
    93
    private Map<String,JDefinedClass> classes;
474761f14bca Initial load
duke
parents:
diff changeset
    94
474761f14bca Initial load
duke
parents:
diff changeset
    95
474761f14bca Initial load
duke
parents:
diff changeset
    96
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    97
     * Flag that controls whether this class should be really generated or not.
474761f14bca Initial load
duke
parents:
diff changeset
    98
     *
474761f14bca Initial load
duke
parents:
diff changeset
    99
     * Sometimes it is useful to generate code that refers to class X,
474761f14bca Initial load
duke
parents:
diff changeset
   100
     * without actually generating the code of X.
474761f14bca Initial load
duke
parents:
diff changeset
   101
     * This flag is used to surpress X.java file in the output.
474761f14bca Initial load
duke
parents:
diff changeset
   102
     */
474761f14bca Initial load
duke
parents:
diff changeset
   103
    private boolean hideFile = false;
474761f14bca Initial load
duke
parents:
diff changeset
   104
474761f14bca Initial load
duke
parents:
diff changeset
   105
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   106
     * Client-app spcific metadata associated with this user-created class.
474761f14bca Initial load
duke
parents:
diff changeset
   107
     */
474761f14bca Initial load
duke
parents:
diff changeset
   108
    public Object metadata;
474761f14bca Initial load
duke
parents:
diff changeset
   109
474761f14bca Initial load
duke
parents:
diff changeset
   110
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   111
     * String that will be put directly inside the generated code.
474761f14bca Initial load
duke
parents:
diff changeset
   112
     * Can be null.
474761f14bca Initial load
duke
parents:
diff changeset
   113
     */
474761f14bca Initial load
duke
parents:
diff changeset
   114
    private String directBlock;
474761f14bca Initial load
duke
parents:
diff changeset
   115
474761f14bca Initial load
duke
parents:
diff changeset
   116
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   117
     * If this is a package-member class, this is {@link JPackage}.
474761f14bca Initial load
duke
parents:
diff changeset
   118
     * If this is a nested class, this is {@link JDefinedClass}.
474761f14bca Initial load
duke
parents:
diff changeset
   119
     * If this is an anonymous class, this constructor shouldn't be used.
474761f14bca Initial load
duke
parents:
diff changeset
   120
     */
474761f14bca Initial load
duke
parents:
diff changeset
   121
    private JClassContainer outer = null;
474761f14bca Initial load
duke
parents:
diff changeset
   122
474761f14bca Initial load
duke
parents:
diff changeset
   123
474761f14bca Initial load
duke
parents:
diff changeset
   124
    /** Default value is class or interface
474761f14bca Initial load
duke
parents:
diff changeset
   125
     *  or annotationTypeDeclaration
474761f14bca Initial load
duke
parents:
diff changeset
   126
     *  or enum
474761f14bca Initial load
duke
parents:
diff changeset
   127
     *
474761f14bca Initial load
duke
parents:
diff changeset
   128
     */
474761f14bca Initial load
duke
parents:
diff changeset
   129
    private final ClassType classType;
474761f14bca Initial load
duke
parents:
diff changeset
   130
474761f14bca Initial load
duke
parents:
diff changeset
   131
    /** List containing the enum value declarations
474761f14bca Initial load
duke
parents:
diff changeset
   132
     *
474761f14bca Initial load
duke
parents:
diff changeset
   133
     */
474761f14bca Initial load
duke
parents:
diff changeset
   134
//    private List enumValues = new ArrayList();
474761f14bca Initial load
duke
parents:
diff changeset
   135
474761f14bca Initial load
duke
parents:
diff changeset
   136
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   137
     * Set of enum constants that are keyed by names.
474761f14bca Initial load
duke
parents:
diff changeset
   138
     * In Java, enum constant order is actually significant,
474761f14bca Initial load
duke
parents:
diff changeset
   139
     * because of order ID they get. So let's preserve the order.
474761f14bca Initial load
duke
parents:
diff changeset
   140
     */
474761f14bca Initial load
duke
parents:
diff changeset
   141
    private final Map<String,JEnumConstant> enumConstantsByName = new LinkedHashMap<String,JEnumConstant>();
474761f14bca Initial load
duke
parents:
diff changeset
   142
474761f14bca Initial load
duke
parents:
diff changeset
   143
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   144
     * Annotations on this variable. Lazily created.
474761f14bca Initial load
duke
parents:
diff changeset
   145
     */
474761f14bca Initial load
duke
parents:
diff changeset
   146
    private List<JAnnotationUse> annotations = null;
474761f14bca Initial load
duke
parents:
diff changeset
   147
474761f14bca Initial load
duke
parents:
diff changeset
   148
474761f14bca Initial load
duke
parents:
diff changeset
   149
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   150
     * Helper class to implement {@link JGenerifiable}.
474761f14bca Initial load
duke
parents:
diff changeset
   151
     */
474761f14bca Initial load
duke
parents:
diff changeset
   152
    private final JGenerifiableImpl generifiable = new JGenerifiableImpl() {
474761f14bca Initial load
duke
parents:
diff changeset
   153
        protected JCodeModel owner() {
474761f14bca Initial load
duke
parents:
diff changeset
   154
            return JDefinedClass.this.owner();
474761f14bca Initial load
duke
parents:
diff changeset
   155
        }
474761f14bca Initial load
duke
parents:
diff changeset
   156
    };
474761f14bca Initial load
duke
parents:
diff changeset
   157
474761f14bca Initial load
duke
parents:
diff changeset
   158
    JDefinedClass(JClassContainer parent, int mods, String name, ClassType classTypeval) {
474761f14bca Initial load
duke
parents:
diff changeset
   159
        this(mods, name, parent, parent.owner(), classTypeval);
474761f14bca Initial load
duke
parents:
diff changeset
   160
    }
474761f14bca Initial load
duke
parents:
diff changeset
   161
474761f14bca Initial load
duke
parents:
diff changeset
   162
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   163
     * Constructor for creating anonymous inner class.
474761f14bca Initial load
duke
parents:
diff changeset
   164
     */
474761f14bca Initial load
duke
parents:
diff changeset
   165
    JDefinedClass(
474761f14bca Initial load
duke
parents:
diff changeset
   166
        JCodeModel owner,
474761f14bca Initial load
duke
parents:
diff changeset
   167
        int mods,
474761f14bca Initial load
duke
parents:
diff changeset
   168
        String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   169
        this(mods, name, null, owner);
474761f14bca Initial load
duke
parents:
diff changeset
   170
    }
474761f14bca Initial load
duke
parents:
diff changeset
   171
474761f14bca Initial load
duke
parents:
diff changeset
   172
    private JDefinedClass(
474761f14bca Initial load
duke
parents:
diff changeset
   173
            int mods,
474761f14bca Initial load
duke
parents:
diff changeset
   174
            String name,
474761f14bca Initial load
duke
parents:
diff changeset
   175
            JClassContainer parent,
474761f14bca Initial load
duke
parents:
diff changeset
   176
            JCodeModel owner) {
474761f14bca Initial load
duke
parents:
diff changeset
   177
        this (mods,name,parent,owner,ClassType.CLASS);
474761f14bca Initial load
duke
parents:
diff changeset
   178
    }
474761f14bca Initial load
duke
parents:
diff changeset
   179
474761f14bca Initial load
duke
parents:
diff changeset
   180
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   181
     * JClass constructor
474761f14bca Initial load
duke
parents:
diff changeset
   182
     *
474761f14bca Initial load
duke
parents:
diff changeset
   183
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   184
     *        Modifiers for this class declaration
474761f14bca Initial load
duke
parents:
diff changeset
   185
     *
474761f14bca Initial load
duke
parents:
diff changeset
   186
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   187
     *        Name of this class
474761f14bca Initial load
duke
parents:
diff changeset
   188
     */
474761f14bca Initial load
duke
parents:
diff changeset
   189
    private JDefinedClass(
474761f14bca Initial load
duke
parents:
diff changeset
   190
        int mods,
474761f14bca Initial load
duke
parents:
diff changeset
   191
        String name,
474761f14bca Initial load
duke
parents:
diff changeset
   192
        JClassContainer parent,
474761f14bca Initial load
duke
parents:
diff changeset
   193
        JCodeModel owner,
474761f14bca Initial load
duke
parents:
diff changeset
   194
                ClassType classTypeVal) {
474761f14bca Initial load
duke
parents:
diff changeset
   195
        super(owner);
474761f14bca Initial load
duke
parents:
diff changeset
   196
474761f14bca Initial load
duke
parents:
diff changeset
   197
        if(name!=null) {
474761f14bca Initial load
duke
parents:
diff changeset
   198
            if (name.trim().length() == 0)
474761f14bca Initial load
duke
parents:
diff changeset
   199
                throw new IllegalArgumentException("JClass name empty");
474761f14bca Initial load
duke
parents:
diff changeset
   200
474761f14bca Initial load
duke
parents:
diff changeset
   201
            if (!Character.isJavaIdentifierStart(name.charAt(0))) {
474761f14bca Initial load
duke
parents:
diff changeset
   202
                String msg =
474761f14bca Initial load
duke
parents:
diff changeset
   203
                    "JClass name "
474761f14bca Initial load
duke
parents:
diff changeset
   204
                        + name
474761f14bca Initial load
duke
parents:
diff changeset
   205
                        + " contains illegal character"
474761f14bca Initial load
duke
parents:
diff changeset
   206
                        + " for beginning of identifier: "
474761f14bca Initial load
duke
parents:
diff changeset
   207
                        + name.charAt(0);
474761f14bca Initial load
duke
parents:
diff changeset
   208
                throw new IllegalArgumentException(msg);
474761f14bca Initial load
duke
parents:
diff changeset
   209
            }
474761f14bca Initial load
duke
parents:
diff changeset
   210
            for (int i = 1; i < name.length(); i++) {
474761f14bca Initial load
duke
parents:
diff changeset
   211
                if (!Character.isJavaIdentifierPart(name.charAt(i))) {
474761f14bca Initial load
duke
parents:
diff changeset
   212
                    String msg =
474761f14bca Initial load
duke
parents:
diff changeset
   213
                        "JClass name "
474761f14bca Initial load
duke
parents:
diff changeset
   214
                            + name
474761f14bca Initial load
duke
parents:
diff changeset
   215
                            + " contains illegal character "
474761f14bca Initial load
duke
parents:
diff changeset
   216
                            + name.charAt(i);
474761f14bca Initial load
duke
parents:
diff changeset
   217
                    throw new IllegalArgumentException(msg);
474761f14bca Initial load
duke
parents:
diff changeset
   218
                }
474761f14bca Initial load
duke
parents:
diff changeset
   219
            }
474761f14bca Initial load
duke
parents:
diff changeset
   220
        }
474761f14bca Initial load
duke
parents:
diff changeset
   221
474761f14bca Initial load
duke
parents:
diff changeset
   222
        this.classType = classTypeVal;
474761f14bca Initial load
duke
parents:
diff changeset
   223
        if (isInterface())
474761f14bca Initial load
duke
parents:
diff changeset
   224
            this.mods = JMods.forInterface(mods);
474761f14bca Initial load
duke
parents:
diff changeset
   225
        else
474761f14bca Initial load
duke
parents:
diff changeset
   226
            this.mods = JMods.forClass(mods);
474761f14bca Initial load
duke
parents:
diff changeset
   227
474761f14bca Initial load
duke
parents:
diff changeset
   228
        this.name = name;
474761f14bca Initial load
duke
parents:
diff changeset
   229
474761f14bca Initial load
duke
parents:
diff changeset
   230
        this.outer = parent;
474761f14bca Initial load
duke
parents:
diff changeset
   231
    }
474761f14bca Initial load
duke
parents:
diff changeset
   232
474761f14bca Initial load
duke
parents:
diff changeset
   233
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   234
     * Returns true if this is an anonymous class.
474761f14bca Initial load
duke
parents:
diff changeset
   235
     */
474761f14bca Initial load
duke
parents:
diff changeset
   236
    public final boolean isAnonymous() {
474761f14bca Initial load
duke
parents:
diff changeset
   237
        return name == null;
474761f14bca Initial load
duke
parents:
diff changeset
   238
    }
474761f14bca Initial load
duke
parents:
diff changeset
   239
474761f14bca Initial load
duke
parents:
diff changeset
   240
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   241
     * This class extends the specifed class.
474761f14bca Initial load
duke
parents:
diff changeset
   242
     *
474761f14bca Initial load
duke
parents:
diff changeset
   243
     * @param superClass
474761f14bca Initial load
duke
parents:
diff changeset
   244
     *        Superclass for this class
474761f14bca Initial load
duke
parents:
diff changeset
   245
     *
474761f14bca Initial load
duke
parents:
diff changeset
   246
     * @return This class
474761f14bca Initial load
duke
parents:
diff changeset
   247
     */
474761f14bca Initial load
duke
parents:
diff changeset
   248
    public JDefinedClass _extends(JClass superClass) {
474761f14bca Initial load
duke
parents:
diff changeset
   249
        if (this.classType==ClassType.INTERFACE)
474761f14bca Initial load
duke
parents:
diff changeset
   250
            throw new IllegalArgumentException("unable to set the super class for an interface");
474761f14bca Initial load
duke
parents:
diff changeset
   251
        if (superClass == null)
474761f14bca Initial load
duke
parents:
diff changeset
   252
            throw new NullPointerException();
474761f14bca Initial load
duke
parents:
diff changeset
   253
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   254
        for( JClass o=superClass.outer(); o!=null; o=o.outer() ){
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   255
            if(this==o){
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   256
                throw new IllegalArgumentException("Illegal class inheritance loop." +
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   257
                "  Outer class " + this.name + " may not subclass from inner class: " + o.name());
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   258
            }
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   259
        }
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   260
8
474761f14bca Initial load
duke
parents:
diff changeset
   261
        this.superClass = superClass;
474761f14bca Initial load
duke
parents:
diff changeset
   262
        return this;
474761f14bca Initial load
duke
parents:
diff changeset
   263
    }
474761f14bca Initial load
duke
parents:
diff changeset
   264
474761f14bca Initial load
duke
parents:
diff changeset
   265
    public JDefinedClass _extends(Class superClass) {
474761f14bca Initial load
duke
parents:
diff changeset
   266
        return _extends(owner().ref(superClass));
474761f14bca Initial load
duke
parents:
diff changeset
   267
    }
474761f14bca Initial load
duke
parents:
diff changeset
   268
474761f14bca Initial load
duke
parents:
diff changeset
   269
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   270
     * Returns the class extended by this class.
474761f14bca Initial load
duke
parents:
diff changeset
   271
     */
474761f14bca Initial load
duke
parents:
diff changeset
   272
    public JClass _extends() {
474761f14bca Initial load
duke
parents:
diff changeset
   273
        if(superClass==null)
474761f14bca Initial load
duke
parents:
diff changeset
   274
            superClass = owner().ref(Object.class);
474761f14bca Initial load
duke
parents:
diff changeset
   275
        return superClass;
474761f14bca Initial load
duke
parents:
diff changeset
   276
    }
474761f14bca Initial load
duke
parents:
diff changeset
   277
474761f14bca Initial load
duke
parents:
diff changeset
   278
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   279
     * This class implements the specifed interface.
474761f14bca Initial load
duke
parents:
diff changeset
   280
     *
474761f14bca Initial load
duke
parents:
diff changeset
   281
     * @param iface
474761f14bca Initial load
duke
parents:
diff changeset
   282
     *        Interface that this class implements
474761f14bca Initial load
duke
parents:
diff changeset
   283
     *
474761f14bca Initial load
duke
parents:
diff changeset
   284
     * @return This class
474761f14bca Initial load
duke
parents:
diff changeset
   285
     */
474761f14bca Initial load
duke
parents:
diff changeset
   286
    public JDefinedClass _implements(JClass iface) {
474761f14bca Initial load
duke
parents:
diff changeset
   287
        interfaces.add(iface);
474761f14bca Initial load
duke
parents:
diff changeset
   288
        return this;
474761f14bca Initial load
duke
parents:
diff changeset
   289
    }
474761f14bca Initial load
duke
parents:
diff changeset
   290
474761f14bca Initial load
duke
parents:
diff changeset
   291
    public JDefinedClass _implements(Class iface) {
474761f14bca Initial load
duke
parents:
diff changeset
   292
        return _implements(owner().ref(iface));
474761f14bca Initial load
duke
parents:
diff changeset
   293
    }
474761f14bca Initial load
duke
parents:
diff changeset
   294
474761f14bca Initial load
duke
parents:
diff changeset
   295
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   296
     * Returns an iterator that walks the nested classes defined in this
474761f14bca Initial load
duke
parents:
diff changeset
   297
     * class.
474761f14bca Initial load
duke
parents:
diff changeset
   298
     */
474761f14bca Initial load
duke
parents:
diff changeset
   299
    public Iterator<JClass> _implements() {
474761f14bca Initial load
duke
parents:
diff changeset
   300
        return interfaces.iterator();
474761f14bca Initial load
duke
parents:
diff changeset
   301
    }
474761f14bca Initial load
duke
parents:
diff changeset
   302
474761f14bca Initial load
duke
parents:
diff changeset
   303
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   304
     * JClass name accessor.
474761f14bca Initial load
duke
parents:
diff changeset
   305
     *
474761f14bca Initial load
duke
parents:
diff changeset
   306
     * <p>
474761f14bca Initial load
duke
parents:
diff changeset
   307
     * For example, for <code>java.util.List</code>, this method
474761f14bca Initial load
duke
parents:
diff changeset
   308
     * returns <code>"List"</code>"
474761f14bca Initial load
duke
parents:
diff changeset
   309
     *
474761f14bca Initial load
duke
parents:
diff changeset
   310
     * @return Name of this class
474761f14bca Initial load
duke
parents:
diff changeset
   311
     */
474761f14bca Initial load
duke
parents:
diff changeset
   312
    public String name() {
474761f14bca Initial load
duke
parents:
diff changeset
   313
        return name;
474761f14bca Initial load
duke
parents:
diff changeset
   314
    }
474761f14bca Initial load
duke
parents:
diff changeset
   315
474761f14bca Initial load
duke
parents:
diff changeset
   316
    /**
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   317
     * If the named enum already exists, the reference to it is returned.
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   318
     * Otherwise this method generates a new enum reference with the given
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   319
     * name and returns it.
8
474761f14bca Initial load
duke
parents:
diff changeset
   320
     *
474761f14bca Initial load
duke
parents:
diff changeset
   321
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   322
     *          The name of the constant.
474761f14bca Initial load
duke
parents:
diff changeset
   323
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   324
     *      The generated type-safe enum constant.
474761f14bca Initial load
duke
parents:
diff changeset
   325
     */
474761f14bca Initial load
duke
parents:
diff changeset
   326
    public JEnumConstant enumConstant(String name){
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   327
        JEnumConstant ec = enumConstantsByName.get(name);
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   328
        if (null == ec) {
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   329
            ec = new JEnumConstant(this, name);
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   330
            enumConstantsByName.put(name, ec);
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   331
        }
8
474761f14bca Initial load
duke
parents:
diff changeset
   332
        return ec;
474761f14bca Initial load
duke
parents:
diff changeset
   333
    }
474761f14bca Initial load
duke
parents:
diff changeset
   334
474761f14bca Initial load
duke
parents:
diff changeset
   335
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   336
     * Gets the fully qualified name of this class.
474761f14bca Initial load
duke
parents:
diff changeset
   337
     */
474761f14bca Initial load
duke
parents:
diff changeset
   338
    public String fullName() {
474761f14bca Initial load
duke
parents:
diff changeset
   339
        if (outer instanceof JDefinedClass)
474761f14bca Initial load
duke
parents:
diff changeset
   340
            return ((JDefinedClass) outer).fullName() + '.' + name();
474761f14bca Initial load
duke
parents:
diff changeset
   341
474761f14bca Initial load
duke
parents:
diff changeset
   342
        JPackage p = _package();
474761f14bca Initial load
duke
parents:
diff changeset
   343
        if (p.isUnnamed())
474761f14bca Initial load
duke
parents:
diff changeset
   344
            return name();
474761f14bca Initial load
duke
parents:
diff changeset
   345
        else
474761f14bca Initial load
duke
parents:
diff changeset
   346
            return p.name() + '.' + name();
474761f14bca Initial load
duke
parents:
diff changeset
   347
    }
474761f14bca Initial load
duke
parents:
diff changeset
   348
474761f14bca Initial load
duke
parents:
diff changeset
   349
    public String binaryName() {
474761f14bca Initial load
duke
parents:
diff changeset
   350
        if (outer instanceof JDefinedClass)
474761f14bca Initial load
duke
parents:
diff changeset
   351
            return ((JDefinedClass) outer).binaryName() + '$' + name();
474761f14bca Initial load
duke
parents:
diff changeset
   352
        else
474761f14bca Initial load
duke
parents:
diff changeset
   353
            return fullName();
474761f14bca Initial load
duke
parents:
diff changeset
   354
    }
474761f14bca Initial load
duke
parents:
diff changeset
   355
474761f14bca Initial load
duke
parents:
diff changeset
   356
    public boolean isInterface() {
474761f14bca Initial load
duke
parents:
diff changeset
   357
        return this.classType==ClassType.INTERFACE;
474761f14bca Initial load
duke
parents:
diff changeset
   358
    }
474761f14bca Initial load
duke
parents:
diff changeset
   359
474761f14bca Initial load
duke
parents:
diff changeset
   360
    public boolean isAbstract() {
474761f14bca Initial load
duke
parents:
diff changeset
   361
        return mods.isAbstract();
474761f14bca Initial load
duke
parents:
diff changeset
   362
    }
474761f14bca Initial load
duke
parents:
diff changeset
   363
474761f14bca Initial load
duke
parents:
diff changeset
   364
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   365
     * Adds a field to the list of field members of this JDefinedClass.
474761f14bca Initial load
duke
parents:
diff changeset
   366
     *
474761f14bca Initial load
duke
parents:
diff changeset
   367
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   368
     *        Modifiers for this field
474761f14bca Initial load
duke
parents:
diff changeset
   369
     *
474761f14bca Initial load
duke
parents:
diff changeset
   370
     * @param type
474761f14bca Initial load
duke
parents:
diff changeset
   371
     *        JType of this field
474761f14bca Initial load
duke
parents:
diff changeset
   372
     *
474761f14bca Initial load
duke
parents:
diff changeset
   373
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   374
     *        Name of this field
474761f14bca Initial load
duke
parents:
diff changeset
   375
     *
474761f14bca Initial load
duke
parents:
diff changeset
   376
     * @return Newly generated field
474761f14bca Initial load
duke
parents:
diff changeset
   377
     */
474761f14bca Initial load
duke
parents:
diff changeset
   378
    public JFieldVar field(int mods, JType type, String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   379
        return field(mods, type, name, null);
474761f14bca Initial load
duke
parents:
diff changeset
   380
    }
474761f14bca Initial load
duke
parents:
diff changeset
   381
474761f14bca Initial load
duke
parents:
diff changeset
   382
    public JFieldVar field(int mods, Class type, String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   383
        return field(mods, owner()._ref(type), name);
474761f14bca Initial load
duke
parents:
diff changeset
   384
    }
474761f14bca Initial load
duke
parents:
diff changeset
   385
474761f14bca Initial load
duke
parents:
diff changeset
   386
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   387
     * Adds a field to the list of field members of this JDefinedClass.
474761f14bca Initial load
duke
parents:
diff changeset
   388
     *
474761f14bca Initial load
duke
parents:
diff changeset
   389
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   390
     *        Modifiers for this field.
474761f14bca Initial load
duke
parents:
diff changeset
   391
     * @param type
474761f14bca Initial load
duke
parents:
diff changeset
   392
     *        JType of this field.
474761f14bca Initial load
duke
parents:
diff changeset
   393
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   394
     *        Name of this field.
474761f14bca Initial load
duke
parents:
diff changeset
   395
     * @param init
474761f14bca Initial load
duke
parents:
diff changeset
   396
     *        Initial value of this field.
474761f14bca Initial load
duke
parents:
diff changeset
   397
     *
474761f14bca Initial load
duke
parents:
diff changeset
   398
     * @return Newly generated field
474761f14bca Initial load
duke
parents:
diff changeset
   399
     */
474761f14bca Initial load
duke
parents:
diff changeset
   400
    public JFieldVar field(
474761f14bca Initial load
duke
parents:
diff changeset
   401
        int mods,
474761f14bca Initial load
duke
parents:
diff changeset
   402
        JType type,
474761f14bca Initial load
duke
parents:
diff changeset
   403
        String name,
474761f14bca Initial load
duke
parents:
diff changeset
   404
        JExpression init) {
474761f14bca Initial load
duke
parents:
diff changeset
   405
        JFieldVar f = new JFieldVar(this,JMods.forField(mods), type, name, init);
474761f14bca Initial load
duke
parents:
diff changeset
   406
474761f14bca Initial load
duke
parents:
diff changeset
   407
        if(fields.put(name, f)!=null)
474761f14bca Initial load
duke
parents:
diff changeset
   408
            throw new IllegalArgumentException("trying to create the same field twice: "+name);
474761f14bca Initial load
duke
parents:
diff changeset
   409
474761f14bca Initial load
duke
parents:
diff changeset
   410
        return f;
474761f14bca Initial load
duke
parents:
diff changeset
   411
    }
474761f14bca Initial load
duke
parents:
diff changeset
   412
474761f14bca Initial load
duke
parents:
diff changeset
   413
    /**  This method indicates if the interface
474761f14bca Initial load
duke
parents:
diff changeset
   414
     *   is an annotationTypeDeclaration
474761f14bca Initial load
duke
parents:
diff changeset
   415
     *
474761f14bca Initial load
duke
parents:
diff changeset
   416
     */
474761f14bca Initial load
duke
parents:
diff changeset
   417
    public boolean isAnnotationTypeDeclaration() {
474761f14bca Initial load
duke
parents:
diff changeset
   418
        return this.classType==ClassType.ANNOTATION_TYPE_DECL;
474761f14bca Initial load
duke
parents:
diff changeset
   419
474761f14bca Initial load
duke
parents:
diff changeset
   420
474761f14bca Initial load
duke
parents:
diff changeset
   421
    }
474761f14bca Initial load
duke
parents:
diff changeset
   422
474761f14bca Initial load
duke
parents:
diff changeset
   423
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   424
     * Add an annotationType Declaration to this package
474761f14bca Initial load
duke
parents:
diff changeset
   425
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   426
     *      Name of the annotation Type declaration to be added to this package
474761f14bca Initial load
duke
parents:
diff changeset
   427
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   428
     *      newly created Annotation Type Declaration
474761f14bca Initial load
duke
parents:
diff changeset
   429
     * @exception JClassAlreadyExistsException
474761f14bca Initial load
duke
parents:
diff changeset
   430
     *      When the specified class/interface was already created.
2719
99d59312294b 6658158: Mutable statics in SAAJ (findbugs)
tbell
parents: 2678
diff changeset
   431
8
474761f14bca Initial load
duke
parents:
diff changeset
   432
     */
474761f14bca Initial load
duke
parents:
diff changeset
   433
    public JDefinedClass _annotationTypeDeclaration(String name) throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   434
        return _class (JMod.PUBLIC,name,ClassType.ANNOTATION_TYPE_DECL);
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
     * Add a public enum to this package
474761f14bca Initial load
duke
parents:
diff changeset
   439
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   440
     *      Name of the enum to be added to this package
474761f14bca Initial load
duke
parents:
diff changeset
   441
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   442
     *      newly created Enum
474761f14bca Initial load
duke
parents:
diff changeset
   443
     * @exception JClassAlreadyExistsException
474761f14bca Initial load
duke
parents:
diff changeset
   444
     *      When the specified class/interface was already created.
474761f14bca Initial load
duke
parents:
diff changeset
   445
474761f14bca Initial load
duke
parents:
diff changeset
   446
     */
474761f14bca Initial load
duke
parents:
diff changeset
   447
    public JDefinedClass _enum (String name) throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   448
        return _class (JMod.PUBLIC,name,ClassType.ENUM);
474761f14bca Initial load
duke
parents:
diff changeset
   449
    }
474761f14bca Initial load
duke
parents:
diff changeset
   450
474761f14bca Initial load
duke
parents:
diff changeset
   451
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   452
     * Add a public enum to this package
474761f14bca Initial load
duke
parents:
diff changeset
   453
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   454
     *      Name of the enum to be added to this package
474761f14bca Initial load
duke
parents:
diff changeset
   455
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   456
     *          Modifiers for this enum declaration
474761f14bca Initial load
duke
parents:
diff changeset
   457
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   458
     *      newly created Enum
474761f14bca Initial load
duke
parents:
diff changeset
   459
     * @exception JClassAlreadyExistsException
474761f14bca Initial load
duke
parents:
diff changeset
   460
     *      When the specified class/interface was already created.
474761f14bca Initial load
duke
parents:
diff changeset
   461
474761f14bca Initial load
duke
parents:
diff changeset
   462
     */
474761f14bca Initial load
duke
parents:
diff changeset
   463
    public JDefinedClass _enum (int mods,String name) throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   464
        return _class (mods,name,ClassType.ENUM);
474761f14bca Initial load
duke
parents:
diff changeset
   465
    }
474761f14bca Initial load
duke
parents:
diff changeset
   466
474761f14bca Initial load
duke
parents:
diff changeset
   467
474761f14bca Initial load
duke
parents:
diff changeset
   468
474761f14bca Initial load
duke
parents:
diff changeset
   469
474761f14bca Initial load
duke
parents:
diff changeset
   470
474761f14bca Initial load
duke
parents:
diff changeset
   471
    public ClassType getClassType(){
474761f14bca Initial load
duke
parents:
diff changeset
   472
        return this.classType;
474761f14bca Initial load
duke
parents:
diff changeset
   473
    }
474761f14bca Initial load
duke
parents:
diff changeset
   474
474761f14bca Initial load
duke
parents:
diff changeset
   475
    public JFieldVar field(
474761f14bca Initial load
duke
parents:
diff changeset
   476
        int mods,
474761f14bca Initial load
duke
parents:
diff changeset
   477
        Class type,
474761f14bca Initial load
duke
parents:
diff changeset
   478
        String name,
474761f14bca Initial load
duke
parents:
diff changeset
   479
        JExpression init) {
474761f14bca Initial load
duke
parents:
diff changeset
   480
        return field(mods, owner()._ref(type), name, init);
474761f14bca Initial load
duke
parents:
diff changeset
   481
    }
474761f14bca Initial load
duke
parents:
diff changeset
   482
474761f14bca Initial load
duke
parents:
diff changeset
   483
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   484
     * Returns all the fields declred in this class.
474761f14bca Initial load
duke
parents:
diff changeset
   485
     * The returned {@link Map} is a read-only live view.
474761f14bca Initial load
duke
parents:
diff changeset
   486
     *
474761f14bca Initial load
duke
parents:
diff changeset
   487
     * @return always non-null.
474761f14bca Initial load
duke
parents:
diff changeset
   488
     */
474761f14bca Initial load
duke
parents:
diff changeset
   489
    public Map<String,JFieldVar> fields() {
474761f14bca Initial load
duke
parents:
diff changeset
   490
        return Collections.unmodifiableMap(fields);
474761f14bca Initial load
duke
parents:
diff changeset
   491
    }
474761f14bca Initial load
duke
parents:
diff changeset
   492
474761f14bca Initial load
duke
parents:
diff changeset
   493
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   494
     * Removes a {@link JFieldVar} from this class.
474761f14bca Initial load
duke
parents:
diff changeset
   495
     *
474761f14bca Initial load
duke
parents:
diff changeset
   496
     * @throws IllegalArgumentException
474761f14bca Initial load
duke
parents:
diff changeset
   497
     *      if the given field is not a field on this class.
474761f14bca Initial load
duke
parents:
diff changeset
   498
     */
474761f14bca Initial load
duke
parents:
diff changeset
   499
    public void removeField(JFieldVar field) {
474761f14bca Initial load
duke
parents:
diff changeset
   500
        if(fields.remove(field.name())!=field)
474761f14bca Initial load
duke
parents:
diff changeset
   501
            throw new IllegalArgumentException();
474761f14bca Initial load
duke
parents:
diff changeset
   502
    }
474761f14bca Initial load
duke
parents:
diff changeset
   503
474761f14bca Initial load
duke
parents:
diff changeset
   504
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   505
     * Creates, if necessary, and returns the static initializer
474761f14bca Initial load
duke
parents:
diff changeset
   506
     * for this class.
474761f14bca Initial load
duke
parents:
diff changeset
   507
     *
474761f14bca Initial load
duke
parents:
diff changeset
   508
     * @return JBlock containing initialization statements for this class
474761f14bca Initial load
duke
parents:
diff changeset
   509
     */
474761f14bca Initial load
duke
parents:
diff changeset
   510
    public JBlock init() {
474761f14bca Initial load
duke
parents:
diff changeset
   511
        if (init == null)
474761f14bca Initial load
duke
parents:
diff changeset
   512
            init = new JBlock();
474761f14bca Initial load
duke
parents:
diff changeset
   513
        return init;
474761f14bca Initial load
duke
parents:
diff changeset
   514
    }
474761f14bca Initial load
duke
parents:
diff changeset
   515
474761f14bca Initial load
duke
parents:
diff changeset
   516
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   517
     * Adds a constructor to this class.
474761f14bca Initial load
duke
parents:
diff changeset
   518
     *
474761f14bca Initial load
duke
parents:
diff changeset
   519
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   520
     *        Modifiers for this constructor
474761f14bca Initial load
duke
parents:
diff changeset
   521
     */
474761f14bca Initial load
duke
parents:
diff changeset
   522
    public JMethod constructor(int mods) {
474761f14bca Initial load
duke
parents:
diff changeset
   523
        JMethod c = new JMethod(mods, this);
474761f14bca Initial load
duke
parents:
diff changeset
   524
        constructors.add(c);
474761f14bca Initial load
duke
parents:
diff changeset
   525
        return c;
474761f14bca Initial load
duke
parents:
diff changeset
   526
    }
474761f14bca Initial load
duke
parents:
diff changeset
   527
474761f14bca Initial load
duke
parents:
diff changeset
   528
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   529
     * Returns an iterator that walks the constructors defined in this class.
474761f14bca Initial load
duke
parents:
diff changeset
   530
     */
474761f14bca Initial load
duke
parents:
diff changeset
   531
    public Iterator constructors() {
474761f14bca Initial load
duke
parents:
diff changeset
   532
        return constructors.iterator();
474761f14bca Initial load
duke
parents:
diff changeset
   533
    }
474761f14bca Initial load
duke
parents:
diff changeset
   534
474761f14bca Initial load
duke
parents:
diff changeset
   535
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   536
     * Looks for a method that has the specified method signature
474761f14bca Initial load
duke
parents:
diff changeset
   537
     * and return it.
474761f14bca Initial load
duke
parents:
diff changeset
   538
     *
474761f14bca Initial load
duke
parents:
diff changeset
   539
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   540
     *      null if not found.
474761f14bca Initial load
duke
parents:
diff changeset
   541
     */
474761f14bca Initial load
duke
parents:
diff changeset
   542
    public JMethod getConstructor(JType[] argTypes) {
474761f14bca Initial load
duke
parents:
diff changeset
   543
        for (JMethod m : constructors) {
474761f14bca Initial load
duke
parents:
diff changeset
   544
            if (m.hasSignature(argTypes))
474761f14bca Initial load
duke
parents:
diff changeset
   545
                return m;
474761f14bca Initial load
duke
parents:
diff changeset
   546
        }
474761f14bca Initial load
duke
parents:
diff changeset
   547
        return null;
474761f14bca Initial load
duke
parents:
diff changeset
   548
    }
474761f14bca Initial load
duke
parents:
diff changeset
   549
474761f14bca Initial load
duke
parents:
diff changeset
   550
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   551
     * Add a method to the list of method members of this JDefinedClass instance.
474761f14bca Initial load
duke
parents:
diff changeset
   552
     *
474761f14bca Initial load
duke
parents:
diff changeset
   553
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   554
     *        Modifiers for this method
474761f14bca Initial load
duke
parents:
diff changeset
   555
     *
474761f14bca Initial load
duke
parents:
diff changeset
   556
     * @param type
474761f14bca Initial load
duke
parents:
diff changeset
   557
     *        Return type for this method
474761f14bca Initial load
duke
parents:
diff changeset
   558
     *
474761f14bca Initial load
duke
parents:
diff changeset
   559
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   560
     *        Name of the method
474761f14bca Initial load
duke
parents:
diff changeset
   561
     *
474761f14bca Initial load
duke
parents:
diff changeset
   562
     * @return Newly generated JMethod
474761f14bca Initial load
duke
parents:
diff changeset
   563
     */
474761f14bca Initial load
duke
parents:
diff changeset
   564
    public JMethod method(int mods, JType type, String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   565
        // XXX problems caught in M constructor
474761f14bca Initial load
duke
parents:
diff changeset
   566
        JMethod m = new JMethod(this, mods, type, name);
474761f14bca Initial load
duke
parents:
diff changeset
   567
        methods.add(m);
474761f14bca Initial load
duke
parents:
diff changeset
   568
        return m;
474761f14bca Initial load
duke
parents:
diff changeset
   569
    }
474761f14bca Initial load
duke
parents:
diff changeset
   570
474761f14bca Initial load
duke
parents:
diff changeset
   571
    public JMethod method(int mods, Class type, String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   572
        return method(mods, owner()._ref(type), name);
474761f14bca Initial load
duke
parents:
diff changeset
   573
    }
474761f14bca Initial load
duke
parents:
diff changeset
   574
474761f14bca Initial load
duke
parents:
diff changeset
   575
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   576
     * Returns the set of methods defined in this class.
474761f14bca Initial load
duke
parents:
diff changeset
   577
     */
474761f14bca Initial load
duke
parents:
diff changeset
   578
    public Collection<JMethod> methods() {
474761f14bca Initial load
duke
parents:
diff changeset
   579
        return methods;
474761f14bca Initial load
duke
parents:
diff changeset
   580
    }
474761f14bca Initial load
duke
parents:
diff changeset
   581
474761f14bca Initial load
duke
parents:
diff changeset
   582
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   583
     * Looks for a method that has the specified method signature
474761f14bca Initial load
duke
parents:
diff changeset
   584
     * and return it.
474761f14bca Initial load
duke
parents:
diff changeset
   585
     *
474761f14bca Initial load
duke
parents:
diff changeset
   586
     * @return
474761f14bca Initial load
duke
parents:
diff changeset
   587
     *      null if not found.
474761f14bca Initial load
duke
parents:
diff changeset
   588
     */
474761f14bca Initial load
duke
parents:
diff changeset
   589
    public JMethod getMethod(String name, JType[] argTypes) {
474761f14bca Initial load
duke
parents:
diff changeset
   590
        for (JMethod m : methods) {
474761f14bca Initial load
duke
parents:
diff changeset
   591
            if (!m.name().equals(name))
474761f14bca Initial load
duke
parents:
diff changeset
   592
                continue;
474761f14bca Initial load
duke
parents:
diff changeset
   593
474761f14bca Initial load
duke
parents:
diff changeset
   594
            if (m.hasSignature(argTypes))
474761f14bca Initial load
duke
parents:
diff changeset
   595
                return m;
474761f14bca Initial load
duke
parents:
diff changeset
   596
        }
474761f14bca Initial load
duke
parents:
diff changeset
   597
        return null;
474761f14bca Initial load
duke
parents:
diff changeset
   598
    }
474761f14bca Initial load
duke
parents:
diff changeset
   599
474761f14bca Initial load
duke
parents:
diff changeset
   600
    public boolean isClass() {
474761f14bca Initial load
duke
parents:
diff changeset
   601
        return true;
474761f14bca Initial load
duke
parents:
diff changeset
   602
    }
474761f14bca Initial load
duke
parents:
diff changeset
   603
    public boolean isPackage() {
474761f14bca Initial load
duke
parents:
diff changeset
   604
        return false;
474761f14bca Initial load
duke
parents:
diff changeset
   605
    }
474761f14bca Initial load
duke
parents:
diff changeset
   606
    public JPackage getPackage() { return parentContainer().getPackage(); }
474761f14bca Initial load
duke
parents:
diff changeset
   607
474761f14bca Initial load
duke
parents:
diff changeset
   608
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   609
     * Add a new nested class to this class.
474761f14bca Initial load
duke
parents:
diff changeset
   610
     *
474761f14bca Initial load
duke
parents:
diff changeset
   611
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   612
     *        Modifiers for this class declaration
474761f14bca Initial load
duke
parents:
diff changeset
   613
     *
474761f14bca Initial load
duke
parents:
diff changeset
   614
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   615
     *        Name of class to be added to this package
474761f14bca Initial load
duke
parents:
diff changeset
   616
     *
474761f14bca Initial load
duke
parents:
diff changeset
   617
     * @return Newly generated class
474761f14bca Initial load
duke
parents:
diff changeset
   618
     */
474761f14bca Initial load
duke
parents:
diff changeset
   619
    public JDefinedClass _class(int mods, String name)
474761f14bca Initial load
duke
parents:
diff changeset
   620
        throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   621
        return _class(mods, name, ClassType.CLASS);
474761f14bca Initial load
duke
parents:
diff changeset
   622
    }
474761f14bca Initial load
duke
parents:
diff changeset
   623
474761f14bca Initial load
duke
parents:
diff changeset
   624
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   625
     * {@inheritDoc}
474761f14bca Initial load
duke
parents:
diff changeset
   626
     *
474761f14bca Initial load
duke
parents:
diff changeset
   627
     * @deprecated
474761f14bca Initial load
duke
parents:
diff changeset
   628
     */
474761f14bca Initial load
duke
parents:
diff changeset
   629
    public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   630
        return _class(mods,name,isInterface?ClassType.INTERFACE:ClassType.CLASS);
474761f14bca Initial load
duke
parents:
diff changeset
   631
    }
474761f14bca Initial load
duke
parents:
diff changeset
   632
474761f14bca Initial load
duke
parents:
diff changeset
   633
    public JDefinedClass _class(int mods, String name, ClassType classTypeVal)
474761f14bca Initial load
duke
parents:
diff changeset
   634
        throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   635
474761f14bca Initial load
duke
parents:
diff changeset
   636
        String NAME;
474761f14bca Initial load
duke
parents:
diff changeset
   637
        if (JCodeModel.isCaseSensitiveFileSystem)
474761f14bca Initial load
duke
parents:
diff changeset
   638
            NAME = name.toUpperCase();
474761f14bca Initial load
duke
parents:
diff changeset
   639
        else
474761f14bca Initial load
duke
parents:
diff changeset
   640
            NAME = name;
474761f14bca Initial load
duke
parents:
diff changeset
   641
474761f14bca Initial load
duke
parents:
diff changeset
   642
        if (getClasses().containsKey(NAME))
474761f14bca Initial load
duke
parents:
diff changeset
   643
            throw new JClassAlreadyExistsException(getClasses().get(NAME));
474761f14bca Initial load
duke
parents:
diff changeset
   644
        else {
474761f14bca Initial load
duke
parents:
diff changeset
   645
            // XXX problems caught in the NC constructor
474761f14bca Initial load
duke
parents:
diff changeset
   646
            JDefinedClass c = new JDefinedClass(this, mods, name, classTypeVal);
474761f14bca Initial load
duke
parents:
diff changeset
   647
            getClasses().put(NAME,c);
474761f14bca Initial load
duke
parents:
diff changeset
   648
            return c;
474761f14bca Initial load
duke
parents:
diff changeset
   649
        }
474761f14bca Initial load
duke
parents:
diff changeset
   650
    }
474761f14bca Initial load
duke
parents:
diff changeset
   651
474761f14bca Initial load
duke
parents:
diff changeset
   652
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   653
     * Add a new public nested class to this class.
474761f14bca Initial load
duke
parents:
diff changeset
   654
     */
474761f14bca Initial load
duke
parents:
diff changeset
   655
    public JDefinedClass _class(String name)
474761f14bca Initial load
duke
parents:
diff changeset
   656
        throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   657
        return _class(JMod.PUBLIC, name);
474761f14bca Initial load
duke
parents:
diff changeset
   658
    }
474761f14bca Initial load
duke
parents:
diff changeset
   659
474761f14bca Initial load
duke
parents:
diff changeset
   660
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   661
     * Add an interface to this package.
474761f14bca Initial load
duke
parents:
diff changeset
   662
     *
474761f14bca Initial load
duke
parents:
diff changeset
   663
     * @param mods
474761f14bca Initial load
duke
parents:
diff changeset
   664
     *        Modifiers for this interface declaration
474761f14bca Initial load
duke
parents:
diff changeset
   665
     *
474761f14bca Initial load
duke
parents:
diff changeset
   666
     * @param name
474761f14bca Initial load
duke
parents:
diff changeset
   667
     *        Name of interface to be added to this package
474761f14bca Initial load
duke
parents:
diff changeset
   668
     *
474761f14bca Initial load
duke
parents:
diff changeset
   669
     * @return Newly generated interface
474761f14bca Initial load
duke
parents:
diff changeset
   670
     */
474761f14bca Initial load
duke
parents:
diff changeset
   671
    public JDefinedClass _interface(int mods, String name)
474761f14bca Initial load
duke
parents:
diff changeset
   672
        throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   673
        return _class(mods, name, ClassType.INTERFACE);
474761f14bca Initial load
duke
parents:
diff changeset
   674
    }
474761f14bca Initial load
duke
parents:
diff changeset
   675
474761f14bca Initial load
duke
parents:
diff changeset
   676
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   677
     * Adds a public interface to this package.
474761f14bca Initial load
duke
parents:
diff changeset
   678
     */
474761f14bca Initial load
duke
parents:
diff changeset
   679
    public JDefinedClass _interface(String name)
474761f14bca Initial load
duke
parents:
diff changeset
   680
        throws JClassAlreadyExistsException {
474761f14bca Initial load
duke
parents:
diff changeset
   681
        return _interface(JMod.PUBLIC, name);
474761f14bca Initial load
duke
parents:
diff changeset
   682
    }
474761f14bca Initial load
duke
parents:
diff changeset
   683
474761f14bca Initial load
duke
parents:
diff changeset
   684
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   685
     * Creates, if necessary, and returns the class javadoc for this
474761f14bca Initial load
duke
parents:
diff changeset
   686
     * JDefinedClass
474761f14bca Initial load
duke
parents:
diff changeset
   687
     *
474761f14bca Initial load
duke
parents:
diff changeset
   688
     * @return JDocComment containing javadocs for this class
474761f14bca Initial load
duke
parents:
diff changeset
   689
     */
474761f14bca Initial load
duke
parents:
diff changeset
   690
    public JDocComment javadoc() {
474761f14bca Initial load
duke
parents:
diff changeset
   691
        if (jdoc == null)
474761f14bca Initial load
duke
parents:
diff changeset
   692
            jdoc = new JDocComment(owner());
474761f14bca Initial load
duke
parents:
diff changeset
   693
        return jdoc;
474761f14bca Initial load
duke
parents:
diff changeset
   694
    }
474761f14bca Initial load
duke
parents:
diff changeset
   695
474761f14bca Initial load
duke
parents:
diff changeset
   696
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   697
     * Mark this file as hidden, so that this file won't be
474761f14bca Initial load
duke
parents:
diff changeset
   698
     * generated.
474761f14bca Initial load
duke
parents:
diff changeset
   699
     *
474761f14bca Initial load
duke
parents:
diff changeset
   700
     * <p>
474761f14bca Initial load
duke
parents:
diff changeset
   701
     * This feature could be used to generate code that refers
474761f14bca Initial load
duke
parents:
diff changeset
   702
     * to class X, without actually generating X.java.
474761f14bca Initial load
duke
parents:
diff changeset
   703
     */
474761f14bca Initial load
duke
parents:
diff changeset
   704
    public void hide() {
474761f14bca Initial load
duke
parents:
diff changeset
   705
        hideFile = true;
474761f14bca Initial load
duke
parents:
diff changeset
   706
    }
474761f14bca Initial load
duke
parents:
diff changeset
   707
474761f14bca Initial load
duke
parents:
diff changeset
   708
    public boolean isHidden() {
474761f14bca Initial load
duke
parents:
diff changeset
   709
        return hideFile;
474761f14bca Initial load
duke
parents:
diff changeset
   710
    }
474761f14bca Initial load
duke
parents:
diff changeset
   711
474761f14bca Initial load
duke
parents:
diff changeset
   712
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   713
     * Returns an iterator that walks the nested classes defined in this
474761f14bca Initial load
duke
parents:
diff changeset
   714
     * class.
474761f14bca Initial load
duke
parents:
diff changeset
   715
     */
474761f14bca Initial load
duke
parents:
diff changeset
   716
    public final Iterator<JDefinedClass> classes() {
474761f14bca Initial load
duke
parents:
diff changeset
   717
        if(classes==null)
474761f14bca Initial load
duke
parents:
diff changeset
   718
            return Collections.<JDefinedClass>emptyList().iterator();
474761f14bca Initial load
duke
parents:
diff changeset
   719
        else
474761f14bca Initial load
duke
parents:
diff changeset
   720
            return classes.values().iterator();
474761f14bca Initial load
duke
parents:
diff changeset
   721
    }
474761f14bca Initial load
duke
parents:
diff changeset
   722
474761f14bca Initial load
duke
parents:
diff changeset
   723
    private Map<String,JDefinedClass> getClasses() {
474761f14bca Initial load
duke
parents:
diff changeset
   724
        if(classes==null)
474761f14bca Initial load
duke
parents:
diff changeset
   725
            classes = new TreeMap<String,JDefinedClass>();
474761f14bca Initial load
duke
parents:
diff changeset
   726
        return classes;
474761f14bca Initial load
duke
parents:
diff changeset
   727
    }
474761f14bca Initial load
duke
parents:
diff changeset
   728
474761f14bca Initial load
duke
parents:
diff changeset
   729
474761f14bca Initial load
duke
parents:
diff changeset
   730
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   731
     * Returns all the nested classes defined in this class.
474761f14bca Initial load
duke
parents:
diff changeset
   732
     */
474761f14bca Initial load
duke
parents:
diff changeset
   733
    public final JClass[] listClasses() {
474761f14bca Initial load
duke
parents:
diff changeset
   734
        if(classes==null)
474761f14bca Initial load
duke
parents:
diff changeset
   735
            return new JClass[0];
474761f14bca Initial load
duke
parents:
diff changeset
   736
        else
474761f14bca Initial load
duke
parents:
diff changeset
   737
            return classes.values().toArray(new JClass[classes.values().size()]);
474761f14bca Initial load
duke
parents:
diff changeset
   738
    }
474761f14bca Initial load
duke
parents:
diff changeset
   739
474761f14bca Initial load
duke
parents:
diff changeset
   740
    @Override
474761f14bca Initial load
duke
parents:
diff changeset
   741
    public JClass outer() {
474761f14bca Initial load
duke
parents:
diff changeset
   742
        if (outer.isClass())
474761f14bca Initial load
duke
parents:
diff changeset
   743
            return (JClass) outer;
474761f14bca Initial load
duke
parents:
diff changeset
   744
        else
474761f14bca Initial load
duke
parents:
diff changeset
   745
            return null;
474761f14bca Initial load
duke
parents:
diff changeset
   746
    }
474761f14bca Initial load
duke
parents:
diff changeset
   747
474761f14bca Initial load
duke
parents:
diff changeset
   748
    public void declare(JFormatter f) {
474761f14bca Initial load
duke
parents:
diff changeset
   749
        if (jdoc != null)
474761f14bca Initial load
duke
parents:
diff changeset
   750
            f.nl().g(jdoc);
474761f14bca Initial load
duke
parents:
diff changeset
   751
474761f14bca Initial load
duke
parents:
diff changeset
   752
        if (annotations != null){
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   753
            for (JAnnotationUse annotation : annotations)
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
   754
                f.g(annotation).nl();
8
474761f14bca Initial load
duke
parents:
diff changeset
   755
        }
474761f14bca Initial load
duke
parents:
diff changeset
   756
474761f14bca Initial load
duke
parents:
diff changeset
   757
        f.g(mods).p(classType.declarationToken).id(name).d(generifiable);
474761f14bca Initial load
duke
parents:
diff changeset
   758
474761f14bca Initial load
duke
parents:
diff changeset
   759
        if (superClass != null && superClass != owner().ref(Object.class))
474761f14bca Initial load
duke
parents:
diff changeset
   760
            f.nl().i().p("extends").g(superClass).nl().o();
474761f14bca Initial load
duke
parents:
diff changeset
   761
474761f14bca Initial load
duke
parents:
diff changeset
   762
        if (!interfaces.isEmpty()) {
474761f14bca Initial load
duke
parents:
diff changeset
   763
            if (superClass == null)
474761f14bca Initial load
duke
parents:
diff changeset
   764
                f.nl();
474761f14bca Initial load
duke
parents:
diff changeset
   765
            f.i().p(classType==ClassType.INTERFACE ? "extends" : "implements");
474761f14bca Initial load
duke
parents:
diff changeset
   766
            f.g(interfaces);
474761f14bca Initial load
duke
parents:
diff changeset
   767
            f.nl().o();
474761f14bca Initial load
duke
parents:
diff changeset
   768
        }
474761f14bca Initial load
duke
parents:
diff changeset
   769
        declareBody(f);
474761f14bca Initial load
duke
parents:
diff changeset
   770
    }
474761f14bca Initial load
duke
parents:
diff changeset
   771
474761f14bca Initial load
duke
parents:
diff changeset
   772
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   773
     * prints the body of a class.
474761f14bca Initial load
duke
parents:
diff changeset
   774
     */
474761f14bca Initial load
duke
parents:
diff changeset
   775
    protected void declareBody(JFormatter f) {
474761f14bca Initial load
duke
parents:
diff changeset
   776
        f.p('{').nl().nl().i();
474761f14bca Initial load
duke
parents:
diff changeset
   777
        boolean first = true;
474761f14bca Initial load
duke
parents:
diff changeset
   778
474761f14bca Initial load
duke
parents:
diff changeset
   779
        if (!enumConstantsByName.isEmpty()) {
474761f14bca Initial load
duke
parents:
diff changeset
   780
            for (JEnumConstant c : enumConstantsByName.values()) {
474761f14bca Initial load
duke
parents:
diff changeset
   781
                if (!first) f.p(',').nl();
474761f14bca Initial load
duke
parents:
diff changeset
   782
                f.d(c);
474761f14bca Initial load
duke
parents:
diff changeset
   783
                first = false;
474761f14bca Initial load
duke
parents:
diff changeset
   784
            }
474761f14bca Initial load
duke
parents:
diff changeset
   785
                f.p(';').nl();
474761f14bca Initial load
duke
parents:
diff changeset
   786
        }
474761f14bca Initial load
duke
parents:
diff changeset
   787
474761f14bca Initial load
duke
parents:
diff changeset
   788
        for( JFieldVar field : fields.values() )
474761f14bca Initial load
duke
parents:
diff changeset
   789
            f.d(field);
474761f14bca Initial load
duke
parents:
diff changeset
   790
        if (init != null)
474761f14bca Initial load
duke
parents:
diff changeset
   791
            f.nl().p("static").s(init);
474761f14bca Initial load
duke
parents:
diff changeset
   792
        for (JMethod m : constructors) {
474761f14bca Initial load
duke
parents:
diff changeset
   793
            f.nl().d(m);
474761f14bca Initial load
duke
parents:
diff changeset
   794
        }
474761f14bca Initial load
duke
parents:
diff changeset
   795
        for (JMethod m : methods) {
474761f14bca Initial load
duke
parents:
diff changeset
   796
            f.nl().d(m);
474761f14bca Initial load
duke
parents:
diff changeset
   797
        }
474761f14bca Initial load
duke
parents:
diff changeset
   798
        if(classes!=null)
474761f14bca Initial load
duke
parents:
diff changeset
   799
            for (JDefinedClass dc : classes.values())
474761f14bca Initial load
duke
parents:
diff changeset
   800
                f.nl().d(dc);
474761f14bca Initial load
duke
parents:
diff changeset
   801
474761f14bca Initial load
duke
parents:
diff changeset
   802
474761f14bca Initial load
duke
parents:
diff changeset
   803
        if (directBlock != null)
474761f14bca Initial load
duke
parents:
diff changeset
   804
            f.p(directBlock);
474761f14bca Initial load
duke
parents:
diff changeset
   805
        f.nl().o().p('}').nl();
474761f14bca Initial load
duke
parents:
diff changeset
   806
    }
474761f14bca Initial load
duke
parents:
diff changeset
   807
474761f14bca Initial load
duke
parents:
diff changeset
   808
    /**
474761f14bca Initial load
duke
parents:
diff changeset
   809
     * Places the given string directly inside the generated class.
474761f14bca Initial load
duke
parents:
diff changeset
   810
     *
474761f14bca Initial load
duke
parents:
diff changeset
   811
     * This method can be used to add methods/fields that are not
474761f14bca Initial load
duke
parents:
diff changeset
   812
     * generated by CodeModel.
474761f14bca Initial load
duke
parents:
diff changeset
   813
     * This method should be used only as the last resort.
474761f14bca Initial load
duke
parents:
diff changeset
   814
     */
474761f14bca Initial load
duke
parents:
diff changeset
   815
    public void direct(String string) {
474761f14bca Initial load
duke
parents:
diff changeset
   816
        if (directBlock == null)
474761f14bca Initial load
duke
parents:
diff changeset
   817
            directBlock = string;
474761f14bca Initial load
duke
parents:
diff changeset
   818
        else
474761f14bca Initial load
duke
parents:
diff changeset
   819
            directBlock += string;
474761f14bca Initial load
duke
parents:
diff changeset
   820
    }
474761f14bca Initial load
duke
parents:
diff changeset
   821
474761f14bca Initial load
duke
parents:
diff changeset
   822
    public final JPackage _package() {
474761f14bca Initial load
duke
parents:
diff changeset
   823
        JClassContainer p = outer;
474761f14bca Initial load
duke
parents:
diff changeset
   824
        while (!(p instanceof JPackage))
474761f14bca Initial load
duke
parents:
diff changeset
   825
            p = p.parentContainer();
474761f14bca Initial load
duke
parents:
diff changeset
   826
        return (JPackage) p;
474761f14bca Initial load
duke
parents:
diff changeset
   827
    }
474761f14bca Initial load
duke
parents:
diff changeset
   828
474761f14bca Initial load
duke
parents:
diff changeset
   829
    public final JClassContainer parentContainer() {
474761f14bca Initial load
duke
parents:
diff changeset
   830
        return outer;
474761f14bca Initial load
duke
parents:
diff changeset
   831
    }
474761f14bca Initial load
duke
parents:
diff changeset
   832
474761f14bca Initial load
duke
parents:
diff changeset
   833
    public JTypeVar generify(String name) {
474761f14bca Initial load
duke
parents:
diff changeset
   834
        return generifiable.generify(name);
474761f14bca Initial load
duke
parents:
diff changeset
   835
    }
474761f14bca Initial load
duke
parents:
diff changeset
   836
    public JTypeVar generify(String name, Class bound) {
474761f14bca Initial load
duke
parents:
diff changeset
   837
        return generifiable.generify(name, bound);
474761f14bca Initial load
duke
parents:
diff changeset
   838
    }
474761f14bca Initial load
duke
parents:
diff changeset
   839
    public JTypeVar generify(String name, JClass bound) {
474761f14bca Initial load
duke
parents:
diff changeset
   840
        return generifiable.generify(name, bound);
474761f14bca Initial load
duke
parents:
diff changeset
   841
    }
474761f14bca Initial load
duke
parents:
diff changeset
   842
    @Override
474761f14bca Initial load
duke
parents:
diff changeset
   843
    public JTypeVar[] typeParams() {
474761f14bca Initial load
duke
parents:
diff changeset
   844
        return generifiable.typeParams();
474761f14bca Initial load
duke
parents:
diff changeset
   845
    }
474761f14bca Initial load
duke
parents:
diff changeset
   846
474761f14bca Initial load
duke
parents:
diff changeset
   847
    protected JClass substituteParams(
474761f14bca Initial load
duke
parents:
diff changeset
   848
        JTypeVar[] variables,
474761f14bca Initial load
duke
parents:
diff changeset
   849
        List<JClass> bindings) {
474761f14bca Initial load
duke
parents:
diff changeset
   850
        return this;
474761f14bca Initial load
duke
parents:
diff changeset
   851
    }
474761f14bca Initial load
duke
parents:
diff changeset
   852
474761f14bca Initial load
duke
parents:
diff changeset
   853
    /** Adding ability to annotate a class
474761f14bca Initial load
duke
parents:
diff changeset
   854
     * @param clazz
474761f14bca Initial load
duke
parents:
diff changeset
   855
     *          The annotation class to annotate the class with
474761f14bca Initial load
duke
parents:
diff changeset
   856
     */
474761f14bca Initial load
duke
parents:
diff changeset
   857
    public JAnnotationUse annotate(Class <? extends Annotation> clazz){
474761f14bca Initial load
duke
parents:
diff changeset
   858
        return annotate(owner().ref(clazz));
474761f14bca Initial load
duke
parents:
diff changeset
   859
    }
474761f14bca Initial load
duke
parents:
diff changeset
   860
474761f14bca Initial load
duke
parents:
diff changeset
   861
    /** Adding ability to annotate a class
474761f14bca Initial load
duke
parents:
diff changeset
   862
      * @param clazz
474761f14bca Initial load
duke
parents:
diff changeset
   863
      *          The annotation class to annotate the class with
474761f14bca Initial load
duke
parents:
diff changeset
   864
      */
474761f14bca Initial load
duke
parents:
diff changeset
   865
     public JAnnotationUse annotate(JClass clazz){
474761f14bca Initial load
duke
parents:
diff changeset
   866
        if(annotations==null)
474761f14bca Initial load
duke
parents:
diff changeset
   867
           annotations = new ArrayList<JAnnotationUse>();
474761f14bca Initial load
duke
parents:
diff changeset
   868
        JAnnotationUse a = new JAnnotationUse(clazz);
474761f14bca Initial load
duke
parents:
diff changeset
   869
        annotations.add(a);
474761f14bca Initial load
duke
parents:
diff changeset
   870
        return a;
474761f14bca Initial load
duke
parents:
diff changeset
   871
    }
474761f14bca Initial load
duke
parents:
diff changeset
   872
474761f14bca Initial load
duke
parents:
diff changeset
   873
    public <W extends JAnnotationWriter> W annotate2(Class<W> clazz) {
474761f14bca Initial load
duke
parents:
diff changeset
   874
        return TypedAnnotationWriter.create(clazz,this);
474761f14bca Initial load
duke
parents:
diff changeset
   875
    }
474761f14bca Initial load
duke
parents:
diff changeset
   876
}