jaxp/src/com/sun/org/apache/bcel/internal/classfile/Attribute.java
author dbuck
Thu, 10 Jan 2013 20:26:00 -0800
changeset 15346 3f6fd93fec9a
parent 12457 c348e06f0e82
permissions -rw-r--r--
8003147: port fix for BCEL bug 39695 Summary: Added support for Local Variable Type Table so that BCEL library can be used to modify methods with generics-related debug data without violating class file format Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
package com.sun.org.apache.bcel.internal.classfile;
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
/* ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * The Apache Software License, Version 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * Redistribution and use in source and binary forms, with or without
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * modification, are permitted provided that the following conditions
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * are met:
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * 1. Redistributions of source code must retain the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 *    notice, this list of conditions and the following disclaimer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 * 2. Redistributions in binary form must reproduce the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 *    notice, this list of conditions and the following disclaimer in
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 *    the documentation and/or other materials provided with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 *    distribution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
 * 3. The end-user documentation included with the redistribution,
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 *    if any, must include the following acknowledgment:
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 *       "This product includes software developed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 *        Apache Software Foundation (http://www.apache.org/)."
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 *    Alternately, this acknowledgment may appear in the software itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *    if and wherever such third-party acknowledgments normally appear.
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * 4. The names "Apache" and "Apache Software Foundation" and
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *    "Apache BCEL" must not be used to endorse or promote products
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    derived from this software without prior written permission. For
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *    written permission, please contact apache@apache.org.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * 5. Products derived from this software may not be called "Apache",
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *    "Apache BCEL", nor may "Apache" appear in their name, without
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *    prior written permission of the Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * SUCH DAMAGE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * This software consists of voluntary contributions made by many
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * individuals on behalf of the Apache Software Foundation.  For more
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * information on the Apache Software Foundation, please see
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * <http://www.apache.org/>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import com.sun.org.apache.bcel.internal.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import java.io.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
import java.util.HashMap;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * Abstract super class for <em>Attribute</em> objects. Currently the
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * <em>ConstantValue</em>, <em>SourceFile</em>, <em>Code</em>,
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * <em>Exceptiontable</em>, <em>LineNumberTable</em>,
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * <em>LocalVariableTable</em>, <em>InnerClasses</em> and
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 * <em>Synthetic</em> attributes are supported. The
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 * <em>Unknown</em> attribute stands for non-standard-attributes.
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 * @see     ConstantValue
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
 * @see     SourceFile
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
 * @see     Code
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
 * @see     Unknown
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
 * @see     ExceptionTable
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 * @see     LineNumberTable
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
 * @see     LocalVariableTable
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 * @see     InnerClasses
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
 * @see     Synthetic
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
 * @see     Deprecated
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
 * @see     Signature
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
*/
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
public abstract class Attribute implements Cloneable, Node, Serializable {
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  protected int          name_index; // Points to attribute name in constant pool
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
  protected int          length;     // Content length of attribute field
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  protected byte         tag;        // Tag to distiguish subclasses
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  protected ConstantPool constant_pool;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  protected Attribute(byte tag, int name_index, int length,
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
                      ConstantPool constant_pool) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    this.tag           = tag;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    this.name_index    = name_index;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    this.length        = length;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    this.constant_pool = constant_pool;
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * Called by objects that are traversing the nodes of the tree implicitely
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   * defined by the contents of a Java class. I.e., the hierarchy of methods,
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   * fields, attributes, etc. spawns a tree of objects.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
   * @param v Visitor object
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
  public abstract void accept(Visitor v);
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * Dump attribute to file stream in binary format.
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * @param file Output file stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
  public void dump(DataOutputStream file) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    file.writeShort(name_index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    file.writeInt(length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
  private static HashMap readers = new HashMap();
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
  /** Add an Attribute reader capable of parsing (user-defined) attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
   * named "name". You should not add readers for the standard attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   * such as "LineNumberTable", because those are handled internally.
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * @param name the name of the attribute as stored in the class file
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   * @param r the reader object
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
  public static void addAttributeReader(String name, AttributeReader r) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    readers.put(name, r);
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  /** Remove attribute reader
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
   * @param name the name of the attribute as stored in the class file
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
  public static void removeAttributeReader(String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    readers.remove(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
  /* Class method reads one attribute from the input data stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * This method must not be accessible from the outside.  It is
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   * called by the Field and Method constructor methods.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   * @see    Field
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * @see    Method
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   * @param  file Input stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   * @param  constant_pool Array of constants
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   * @return Attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   * @throws  IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   * @throws  ClassFormatException
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
  public static final Attribute readAttribute(DataInputStream file,
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                                              ConstantPool constant_pool)
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    throws IOException, ClassFormatException
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    ConstantUtf8 c;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    String       name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    int          name_index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    int          length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    byte         tag = Constants.ATTR_UNKNOWN; // Unknown attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    // Get class name from constant pool via `name_index' indirection
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    name_index = (int)file.readUnsignedShort();
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    c          = (ConstantUtf8)constant_pool.getConstant(name_index,
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                                                         Constants.CONSTANT_Utf8);
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
    name       = c.getBytes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    // Length of data in bytes
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    length = file.readInt();
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    // Compare strings to find known attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    for(byte i=0; i < Constants.KNOWN_ATTRIBUTES; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
      if(name.equals(Constants.ATTRIBUTE_NAMES[i])) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        tag = i; // found!
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    // Call proper constructor, depending on `tag'
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    switch(tag) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    case Constants.ATTR_UNKNOWN:
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
      AttributeReader r = (AttributeReader)readers.get(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
      if(r != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        return r.createAttribute(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        return new Unknown(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    case Constants.ATTR_CONSTANT_VALUE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
      return new ConstantValue(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    case Constants.ATTR_SOURCE_FILE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
      return new SourceFile(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    case Constants.ATTR_CODE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
      return new Code(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
    case Constants.ATTR_EXCEPTIONS:
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
      return new ExceptionTable(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    case Constants.ATTR_LINE_NUMBER_TABLE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
      return new LineNumberTable(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    case Constants.ATTR_LOCAL_VARIABLE_TABLE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      return new LocalVariableTable(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
15346
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents: 12457
diff changeset
   209
    case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE:
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents: 12457
diff changeset
   210
      return new LocalVariableTypeTable(name_index, length, file, constant_pool);
3f6fd93fec9a 8003147: port fix for BCEL bug 39695
dbuck
parents: 12457
diff changeset
   211
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    case Constants.ATTR_INNER_CLASSES:
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
      return new InnerClasses(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    case Constants.ATTR_SYNTHETIC:
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
      return new Synthetic(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    case Constants.ATTR_DEPRECATED:
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
      return new Deprecated(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    case Constants.ATTR_PMG:
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
      return new PMGClass(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    case Constants.ATTR_SIGNATURE:
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
      return new Signature(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    case Constants.ATTR_STACK_MAP:
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
      return new StackMap(name_index, length, file, constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
    default: // Never reached
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
      throw new IllegalStateException("Ooops! default case reached.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
   * @return Length of attribute field in bytes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
  public final int   getLength()    { return length; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
   * @param Attribute length in bytes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
  public final void setLength(int length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
    this.length = length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
   * @param name_index of attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
  public final void setNameIndex(int name_index) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    this.name_index = name_index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
   * @return Name index in constant pool of attribute name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
  public final int getNameIndex() { return name_index; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
   * @return Tag of attribute, i.e., its type. Value may not be altered, thus
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * there is no setTag() method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
  public final byte  getTag()       { return tag; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
   * @return Constant pool used by this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
   * @see ConstantPool
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
  public final ConstantPool getConstantPool() { return constant_pool; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
   * @param constant_pool Constant pool to be used for this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
   * @see ConstantPool
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
  public final void setConstantPool(ConstantPool constant_pool) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    this.constant_pool = constant_pool;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
   * Use copy() if you want to have a deep copy(), i.e., with all references
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
   * copied correctly.
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
   * @return shallow copy of this attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
  public Object clone() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    Object o = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
      o = super.clone();
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    } catch(CloneNotSupportedException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
      e.printStackTrace(); // Never occurs
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
    return o;
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
   * @return deep copy of this attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
  public abstract Attribute copy(ConstantPool constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
   * @return attribute name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
  public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    return Constants.ATTRIBUTE_NAMES[tag];
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
}