Methods Summary |
---|
public int | access()Return the access flags for the class - see VMConstants
return accessFlags;
|
public void | addField(ClassField field)Add a field to the list of the fields which the class contains
classFields.addElement(field);
|
public void | addField(ClassField field, int index)Add a field to the list of the fields which the class contains,
at the index'th position.
classFields.insertElementAt(field, index);
|
public void | addInterface(ConstClass iface)Add an interface to the list of the interfaces which the class implements
classInterfaces.addElement(iface);
|
public void | addMethod(ClassMethod method)Add a method to the list of the methods which the class defines
classMethods.addElement(method);
|
public AttributeVector | attributes()Return the list of the attributes associated with the class
return classAttributes;
|
public ConstClass | className()Return the name of the class
return thisClassName;
|
private static java.util.List | convertMajorMinorVersions(short[][] majorMinor)
int length = majorMinor.length;
List result = new ArrayList(length);
for (int i = 0; i < length; i++) {
result.add(getVersionInt(majorMinor[i][0], majorMinor[i][1]));
}
return result;
|
public java.util.Vector | fields()Return the list of the fields which the class contains
The contents are ClassField objects
return classFields;
|
public ClassField | findField(java.lang.String fieldName)Look for a field with the specified name
for (Enumeration e = fields().elements(); e.hasMoreElements();) {
ClassField field = (ClassField) e.nextElement();
if (field.name().asString().equals(fieldName))
return field;
}
return null;
|
public ClassMethod | findMethod(java.lang.String methodName, java.lang.String methodSig)Look for a method with the specified name and type signature
for (Enumeration e = methods().elements(); e.hasMoreElements();) {
ClassMethod method = (ClassMethod) e.nextElement();
if (method.name().asString().equals(methodName) &&
method.signature().asString().equals(methodSig))
return method;
}
return null;
|
public byte[] | getBytes()Returns a byte array representation of this class.
/* Write the class bytes to a file, for debugging. */
String writeClassToDirectory =
System.getProperty("filter.writeClassToDirectory");
if (writeClassToDirectory != null) {
String filename = writeClassToDirectory + java.io.File.separator +
thisClassName.asString() + ".class";//NOI18N
System.err.println("Writing class to file " + filename);
DataOutputStream stream = new DataOutputStream(
new java.io.FileOutputStream(filename));
write(stream);
stream.close();
}
/* Get the class bytes and return them. */
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
write(new DataOutputStream(byteStream));
return byteStream.toByteArray();
|
private static java.lang.Integer | getVersionInt(short major, short minor)
return new Integer(major * 65536 + minor);
|
public java.util.Vector | interfaces()Return the list of the interfaces which the class implements
The contents are ConstClass objects
return classInterfaces;
|
public final boolean | isAbstract()Is the class abstract?
return (accessFlags & ACCAbstract) != 0;
|
public final boolean | isFinal()Is the class final?
return (accessFlags & ACCFinal) != 0;
|
public final boolean | isInterface()Is the class an interface?
return (accessFlags & ACCInterface) != 0;
|
public final boolean | isPublic()Is the class public?
return (accessFlags & ACCPublic) != 0;
|
private static boolean | isSupportedVersion(short major, short minor)
Integer version = getVersionInt(major, minor);
return jdkVersions.contains(version);
|
public java.util.Vector | methods()Return the list of the methods which the class defines
The contents are ClassMethod objects
return classMethods;
|
public ConstantPool | pool()Return the constant pool for the class file
/* public accessors */
return constantPool;
|
public void | print(java.io.PrintStream out)
constantPool.print(out);
out.println();
out.println("majorVersion = " + Integer.toString(majorVersion));//NOI18N
out.println("minorVersion = " + Integer.toString(minorVersion));//NOI18N
out.println("accessFlags = " + Integer.toString(accessFlags));//NOI18N
out.println("className = " + thisClassName.asString());//NOI18N
out.println("superClassName = " + superClassName.asString());//NOI18N
out.print("Interfaces =");//NOI18N
for (int i=0; i<classInterfaces.size(); i++) {
out.print(" " + ((ConstClass) classInterfaces.elementAt(i)).asString());//NOI18N
}
out.println();
out.println("fields =");//NOI18N
for (int i=0; i<classFields.size(); i++) {
((ClassField) classFields.elementAt(i)).print(out, 3);
}
out.println("methods =");//NOI18N
for (int i=0; i<classMethods.size(); i++) {
((ClassMethod) classMethods.elementAt(i)).print(out, 3);
}
out.println("attributes =");//NOI18N
classAttributes.print(out, 3);
|
public static final java.lang.String | printSupportedVersions()
StringBuffer buf = new StringBuffer("{"); //NOI18N
int length = jdkMajorMinorVersions.length;
for (int i = 0; i < length; i++) {
int major = jdkMajorMinorVersions[i][0];
int minor = jdkMajorMinorVersions[i][1];
buf.append("{"); //NOI18N
buf.append(major);
buf.append(","); //NOI18N
buf.append(minor);
buf.append("}"); //NOI18N
}
buf.append("}"); //NOI18N
return buf.toString();
|
private void | readConstants(java.io.DataInputStream data)
constantPool = new ConstantPool(data);
|
private void | readFields(java.io.DataInputStream data)
int nFields = data.readUnsignedShort();
while (nFields-- > 0) {
classFields.addElement (ClassField.read(data, constantPool));
}
|
private void | readInterfaces(java.io.DataInputStream data)
int nInterfaces = data.readUnsignedShort();
while (nInterfaces-- > 0) {
int interfaceIndex = data.readUnsignedShort();
ConstClass ci = null;
if (interfaceIndex != 0)
ci = (ConstClass) constantPool.constantAt(interfaceIndex);
classInterfaces.addElement(ci);
}
|
private void | readMethods(java.io.DataInputStream data)
int nMethods = data.readUnsignedShort();
while (nMethods-- > 0) {
classMethods.addElement (ClassMethod.read(data, constantPool));
}
|
public void | setAccessFlags(int flags)Set the access flags for the class - see VMConstants
accessFlags = flags;
|
public void | setSuperName(ConstClass superCl)Set the name of the super class
superClassName = superCl;
|
public void | summarize()
PrintStream os = System.out;
constantPool.summarize();
int codeSize = 0;
for (int i=0; i<classMethods.size(); i++) {
codeSize += ((ClassMethod) classMethods.elementAt(i)).codeSize();
}
System.out.println(classMethods.size() + " methods in " + codeSize + " bytes");//NOI18N
|
public ConstClass | superName()Return the name of the super class
return superClassName;
|
public java.lang.String | superNameString()Return the name of the super class as a string
return (superClassName == null) ? null : superClassName.asString();
|
public void | write(java.io.DataOutputStream buff)Write the Class file to the data output stream
buff.writeInt(magic);
buff.writeShort(minorVersion);
buff.writeShort(majorVersion);
constantPool.write(buff);
buff.writeShort(accessFlags);
buff.writeShort(thisClassName.getIndex());
//@lars: superclass may be null (java.lang.Object); VMSpec 2nd ed., section 4.1
buff.writeShort(superClassName == null ? 0 : superClassName.getIndex());
// buff.writeShort(superClassName.getIndex());
writeInterfaces(buff);
writeFields(buff);
writeMethods(buff);
classAttributes.write(buff);
|
private void | writeFields(java.io.DataOutputStream data)
data.writeShort(classFields.size());
for (int i=0; i<classFields.size(); i++)
((ClassField)classFields.elementAt(i)).write(data);
|
private void | writeInterfaces(java.io.DataOutputStream data)
data.writeShort(classInterfaces.size());
for (int i=0; i<classInterfaces.size(); i++) {
ConstClass ci = (ConstClass) classInterfaces.elementAt(i);
int interfaceIndex = 0;
if (ci != null)
interfaceIndex = ci.getIndex();
data.writeShort(interfaceIndex);
}
|
private void | writeMethods(java.io.DataOutputStream data)
data.writeShort(classMethods.size());
for (int i=0; i<classMethods.size(); i++)
((ClassMethod)classMethods.elementAt(i)).write(data);
|