Methods Summary |
---|
public int | addArrayClass(com.sun.org.apache.bcel.internal.generic.ArrayType type)Add a reference to an array class (e.g. String[][]) as needed by MULTIANEWARRAY
instruction, e.g. to the ConstantPool.
return addClass_(type.getSignature());
|
public int | addClass(com.sun.org.apache.bcel.internal.generic.ObjectType type)Add a new Class reference to the ConstantPool for a given type.
return addClass(type.getClassName());
|
public int | addClass(java.lang.String str)Add a new Class reference to the ConstantPool, if it is not already in there.
return addClass_(str.replace('.", '/"));
|
private int | addClass_(java.lang.String clazz)
int ret;
if((ret = lookupClass(clazz)) != -1)
return ret; // Already in CP
adjustSize();
ConstantClass c = new ConstantClass(addUtf8(clazz));
ret = index;
constants[index++] = c;
class_table.put(clazz, new Index(ret));
return ret;
|
public int | addConstant(com.sun.org.apache.bcel.internal.classfile.Constant c, com.sun.org.apache.bcel.internal.generic.ConstantPoolGen cp)Import constant from another ConstantPool and return new index.
Constant[] constants = cp.getConstantPool().getConstantPool();
switch(c.getTag()) {
case Constants.CONSTANT_String: {
ConstantString s = (ConstantString)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()];
return addString(u8.getBytes());
}
case Constants.CONSTANT_Class: {
ConstantClass s = (ConstantClass)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()];
return addClass(u8.getBytes());
}
case Constants.CONSTANT_NameAndType: {
ConstantNameAndType n = (ConstantNameAndType)c;
ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()];
ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
return addNameAndType(u8.getBytes(), u8_2.getBytes());
}
case Constants.CONSTANT_Utf8:
return addUtf8(((ConstantUtf8)c).getBytes());
case Constants.CONSTANT_Double:
return addDouble(((ConstantDouble)c).getBytes());
case Constants.CONSTANT_Float:
return addFloat(((ConstantFloat)c).getBytes());
case Constants.CONSTANT_Long:
return addLong(((ConstantLong)c).getBytes());
case Constants.CONSTANT_Integer:
return addInteger(((ConstantInteger)c).getBytes());
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
case Constants.CONSTANT_Fieldref: {
ConstantCP m = (ConstantCP)c;
ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()];
ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()];
String class_name = u8.getBytes().replace('/", '.");
u8 = (ConstantUtf8)constants[n.getNameIndex()];
String name = u8.getBytes();
u8 = (ConstantUtf8)constants[n.getSignatureIndex()];
String signature = u8.getBytes();
switch(c.getTag()) {
case Constants.CONSTANT_InterfaceMethodref:
return addInterfaceMethodref(class_name, name, signature);
case Constants.CONSTANT_Methodref:
return addMethodref(class_name, name, signature);
case Constants.CONSTANT_Fieldref:
return addFieldref(class_name, name, signature);
default: // Never reached
throw new RuntimeException("Unknown constant type " + c);
}
}
default: // Never reached
throw new RuntimeException("Unknown constant type " + c);
}
|
public int | addDouble(double n)Add a new double constant to the ConstantPool, if it is not already in there.
int ret;
if((ret = lookupDouble(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index] = new ConstantDouble(n);
index += 2; // Wastes one entry according to spec
return ret;
|
public int | addFieldref(java.lang.String class_name, java.lang.String field_name, java.lang.String signature)Add a new Fieldref constant to the ConstantPool, if it is not already
in there.
int ret;
int class_index, name_and_type_index;
if((ret = lookupFieldref(class_name, field_name, signature)) != -1)
return ret; // Already in CP
adjustSize();
class_index = addClass(class_name);
name_and_type_index = addNameAndType(field_name, signature);
ret = index;
constants[index++] = new ConstantFieldref(class_index, name_and_type_index);
cp_table.put(class_name + FIELDREF_DELIM + field_name + FIELDREF_DELIM + signature, new Index(ret));
return ret;
|
public int | addFloat(float n)Add a new Float constant to the ConstantPool, if it is not already in there.
int ret;
if((ret = lookupFloat(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index++] = new ConstantFloat(n);
return ret;
|
public int | addInteger(int n)Add a new Integer constant to the ConstantPool, if it is not already in there.
int ret;
if((ret = lookupInteger(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index++] = new ConstantInteger(n);
return ret;
|
public int | addInterfaceMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)Add a new InterfaceMethodref constant to the ConstantPool, if it is not already
in there.
int ret, class_index, name_and_type_index;
if((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1)
return ret; // Already in CP
adjustSize();
class_index = addClass(class_name);
name_and_type_index = addNameAndType(method_name, signature);
ret = index;
constants[index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index);
cp_table.put(class_name + IMETHODREF_DELIM + method_name +
IMETHODREF_DELIM + signature, new Index(ret));
return ret;
|
public int | addInterfaceMethodref(com.sun.org.apache.bcel.internal.generic.MethodGen method)
return addInterfaceMethodref(method.getClassName(), method.getName(),
method.getSignature());
|
public int | addLong(long n)Add a new long constant to the ConstantPool, if it is not already in there.
int ret;
if((ret = lookupLong(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index] = new ConstantLong(n);
index += 2; // Wastes one entry according to spec
return ret;
|
public int | addMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)Add a new Methodref constant to the ConstantPool, if it is not already
in there.
int ret, class_index, name_and_type_index;
if((ret = lookupMethodref(class_name, method_name, signature)) != -1)
return ret; // Already in CP
adjustSize();
name_and_type_index = addNameAndType(method_name, signature);
class_index = addClass(class_name);
ret = index;
constants[index++] = new ConstantMethodref(class_index, name_and_type_index);
cp_table.put(class_name + METHODREF_DELIM + method_name +
METHODREF_DELIM + signature, new Index(ret));
return ret;
|
public int | addMethodref(com.sun.org.apache.bcel.internal.generic.MethodGen method)
return addMethodref(method.getClassName(), method.getName(),
method.getSignature());
|
public int | addNameAndType(java.lang.String name, java.lang.String signature)Add a new NameAndType constant to the ConstantPool if it is not already
in there.
int ret;
int name_index, signature_index;
if((ret = lookupNameAndType(name, signature)) != -1)
return ret; // Already in CP
adjustSize();
name_index = addUtf8(name);
signature_index = addUtf8(signature);
ret = index;
constants[index++] = new ConstantNameAndType(name_index, signature_index);
n_a_t_table.put(name + NAT_DELIM + signature, new Index(ret));
return ret;
|
public int | addString(java.lang.String str)Add a new String constant to the ConstantPool, if it is not already in there.
int ret;
if((ret = lookupString(str)) != -1)
return ret; // Already in CP
adjustSize();
ConstantUtf8 u8 = new ConstantUtf8(str);
ConstantString s = new ConstantString(index);
constants[index++] = u8;
ret = index;
constants[index++] = s;
string_table.put(str, new Index(ret));
return ret;
|
public int | addUtf8(java.lang.String n)Add a new Utf8 constant to the ConstantPool, if it is not already in there.
int ret;
if((ret = lookupUtf8(n)) != -1)
return ret; // Already in CP
adjustSize();
ret = index;
constants[index++] = new ConstantUtf8(n);
utf8_table.put(n, new Index(ret));
return ret;
|
protected void | adjustSize()Resize internal array of constants.
if(index + 3 >= size) {
Constant[] cs = constants;
size *= 2;
constants = new Constant[size];
System.arraycopy(cs, 0, constants, 0, index);
}
|
public com.sun.org.apache.bcel.internal.classfile.Constant | getConstant(int i) return constants[i];
|
public com.sun.org.apache.bcel.internal.classfile.ConstantPool | getConstantPool()
return new ConstantPool(constants);
|
public com.sun.org.apache.bcel.internal.classfile.ConstantPool | getFinalConstantPool()
Constant[] cs = new Constant[index];
System.arraycopy(constants, 0, cs, 0, index);
return new ConstantPool(cs);
|
public int | getSize()
return index;
|
public int | lookupClass(java.lang.String str)Look for ConstantClass in ConstantPool named `str'.
Index index = (Index)class_table.get(str.replace('.", '/"));
return (index != null)? index.index : -1;
|
public int | lookupDouble(double n)Look for ConstantDouble in ConstantPool.
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantDouble) {
ConstantDouble c = (ConstantDouble)constants[i];
if(c.getBytes() == n)
return i;
}
}
return -1;
|
public int | lookupFieldref(java.lang.String class_name, java.lang.String field_name, java.lang.String signature)Look for ConstantFieldref in ConstantPool.
Index index = (Index)cp_table.get(class_name + FIELDREF_DELIM + field_name +
FIELDREF_DELIM + signature);
return (index != null)? index.index : -1;
|
public int | lookupFloat(float n)Look for ConstantFloat in ConstantPool.
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantFloat) {
ConstantFloat c = (ConstantFloat)constants[i];
if(c.getBytes() == n)
return i;
}
}
return -1;
|
public int | lookupInteger(int n)Look for ConstantInteger in ConstantPool.
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantInteger) {
ConstantInteger c = (ConstantInteger)constants[i];
if(c.getBytes() == n)
return i;
}
}
return -1;
|
public int | lookupInterfaceMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)Look for ConstantInterfaceMethodref in ConstantPool.
Index index = (Index)cp_table.get(class_name + IMETHODREF_DELIM + method_name +
IMETHODREF_DELIM + signature);
return (index != null)? index.index : -1;
|
public int | lookupInterfaceMethodref(com.sun.org.apache.bcel.internal.generic.MethodGen method)
return lookupInterfaceMethodref(method.getClassName(), method.getName(),
method.getSignature());
|
public int | lookupLong(long n)Look for ConstantLong in ConstantPool.
for(int i=1; i < index; i++) {
if(constants[i] instanceof ConstantLong) {
ConstantLong c = (ConstantLong)constants[i];
if(c.getBytes() == n)
return i;
}
}
return -1;
|
public int | lookupMethodref(java.lang.String class_name, java.lang.String method_name, java.lang.String signature)Look for ConstantMethodref in ConstantPool.
Index index = (Index)cp_table.get(class_name + METHODREF_DELIM + method_name +
METHODREF_DELIM + signature);
return (index != null)? index.index : -1;
|
public int | lookupMethodref(com.sun.org.apache.bcel.internal.generic.MethodGen method)
return lookupMethodref(method.getClassName(), method.getName(),
method.getSignature());
|
public int | lookupNameAndType(java.lang.String name, java.lang.String signature)Look for ConstantNameAndType in ConstantPool.
Index index = (Index)n_a_t_table.get(name + NAT_DELIM + signature);
return (index != null)? index.index : -1;
|
public int | lookupString(java.lang.String str)Look for ConstantString in ConstantPool containing String `str'.
Index index = (Index)string_table.get(str);
return (index != null)? index.index : -1;
|
public int | lookupUtf8(java.lang.String n)Look for ConstantUtf8 in ConstantPool.
Index index = (Index)utf8_table.get(n);
return (index != null)? index.index : -1;
|
public void | setConstant(int i, com.sun.org.apache.bcel.internal.classfile.Constant c)Use with care! constants[i] = c;
|
public java.lang.String | toString()
StringBuffer buf = new StringBuffer();
for(int i=1; i < index; i++)
buf.append(i + ")" + constants[i] + "\n");
return buf.toString();
|