FileDocCategorySizeDatePackage
ClassDescriptor.javaAPI DocAndroid 1.5 API7023Wed May 06 22:41:16 BST 2009com.vladium.emma.data

ClassDescriptor

public final class ClassDescriptor extends Object implements com.vladium.util.IConstants, Serializable
author
Vlad Roubtsov, (C) 2003

Fields Summary
private final String
m_packageVMName
private final String
m_name
private final long
m_stamp
private final String
m_srcFileName
private final MethodDescriptor[]
m_methods
private final boolean
m_hasCompleteLineNumberInfo
private transient int
m_hash
Constructors Summary
public ClassDescriptor(String packageVMName, String name, long stamp, String srcFileName, MethodDescriptor[] methods)

        if (packageVMName == null)
            throw new IllegalArgumentException ("null input: packageVMName");
        if (name == null)
            throw new IllegalArgumentException ("null input: name");
        if (methods == null)
            throw new IllegalArgumentException ("null input: methods");
        
        if ($assert.ENABLED)
        {
            for (int m = 0; m < methods.length; ++ m)
            {
                $assert.ASSERT (methods [m] != null, "methods [" + m + "] = null (length = " + methods.length + ")");
            }
        }
        
        m_packageVMName = packageVMName;
        m_name = name;
        m_stamp = stamp;
        m_srcFileName = srcFileName;
        m_methods = methods; // TODO: defensive copy?
        
        boolean completeLineNumberInfo = true;
        for (int m = 0; m < m_methods.length; ++ m)
        {
            final MethodDescriptor method = methods [m];
            
            if (((method.getStatus () & IMetadataConstants.METHOD_NO_BLOCK_DATA) == 0) && ! m_methods [m].hasLineNumberInfo ())
            {
                completeLineNumberInfo = false;
                break;
            }
        }
        
        m_hasCompleteLineNumberInfo = completeLineNumberInfo;
    
Methods Summary
public final booleanequals(java.lang.Object rhs)

        if (! (rhs instanceof ClassDescriptor)) return false;
        
        final ClassDescriptor _rhs = (ClassDescriptor) rhs;
        
        if (hashCode () != _rhs.hashCode ()) return false;
        
        if (! m_name.equals (_rhs.m_name)) return false;
        if (! m_packageVMName.equals (_rhs.m_packageVMName)) return false;
        
        return true;
    
public final java.lang.StringgetClassVMName()

        // TODO: use Descriptors API?
        if (m_packageVMName.length () == 0)
            return m_name;
        else
            return new StringBuffer (m_packageVMName).append ("/").append (m_name).toString ();
    
public final MethodDescriptor[]getMethods()

        return m_methods; // no defensive copy
    
public final java.lang.StringgetName()

        return m_name;
    
public final java.lang.StringgetPackageVMName()

        return m_packageVMName;
    
public final java.lang.StringgetSrcFileName()

        return m_srcFileName;
    
public final longgetStamp()

        return m_stamp;
    
public final booleanhasCompleteLineNumberInfo()

        return m_hasCompleteLineNumberInfo;
    
public final booleanhasSrcFileInfo()

        return m_srcFileName != null;
    
public final inthashCode()

        if (m_hash == 0)
        {
            final int hash = m_name.hashCode () + 16661 * m_packageVMName.hashCode ();
            m_hash = hash;
            
            return hash;
        }
        
        return m_hash;
    
static com.vladium.emma.data.ClassDescriptorreadExternal(java.io.DataInput in)

        final String packageVMName = in.readUTF ();
        final String name = in.readUTF ();
        
        final long stamp = in.readLong ();
        
        final byte srcFileNameFlag = in.readByte ();
        final String srcFileName = srcFileNameFlag != 0 ? in.readUTF () : null;
        
        final int length = in.readInt ();
        final MethodDescriptor [] methods = new MethodDescriptor [length];
        for (int i = 0; i < length; ++ i)
        {
            methods [i] = MethodDescriptor.readExternal (in);
        }
        
        return new ClassDescriptor (packageVMName, name, stamp, srcFileName, methods);
    
public java.lang.StringtoString()

        return toString ("");
    
public java.lang.StringtoString(java.lang.String indent)

        StringBuffer s = new StringBuffer (indent + "class [" + (m_packageVMName.length () > 0 ? m_packageVMName + "/" : "") + m_name + "] descriptor:");
        
        for (int m = 0; m < m_methods.length; ++ m)
        {
            s.append (EOL);
            s.append (m_methods [m].toString (indent + INDENT_INCREMENT));
        }
        
        return s.toString ();
    
static voidwriteExternal(com.vladium.emma.data.ClassDescriptor cls, java.io.DataOutput out)

        out.writeUTF (cls.m_packageVMName);
        out.writeUTF (cls.m_name);
        
        out.writeLong (cls.m_stamp);
        
        if (cls.m_srcFileName != null)
        {
            out.writeByte (1);
            out.writeUTF (cls.m_srcFileName);
        }
        else
        {
            out.writeByte (0);
        }
        
        final MethodDescriptor [] methods = cls.m_methods;
        final int length = methods.length;
        out.writeInt (length);
        for (int i = 0; i < length; ++ i)
        {
            MethodDescriptor.writeExternal (methods [i], out);
        }
        
        // [m_hash and m_hasCompleteLineNumberInfo are transient data]