286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/Apackage com.sun.org.apache.bcel.internal.classfile;
286N/A
286N/A/* ====================================================================
286N/A * The Apache Software License, Version 1.1
286N/A *
286N/A * Copyright (c) 2001 The Apache Software Foundation. All rights
286N/A * reserved.
286N/A *
286N/A * Redistribution and use in source and binary forms, with or without
286N/A * modification, are permitted provided that the following conditions
286N/A * are met:
286N/A *
286N/A * 1. Redistributions of source code must retain the above copyright
286N/A * notice, this list of conditions and the following disclaimer.
286N/A *
286N/A * 2. Redistributions in binary form must reproduce the above copyright
286N/A * notice, this list of conditions and the following disclaimer in
286N/A * the documentation and/or other materials provided with the
286N/A * distribution.
286N/A *
286N/A * 3. The end-user documentation included with the redistribution,
286N/A * if any, must include the following acknowledgment:
286N/A * "This product includes software developed by the
286N/A * Apache Software Foundation (http://www.apache.org/)."
286N/A * Alternately, this acknowledgment may appear in the software itself,
286N/A * if and wherever such third-party acknowledgments normally appear.
286N/A *
286N/A * 4. The names "Apache" and "Apache Software Foundation" and
286N/A * "Apache BCEL" must not be used to endorse or promote products
286N/A * derived from this software without prior written permission. For
286N/A * written permission, please contact apache@apache.org.
286N/A *
286N/A * 5. Products derived from this software may not be called "Apache",
286N/A * "Apache BCEL", nor may "Apache" appear in their name, without
286N/A * prior written permission of the Apache Software Foundation.
286N/A *
286N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
286N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
286N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
286N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
286N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
286N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
286N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
286N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
286N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
286N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
286N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
286N/A * SUCH DAMAGE.
286N/A * ====================================================================
286N/A *
286N/A * This software consists of voluntary contributions made by many
286N/A * individuals on behalf of the Apache Software Foundation. For more
286N/A * information on the Apache Software Foundation, please see
286N/A * <http://www.apache.org/>.
286N/A */
286N/A
286N/Aimport com.sun.org.apache.bcel.internal.Constants;
286N/Aimport java.io.*;
286N/A
286N/A/**
286N/A * This class represents a inner class attribute, i.e., the class
286N/A * indices of the inner and outer classes, the name and the attributes
286N/A * of the inner class.
286N/A *
286N/A * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
286N/A * @see InnerClasses
286N/A */
286N/Apublic final class InnerClass implements Cloneable, Node {
286N/A private int inner_class_index;
286N/A private int outer_class_index;
286N/A private int inner_name_index;
286N/A private int inner_access_flags;
286N/A
286N/A /**
286N/A * Initialize from another object.
286N/A */
286N/A public InnerClass(InnerClass c) {
286N/A this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(),
286N/A c.getInnerAccessFlags());
286N/A }
286N/A
286N/A /**
286N/A * Construct object from file stream.
286N/A * @param file Input stream
286N/A * @throws IOException
286N/A */
286N/A InnerClass(DataInputStream file) throws IOException
286N/A {
286N/A this(file.readUnsignedShort(), file.readUnsignedShort(),
286N/A file.readUnsignedShort(), file.readUnsignedShort());
286N/A }
286N/A
286N/A /**
286N/A * @param inner_class_index Class index in constant pool of inner class
286N/A * @param outer_class_index Class index in constant pool of outer class
286N/A * @param inner_name_index Name index in constant pool of inner class
286N/A * @param inner_access_flags Access flags of inner class
286N/A */
286N/A public InnerClass(int inner_class_index, int outer_class_index,
286N/A int inner_name_index, int inner_access_flags)
286N/A {
286N/A this.inner_class_index = inner_class_index;
286N/A this.outer_class_index = outer_class_index;
286N/A this.inner_name_index = inner_name_index;
286N/A this.inner_access_flags = inner_access_flags;
286N/A }
286N/A
286N/A /**
286N/A * Called by objects that are traversing the nodes of the tree implicitely
286N/A * defined by the contents of a Java class. I.e., the hierarchy of methods,
286N/A * fields, attributes, etc. spawns a tree of objects.
286N/A *
286N/A * @param v Visitor object
286N/A */
286N/A public void accept(Visitor v) {
286N/A v.visitInnerClass(this);
286N/A }
286N/A /**
286N/A * Dump inner class attribute to file stream in binary format.
286N/A *
286N/A * @param file Output file stream
286N/A * @throws IOException
286N/A */
286N/A public final void dump(DataOutputStream file) throws IOException
286N/A {
286N/A file.writeShort(inner_class_index);
286N/A file.writeShort(outer_class_index);
286N/A file.writeShort(inner_name_index);
286N/A file.writeShort(inner_access_flags);
286N/A }
286N/A /**
286N/A * @return access flags of inner class.
286N/A */
286N/A public final int getInnerAccessFlags() { return inner_access_flags; }
286N/A /**
286N/A * @return class index of inner class.
286N/A */
286N/A public final int getInnerClassIndex() { return inner_class_index; }
286N/A /**
286N/A * @return name index of inner class.
286N/A */
286N/A public final int getInnerNameIndex() { return inner_name_index; }
286N/A /**
286N/A * @return class index of outer class.
286N/A */
286N/A public final int getOuterClassIndex() { return outer_class_index; }
286N/A /**
286N/A * @param inner_access_flags.
286N/A */
286N/A public final void setInnerAccessFlags(int inner_access_flags) {
286N/A this.inner_access_flags = inner_access_flags;
286N/A }
286N/A /**
286N/A * @param inner_class_index.
286N/A */
286N/A public final void setInnerClassIndex(int inner_class_index) {
286N/A this.inner_class_index = inner_class_index;
286N/A }
286N/A /**
286N/A * @param inner_name_index.
286N/A */
286N/A public final void setInnerNameIndex(int inner_name_index) {
286N/A this.inner_name_index = inner_name_index;
286N/A }
286N/A /**
286N/A * @param outer_class_index.
286N/A */
286N/A public final void setOuterClassIndex(int outer_class_index) {
286N/A this.outer_class_index = outer_class_index;
286N/A }
286N/A /**
286N/A * @return String representation.
286N/A */
286N/A public final String toString() {
286N/A return "InnerClass(" + inner_class_index + ", " + outer_class_index +
286N/A ", " + inner_name_index + ", " + inner_access_flags + ")";
286N/A }
286N/A
286N/A /**
286N/A * @return Resolved string representation
286N/A */
286N/A public final String toString(ConstantPool constant_pool) {
286N/A String inner_class_name, outer_class_name, inner_name, access;
286N/A
286N/A inner_class_name = constant_pool.getConstantString(inner_class_index,
286N/A Constants.CONSTANT_Class);
286N/A inner_class_name = Utility.compactClassName(inner_class_name);
286N/A
286N/A if (outer_class_index != 0) {
286N/A outer_class_name = constant_pool.getConstantString(outer_class_index,
286N/A Constants.CONSTANT_Class);
286N/A outer_class_name = Utility.compactClassName(outer_class_name);
286N/A }
286N/A else
286N/A outer_class_name = "<not a member>";
286N/A
286N/A if(inner_name_index != 0)
286N/A inner_name = ((ConstantUtf8)constant_pool.
286N/A getConstant(inner_name_index, Constants.CONSTANT_Utf8)).getBytes();
286N/A else
286N/A inner_name = "<anonymous>";
286N/A
286N/A access = Utility.accessToString(inner_access_flags, true);
286N/A access = access.equals("")? "" : (access + " ");
286N/A
286N/A return "InnerClass:" + access + inner_class_name +
286N/A "(\"" + outer_class_name + "\", \"" + inner_name + "\")";
286N/A }
286N/A
286N/A /**
286N/A * @return deep copy of this object
286N/A */
286N/A public InnerClass copy() {
286N/A try {
286N/A return (InnerClass)clone();
286N/A } catch(CloneNotSupportedException e) {}
286N/A
286N/A return null;
286N/A }
286N/A}