Methods Summary |
---|
public ConstClass | addClass(java.lang.String className)Find or create a class constant in the pool
hashConstants();
ConstClass c = (ConstClass) classTable.get(className);
if (c == null) {
c = new ConstClass(addUtf8(className));
internConstant(c);
}
return c;
|
public ConstDouble | addDouble(double d)Find or create a double constant in the pool
hashConstants();
Double dobj = new Double(d);
ConstDouble cd = (ConstDouble) doubleTable.get(dobj);
if (cd == null) {
cd = new ConstDouble(d);
internConstant(cd);
internConstant(null);
}
return cd;
|
public ConstFieldRef | addFieldRef(java.lang.String className, java.lang.String fieldName, java.lang.String type)Find or create a field constant in the pool
hashConstants();
ConstFieldRef f = (ConstFieldRef)
searchTable(fieldRefTable, className, fieldName, type);
if (f == null) {
f = new ConstFieldRef (addClass(className),
addNameAndType(fieldName, type));
internConstant(f);
}
return f;
|
public ConstFloat | addFloat(float f)Find or create a float constant in the pool
hashConstants();
Float fo = new Float(f);
ConstFloat cf = (ConstFloat) floatTable.get(fo);
if (cf == null) {
cf = new ConstFloat(f);
internConstant(cf);
}
return cf;
|
public ConstInteger | addInteger(int i)Find or create an integer constant in the pool
hashConstants();
Integer io = new Integer(i);
ConstInteger ci = (ConstInteger) intTable.get(io);
if (ci == null) {
ci = new ConstInteger(i);
internConstant(ci);
}
return ci;
|
public ConstInterfaceMethodRef | addInterfaceMethodRef(java.lang.String className, java.lang.String methodName, java.lang.String type)Find or create an interface method constant in the pool
hashConstants();
ConstInterfaceMethodRef m = (ConstInterfaceMethodRef)
searchTable(ifaceMethodRefTable, className, methodName, type);
if (m == null) {
m = new ConstInterfaceMethodRef (addClass(className),
addNameAndType(methodName, type));
internConstant(m);
}
return m;
|
public ConstLong | addLong(long l)Find or create a long constant in the pool
hashConstants();
Long lo = new Long(l);
ConstLong cl = (ConstLong) longTable.get(lo);
if (cl == null) {
cl = new ConstLong(l);
internConstant(cl);
internConstant(null);
}
return cl;
|
public ConstMethodRef | addMethodRef(java.lang.String className, java.lang.String methodName, java.lang.String type)Find or create a method constant in the pool
hashConstants();
ConstMethodRef m = (ConstMethodRef)
searchTable(methodRefTable, className, methodName, type);
if (m == null) {
m = new ConstMethodRef (addClass(className),
addNameAndType(methodName, type));
internConstant(m);
}
return m;
|
public ConstNameAndType | addNameAndType(java.lang.String name, java.lang.String type)Find or create a name/type constant in the pool
hashConstants();
for (int i=0; i<nameAndTypeTable.size(); i++) {
ConstNameAndType nt = (ConstNameAndType) nameAndTypeTable.elementAt(i);
if (nt.name().asString().equals(name) &&
nt.signature().asString().equals(type))
return nt;
}
ConstNameAndType nt =
new ConstNameAndType(addUtf8(name), addUtf8(type));
internConstant(nt);
return nt;
|
public ConstString | addString(java.lang.String s)Find or create a string constant in the pool
hashConstants();
ConstString cs = (ConstString) stringTable.get(s);
if (cs == null) {
cs = new ConstString(addUtf8(s));
internConstant(cs);
}
return cs;
|
public ConstUnicode | addUnicode(java.lang.String s)Find or create a unicode constant in the pool
Obsolete?
hashConstants();
ConstUnicode u = (ConstUnicode) unicodeTable.get(s);
if (u == null) {
u = new ConstUnicode(s);
internConstant(u);
}
return u;
|
public ConstUtf8 | addUtf8(java.lang.String s)Find or create a utf8 constant in the pool
hashConstants();
ConstUtf8 u = (ConstUtf8) utfTable.get(s);
if (u == null) {
u = new ConstUtf8(s);
internConstant(u);
}
return u;
|
public ConstBasic | constantAt(int index)Return the constant in the pool at the specified entry index
return (ConstBasic) pool.elementAt(index);
|
private void | hashConstants()
if (hashed)
return;
/* Enter objects into the hash tables */
for (int j=0; j<pool.size(); j++) {
ConstBasic c = constantAt(j);
if (c != null) {
recordConstant(c);
}
}
hashed = true;
|
private void | internConstant(ConstBasic c)
if (c != null) {
c.setIndex(pool.size());
recordConstant(c);
}
pool.addElement(c);
|
public int | nEntries()Return the number of pool entries.
/* public accessors */
return pool.size();
|
void | print(java.io.PrintStream out)
for (int i=0; i<pool.size(); i++) {
ConstBasic c = constantAt(i);
if (c != null) {
out.print (i);
out.print (": ");//NOI18N
out.println (c.toString());
}
}
|
private int | readConstant(java.io.DataInputStream input)
ConstBasic basic;
byte b = input.readByte();
int slots = 1;
switch (b) {
case CONSTANTUtf8:
basic = ConstUtf8.read(input);
break;
case CONSTANTUnicode:
basic = ConstUnicode.read(input);
break;
case CONSTANTInteger:
basic = ConstInteger.read(input);
break;
case CONSTANTFloat:
basic = ConstFloat.read(input);
break;
case CONSTANTLong:
basic = ConstLong.read(input);
slots = 2;
break;
case CONSTANTDouble:
basic = ConstDouble.read(input);
slots = 2;
break;
case CONSTANTClass:
basic = ConstClass.read(input);
break;
case CONSTANTString:
basic = ConstString.read(input);
break;
case CONSTANTFieldRef:
basic = ConstFieldRef.read(input);
break;
case CONSTANTMethodRef:
basic = ConstMethodRef.read(input);
break;
case CONSTANTInterfaceMethodRef:
basic = ConstInterfaceMethodRef.read(input);
break;
case CONSTANTNameAndType:
basic = ConstNameAndType.read(input);
break;
default:
throw new ClassFormatError("Don't know this constant type: " +//NOI18N
Integer.toString(b));
}
pool.addElement(basic);
if (slots > 1)
pool.addElement(null);
return slots;
|
private void | recordConstant(ConstBasic c)
if (c != null) {
switch (c.tag()) {
case CONSTANTUtf8:
utfTable.put(((ConstUtf8)c).asString(), c);
break;
case CONSTANTUnicode:
unicodeTable.put(((ConstUnicode)c).asString(), c);
break;
case CONSTANTInteger:
intTable.put(new Integer(((ConstInteger)c).value()), c);
break;
case CONSTANTFloat:
floatTable.put(new Float(((ConstFloat)c).value()), c);
break;
case CONSTANTLong:
longTable.put(new Long(((ConstLong)c).value()), c);
break;
case CONSTANTDouble:
doubleTable.put(new Double(((ConstDouble)c).value()), c);
break;
case CONSTANTClass:
classTable.put(((ConstClass)c).asString(), c);
break;
case CONSTANTString:
stringTable.put(((ConstString)c).value().asString(), c);
break;
case CONSTANTFieldRef:
fieldRefTable.addElement(c);
break;
case CONSTANTMethodRef:
methodRefTable.addElement(c);
break;
case CONSTANTInterfaceMethodRef:
ifaceMethodRefTable.addElement(c);
break;
case CONSTANTNameAndType:
nameAndTypeTable.addElement(c);
break;
}
}
|
private void | resolvePool()
/* resolve indexes to object references */
for (int i=0; i<pool.size(); i++) {
ConstBasic c = constantAt(i);
if (c != null) {
c.setIndex(i);
c.resolve(this);
}
}
|
private ConstBasicMemberRef | searchTable(java.util.Vector table, java.lang.String cname, java.lang.String mname, java.lang.String sig)
for (int i=0; i<table.size(); i++) {
ConstBasicMemberRef memRef = (ConstBasicMemberRef) table.elementAt(i);
if (memRef.className().asString().equals(cname) &&
memRef.nameAndType().name().asString().equals(mname) &&
memRef.nameAndType().signature().asString().equals(sig))
return memRef;
}
return null;
|
void | summarize()
int stringSize = 0;
int nStrings = 0;
for (int i=0; i<pool.size(); i++) {
ConstBasic c = constantAt(i);
if (c != null && c.tag() == CONSTANTUtf8) {
ConstUtf8 utf8 = (ConstUtf8) c;
stringSize += utf8.asString().length();
nStrings++;
}
}
System.out.println(" " + nStrings + " strings totalling " + //NOI18N
stringSize + " bytes");//NOI18N
|
void | write(java.io.DataOutputStream buff)
buff.writeShort(pool.size());
for (int i=1; i<pool.size(); i++) {
ConstBasic cb = (ConstBasic) pool.elementAt(i);
if (cb != null) {
buff.writeByte((byte) cb.tag());
cb.formatData(buff);
}
}
|