Methods Summary |
---|
public void | accept(com.sun.org.apache.bcel.internal.classfile.Visitor v)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.
v.visitConstantPool(this);
|
public java.lang.String | constantToString(com.sun.org.apache.bcel.internal.classfile.Constant c)Resolve constant to a string representation.
String str;
int i;
byte tag = c.getTag();
switch(tag) {
case Constants.CONSTANT_Class:
i = ((ConstantClass)c).getNameIndex();
c = getConstant(i, Constants.CONSTANT_Utf8);
str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
break;
case Constants.CONSTANT_String:
i = ((ConstantString)c).getStringIndex();
c = getConstant(i, Constants.CONSTANT_Utf8);
str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
break;
case Constants.CONSTANT_Utf8: str = ((ConstantUtf8)c).getBytes(); break;
case Constants.CONSTANT_Double: str = "" + ((ConstantDouble)c).getBytes(); break;
case Constants.CONSTANT_Float: str = "" + ((ConstantFloat)c).getBytes(); break;
case Constants.CONSTANT_Long: str = "" + ((ConstantLong)c).getBytes(); break;
case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;
case Constants.CONSTANT_NameAndType:
str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
Constants.CONSTANT_Utf8) + " " +
constantToString(((ConstantNameAndType)c).getSignatureIndex(),
Constants.CONSTANT_Utf8));
break;
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
case Constants.CONSTANT_Fieldref:
str = (constantToString(((ConstantCP)c).getClassIndex(),
Constants.CONSTANT_Class) + "." +
constantToString(((ConstantCP)c).getNameAndTypeIndex(),
Constants.CONSTANT_NameAndType));
break;
default: // Never reached
throw new RuntimeException("Unknown constant type " + tag);
}
return str;
|
public java.lang.String | constantToString(int index, byte tag)Retrieve constant at `index' from constant pool and resolve it to
a string representation.
Constant c = getConstant(index, tag);
return constantToString(c);
|
public com.sun.org.apache.bcel.internal.classfile.ConstantPool | copy()
ConstantPool c = null;
try {
c = (ConstantPool)clone();
} catch(CloneNotSupportedException e) {}
c.constant_pool = new Constant[constant_pool_count];
for(int i=1; i < constant_pool_count; i++) {
if(constant_pool[i] != null)
c.constant_pool[i] = constant_pool[i].copy();
}
return c;
|
public void | dump(java.io.DataOutputStream file)Dump constant pool to file stream in binary format.
file.writeShort(constant_pool_count);
for(int i=1; i < constant_pool_count; i++)
if(constant_pool[i] != null)
constant_pool[i].dump(file);
|
private static final java.lang.String | escape(java.lang.String str)
int len = str.length();
StringBuffer buf = new StringBuffer(len + 5);
char[] ch = str.toCharArray();
for(int i=0; i < len; i++) {
switch(ch[i]) {
case '\n" : buf.append("\\n"); break;
case '\r" : buf.append("\\r"); break;
case '\t" : buf.append("\\t"); break;
case '\b" : buf.append("\\b"); break;
case '"" : buf.append("\\\""); break;
default: buf.append(ch[i]);
}
}
return buf.toString();
|
public com.sun.org.apache.bcel.internal.classfile.Constant | getConstant(int index)Get constant from constant pool.
if (index >= constant_pool.length || index < 0)
throw new ClassFormatException("Invalid constant pool reference: " +
index + ". Constant pool size is: " +
constant_pool.length);
return constant_pool[index];
|
public com.sun.org.apache.bcel.internal.classfile.Constant | getConstant(int index, byte tag)Get constant from constant pool and check whether it has the
expected type.
Constant c;
c = getConstant(index);
if(c == null)
throw new ClassFormatException("Constant pool at index " + index + " is null.");
if(c.getTag() == tag)
return c;
else
throw new ClassFormatException("Expected class `" + Constants.CONSTANT_NAMES[tag] +
"' at index " + index + " and got " + c);
|
public com.sun.org.apache.bcel.internal.classfile.Constant[] | getConstantPool() return constant_pool;
|
public java.lang.String | getConstantString(int index, byte tag)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.
Constant c;
int i;
c = getConstant(index, tag);
/* 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) {
case Constants.CONSTANT_Class: i = ((ConstantClass)c).getNameIndex(); break;
case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
default:
throw new RuntimeException("getConstantString called with illegal tag " + tag);
}
// Finally get the string from the constant pool
c = getConstant(i, Constants.CONSTANT_Utf8);
return ((ConstantUtf8)c).getBytes();
|
public int | getLength()
return constant_pool_count;
|
public void | setConstant(int index, com.sun.org.apache.bcel.internal.classfile.Constant constant)
constant_pool[index] = constant;
|
public void | setConstantPool(com.sun.org.apache.bcel.internal.classfile.Constant[] constant_pool)
this.constant_pool = constant_pool;
constant_pool_count = (constant_pool == null)? 0 : constant_pool.length;
|
public java.lang.String | toString()
StringBuffer buf = new StringBuffer();
for(int i=1; i < constant_pool_count; i++)
buf.append(i + ")" + constant_pool[i] + "\n");
return buf.toString();
|