FileDocCategorySizeDatePackage
ClassFile.javaAPI DocApache Ant 1.704261Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.depend

ClassFile

public class ClassFile extends Object
A ClassFile object stores information about a Java class. The class may be read from a DataInputStream.and written to a DataOutputStream. These are usually streams from a Java class file or a class file component of a Jar file.

Fields Summary
private static final int
CLASS_MAGIC
The Magic Value that marks the start of a Java class file
private org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool
constantPool
This class' constant pool.
private String
className
The class name for this class.
Constructors Summary
Methods Summary
public java.util.VectorgetClassRefs()
Get the classes which this class references.

return
a vector of class names which this class references


        Vector classRefs = new Vector();

        for (int i = 0; i < constantPool.size(); ++i) {
            ConstantPoolEntry entry = constantPool.getEntry(i);

            if (entry != null
                && entry.getTag() == ConstantPoolEntry.CONSTANT_CLASS) {
                ClassCPInfo classEntry = (ClassCPInfo) entry;

                if (!classEntry.getClassName().equals(className)) {
                    classRefs.addElement(
                        ClassFileUtils.convertSlashName(classEntry.getClassName()));
                }
            }
        }

        return classRefs;
    
public java.lang.StringgetFullClassName()
Get the class' fully qualified name in dot format.

return
the class name in dot format (eg. java.lang.Object)

        return ClassFileUtils.convertSlashName(className);
    
public voidread(java.io.InputStream stream)
Read the class from a data stream. This method takes an InputStream as input and parses the class from the stream.

param
stream an InputStream from which the class will be read
exception
IOException if there is a problem reading from the given stream.
exception
ClassFormatError if the class cannot be parsed correctly


                                                                    
           
        DataInputStream classStream = new DataInputStream(stream);

        if (classStream.readInt() != CLASS_MAGIC) {
            throw new ClassFormatError("No Magic Code Found "
                + "- probably not a Java class file.");
        }

        // right we have a good looking class file.
        /* int minorVersion = */ classStream.readUnsignedShort();
        /* int majorVersion = */ classStream.readUnsignedShort();

        // read the constant pool in and resolve it
        constantPool = new ConstantPool();

        constantPool.read(classStream);
        constantPool.resolve();

        /* int accessFlags = */ classStream.readUnsignedShort();
        int thisClassIndex = classStream.readUnsignedShort();
        /* int superClassIndex = */ classStream.readUnsignedShort();
        ClassCPInfo classInfo
            = (ClassCPInfo) constantPool.getEntry(thisClassIndex);
        className  = classInfo.getClassName();