/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/**
* This class represents the constant pool, i.e., a table of constants, of
* a parsed classfile. It may contain null references, due to the JVM
* specification that skips an entry after an 8-byte constant (double,
* long) entry. Those interested in generating constant pools
* programatically should see <a href="../generic/ConstantPoolGen.html">
* ConstantPoolGen</a>.
* @see Constant
* @see com.sun.org.apache.bcel.internal.generic.ConstantPoolGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
private int constant_pool_count;
/**
* @param constant_pool Array of constants
*/
{
}
/**
* Read constants from given file stream.
*
* @param file Input stream
* @throws IOException
* @throws ClassFormatException
*/
{
byte tag;
/* constant_pool[0] is unused by the compiler and may be used freely
* by the implementation.
*/
for(int i=1; i < constant_pool_count; i++) {
/* Quote from the JVM specification:
* "All eight byte constants take up two spots in the constant pool.
* If this is the n'th byte in the constant pool, then the next item
* will be numbered n+2"
*
* Thus we have to increment the index counter.
*/
i++;
}
}
/**
* Called by objects that are traversing the nodes of the tree implicitely
* defined by the contents of a Java class. I.e., the hierarchy of methods,
* fields, attributes, etc. spawns a tree of objects.
*
* @param v Visitor object
*/
v.visitConstantPool(this);
}
/**
* Resolve constant to a string representation.
*
* @param constant Constant to be printed
* @return String representation
*/
throws ClassFormatException
{
int i;
switch(tag) {
case Constants.CONSTANT_Class:
i = ((ConstantClass)c).getNameIndex();
break;
case Constants.CONSTANT_String:
i = ((ConstantString)c).getStringIndex();
break;
break;
case Constants.CONSTANT_Fieldref:
break;
default: // Never reached
}
return str;
}
for(int i=0; i < len; i++) {
switch(ch[i]) {
}
}
}
/**
* Retrieve constant at `index' from constant pool and resolve it to
* a string representation.
*
* @param index of constant in constant pool
* @param tag expected type
* @return String representation
*/
throws ClassFormatException
{
return constantToString(c);
}
/**
* Dump constant pool to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
{
for(int i=1; i < constant_pool_count; i++)
if(constant_pool[i] != null)
}
/**
* Get constant from constant pool.
*
* @param index Index in constant pool
* @return Constant value
* @see Constant
*/
throw new ClassFormatException("Invalid constant pool reference: " +
index + ". Constant pool size is: " +
return constant_pool[index];
}
/**
* Get constant from constant pool and check whether it has the
* expected type.
*
* @param index Index in constant pool
* @param tag Tag of expected constant, i.e., its type
* @return Constant value
* @see Constant
* @throws ClassFormatException
*/
throws ClassFormatException
{
Constant c;
c = getConstant(index);
if(c == null)
return c;
else
}
/**
* @return Array of constants.
* @see Constant
*/
/**
* Get string from constant pool and bypass the indirection of
* `ConstantClass' and `ConstantString' objects. I.e. these classes have
* an index field that points to another entry of the constant pool of
* type `ConstantUtf8' which contains the real data.
*
* @param index Index in constant pool
* @param tag Tag of expected constant, either ConstantClass or ConstantString
* @return Contents of string reference
* @see ConstantClass
* @see ConstantString
* @throws ClassFormatException
*/
throws ClassFormatException
{
Constant c;
int i;
/* This switch() is not that elegant, since the two classes have the
* same contents, they just differ in the name of the index
* field variable.
* But we want to stick to the JVM naming conventions closely though
* we could have solved these more elegantly by using the same
* variable name or by subclassing.
*/
switch(tag) {
default:
}
// Finally get the string from the constant pool
return ((ConstantUtf8)c).getBytes();
}
/**
* @return Length of constant pool.
*/
public int getLength()
{
return constant_pool_count;
}
/**
* @param constant Constant to set
*/
}
/**
* @param constant_pool
*/
this.constant_pool = constant_pool;
}
/**
* @return String representation.
*/
for(int i=1; i < constant_pool_count; i++)
}
/**
* @return deep copy of this constant pool
*/
ConstantPool c = null;
try {
c = (ConstantPool)clone();
} catch(CloneNotSupportedException e) {}
for(int i=1; i < constant_pool_count; i++) {
if(constant_pool[i] != null)
}
return c;
}
}