325N/A/*
325N/A * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/A/*
325N/A * This file is available under and governed by the GNU General Public
325N/A * License version 2 only, as published by the Free Software Foundation.
325N/A * However, the following notice accompanied the original version of this
325N/A * file:
325N/A *
325N/A * ASM: a very small and fast Java bytecode manipulation framework
325N/A * Copyright (c) 2000-2007 INRIA, France Telecom
325N/A * All rights reserved.
325N/A *
325N/A * Redistribution and use in source and binary forms, with or without
325N/A * modification, are permitted provided that the following conditions
325N/A * are met:
325N/A * 1. Redistributions of source code must retain the above copyright
325N/A * notice, this list of conditions and the following disclaimer.
325N/A * 2. Redistributions in binary form must reproduce the above copyright
325N/A * notice, this list of conditions and the following disclaimer in the
325N/A * documentation and/or other materials provided with the distribution.
325N/A * 3. Neither the name of the copyright holders nor the names of its
325N/A * contributors may be used to endorse or promote products derived from
325N/A * this software without specific prior written permission.
325N/A *
325N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
325N/A * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
325N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
325N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
325N/A * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
325N/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
325N/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
325N/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
325N/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
325N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
325N/A * THE POSSIBILITY OF SUCH DAMAGE.
325N/A */
325N/Apackage com.sun.xml.internal.ws.org.objectweb.asm;
325N/A
325N/A/**
325N/A * A non standard class, field, method or code attribute.
325N/A *
325N/A * @author Eric Bruneton
325N/A * @author Eugene Kuleshov
325N/A */
325N/Apublic class Attribute {
325N/A
325N/A /**
325N/A * The type of this attribute.
325N/A */
325N/A public final String type;
325N/A
325N/A /**
325N/A * The raw value of this attribute, used only for unknown attributes.
325N/A */
325N/A byte[] value;
325N/A
325N/A /**
325N/A * The next attribute in this attribute list. May be <tt>null</tt>.
325N/A */
325N/A Attribute next;
325N/A
325N/A /**
325N/A * Constructs a new empty attribute.
325N/A *
325N/A * @param type the type of the attribute.
325N/A */
325N/A protected Attribute(final String type) {
325N/A this.type = type;
325N/A }
325N/A
325N/A /**
325N/A * Returns <tt>true</tt> if this type of attribute is unknown. The default
325N/A * implementation of this method always returns <tt>true</tt>.
325N/A *
325N/A * @return <tt>true</tt> if this type of attribute is unknown.
325N/A */
325N/A public boolean isUnknown() {
325N/A return true;
325N/A }
325N/A
325N/A /**
325N/A * Returns <tt>true</tt> if this type of attribute is a code attribute.
325N/A *
325N/A * @return <tt>true</tt> if this type of attribute is a code attribute.
325N/A */
325N/A public boolean isCodeAttribute() {
325N/A return false;
325N/A }
325N/A
325N/A /**
325N/A * Returns the labels corresponding to this attribute.
325N/A *
325N/A * @return the labels corresponding to this attribute, or <tt>null</tt> if
325N/A * this attribute is not a code attribute that contains labels.
325N/A */
325N/A protected Label[] getLabels() {
325N/A return null;
325N/A }
325N/A
325N/A /**
325N/A * Reads a {@link #type type} attribute. This method must return a <i>new</i>
325N/A * {@link Attribute} object, of type {@link #type type}, corresponding to
325N/A * the <tt>len</tt> bytes starting at the given offset, in the given class
325N/A * reader.
325N/A *
325N/A * @param cr the class that contains the attribute to be read.
325N/A * @param off index of the first byte of the attribute's content in {@link
325N/A * ClassReader#b cr.b}. The 6 attribute header bytes, containing the
325N/A * type and the length of the attribute, are not taken into account
325N/A * here.
325N/A * @param len the length of the attribute's content.
325N/A * @param buf buffer to be used to call
325N/A * {@link ClassReader#readUTF8 readUTF8},
325N/A * {@link ClassReader#readClass(int,char[]) readClass} or
325N/A * {@link ClassReader#readConst readConst}.
325N/A * @param codeOff index of the first byte of code's attribute content in
325N/A * {@link ClassReader#b cr.b}, or -1 if the attribute to be read is
325N/A * not a code attribute. The 6 attribute header bytes, containing the
325N/A * type and the length of the attribute, are not taken into account
325N/A * here.
325N/A * @param labels the labels of the method's code, or <tt>null</tt> if the
325N/A * attribute to be read is not a code attribute.
325N/A * @return a <i>new</i> {@link Attribute} object corresponding to the given
325N/A * bytes.
325N/A */
325N/A protected Attribute read(
325N/A final ClassReader cr,
325N/A final int off,
325N/A final int len,
325N/A final char[] buf,
325N/A final int codeOff,
325N/A final Label[] labels)
325N/A {
325N/A Attribute attr = new Attribute(type);
325N/A attr.value = new byte[len];
325N/A System.arraycopy(cr.b, off, attr.value, 0, len);
325N/A return attr;
325N/A }
325N/A
325N/A /**
325N/A * Returns the byte array form of this attribute.
325N/A *
325N/A * @param cw the class to which this attribute must be added. This parameter
325N/A * can be used to add to the constant pool of this class the items
325N/A * that corresponds to this attribute.
325N/A * @param code the bytecode of the method corresponding to this code
325N/A * attribute, or <tt>null</tt> if this attribute is not a code
325N/A * attributes.
325N/A * @param len the length of the bytecode of the method corresponding to this
325N/A * code attribute, or <tt>null</tt> if this attribute is not a code
325N/A * attribute.
325N/A * @param maxStack the maximum stack size of the method corresponding to
325N/A * this code attribute, or -1 if this attribute is not a code
325N/A * attribute.
325N/A * @param maxLocals the maximum number of local variables of the method
325N/A * corresponding to this code attribute, or -1 if this attribute is
325N/A * not a code attribute.
325N/A * @return the byte array form of this attribute.
325N/A */
325N/A protected ByteVector write(
325N/A final ClassWriter cw,
325N/A final byte[] code,
325N/A final int len,
325N/A final int maxStack,
325N/A final int maxLocals)
325N/A {
325N/A ByteVector v = new ByteVector();
325N/A v.data = value;
325N/A v.length = value.length;
325N/A return v;
325N/A }
325N/A
325N/A /**
325N/A * Returns the length of the attribute list that begins with this attribute.
325N/A *
325N/A * @return the length of the attribute list that begins with this attribute.
325N/A */
325N/A final int getCount() {
325N/A int count = 0;
325N/A Attribute attr = this;
325N/A while (attr != null) {
325N/A count += 1;
325N/A attr = attr.next;
325N/A }
325N/A return count;
325N/A }
325N/A
325N/A /**
325N/A * Returns the size of all the attributes in this attribute list.
325N/A *
325N/A * @param cw the class writer to be used to convert the attributes into byte
325N/A * arrays, with the {@link #write write} method.
325N/A * @param code the bytecode of the method corresponding to these code
325N/A * attributes, or <tt>null</tt> if these attributes are not code
325N/A * attributes.
325N/A * @param len the length of the bytecode of the method corresponding to
325N/A * these code attributes, or <tt>null</tt> if these attributes are
325N/A * not code attributes.
325N/A * @param maxStack the maximum stack size of the method corresponding to
325N/A * these code attributes, or -1 if these attributes are not code
325N/A * attributes.
325N/A * @param maxLocals the maximum number of local variables of the method
325N/A * corresponding to these code attributes, or -1 if these attributes
325N/A * are not code attributes.
325N/A * @return the size of all the attributes in this attribute list. This size
325N/A * includes the size of the attribute headers.
325N/A */
325N/A final int getSize(
325N/A final ClassWriter cw,
325N/A final byte[] code,
325N/A final int len,
325N/A final int maxStack,
325N/A final int maxLocals)
325N/A {
325N/A Attribute attr = this;
325N/A int size = 0;
325N/A while (attr != null) {
325N/A cw.newUTF8(attr.type);
325N/A size += attr.write(cw, code, len, maxStack, maxLocals).length + 6;
325N/A attr = attr.next;
325N/A }
325N/A return size;
325N/A }
325N/A
325N/A /**
325N/A * Writes all the attributes of this attribute list in the given byte
325N/A * vector.
325N/A *
325N/A * @param cw the class writer to be used to convert the attributes into byte
325N/A * arrays, with the {@link #write write} method.
325N/A * @param code the bytecode of the method corresponding to these code
325N/A * attributes, or <tt>null</tt> if these attributes are not code
325N/A * attributes.
325N/A * @param len the length of the bytecode of the method corresponding to
325N/A * these code attributes, or <tt>null</tt> if these attributes are
325N/A * not code attributes.
325N/A * @param maxStack the maximum stack size of the method corresponding to
325N/A * these code attributes, or -1 if these attributes are not code
325N/A * attributes.
325N/A * @param maxLocals the maximum number of local variables of the method
325N/A * corresponding to these code attributes, or -1 if these attributes
325N/A * are not code attributes.
325N/A * @param out where the attributes must be written.
325N/A */
325N/A final void put(
325N/A final ClassWriter cw,
325N/A final byte[] code,
325N/A final int len,
325N/A final int maxStack,
325N/A final int maxLocals,
325N/A final ByteVector out)
325N/A {
325N/A Attribute attr = this;
325N/A while (attr != null) {
325N/A ByteVector b = attr.write(cw, code, len, maxStack, maxLocals);
325N/A out.putShort(cw.newUTF8(attr.type)).putInt(b.length);
325N/A out.putByteArray(b.data, 0, b.length);
325N/A attr = attr.next;
325N/A }
325N/A }
325N/A}