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

MetaData

public final class MetaData extends Object implements IMetaData, Cloneable
author
Vlad Roubtsov, (C) 2003

Fields Summary
private final CoverageOptions
m_options
private boolean
m_hasSrcFileInfo
private boolean
m_hasLineNumberInfo
private HashMap
m_classMap
private transient HashSet
m_packagesWarned
Constructors Summary
MetaData(CoverageOptions options)

        if ($assert.ENABLED) $assert.ASSERT (options != null, "options is null");
        m_options = options;
        
        m_hasSrcFileInfo = true;
        m_hasLineNumberInfo = true;
        
        m_classMap = new HashMap ();
        m_packagesWarned = new HashSet ();
    
private MetaData(CoverageOptions options, HashMap classMap, boolean hasSrcFileInfo, boolean hasLineNumberInfo)

        if ($assert.ENABLED) $assert.ASSERT (options != null, "options is null");
        m_options = options;
        
        m_hasSrcFileInfo = hasSrcFileInfo;
        m_hasLineNumberInfo = hasLineNumberInfo;
        
        m_classMap = classMap;
    
Methods Summary
public booleanadd(ClassDescriptor cls, boolean overwrite)

        if ($assert.ENABLED) $assert.ASSERT (cls != null, "cls is null");
        
        final String classVMName = cls.getClassVMName ();
        
        if (overwrite || ! m_classMap.containsKey (classVMName))
        {
            m_classMap.put (classVMName, cls);
            
            boolean incompleteDebugInfo = false;

            if (! cls.hasSrcFileInfo ())
            {
                m_hasSrcFileInfo = false;
                incompleteDebugInfo = true;
            }
            
            if (! cls.hasCompleteLineNumberInfo ())
            {
                m_hasLineNumberInfo = false;
                incompleteDebugInfo = true;
            }
            
            // SF FR 971176: provide user with sample classes that may later
            // caused warnings about line coverage not available
            
            if (incompleteDebugInfo)
            {
                final Logger log = Logger.getLogger ();
                
                if (log.atINFO ())
                {
                    final String packageVMName = cls.getPackageVMName ();
                    
                    if (m_packagesWarned.add (packageVMName))
                    {
                        log.info ("package [" + packageVMName + "] contains classes [" + cls.getName () + "] without full debug info");
                    }
                }
            }
            
            return true;
        }

        return false;
    
public CoverageOptionsgetOptions()

        return m_options;
    
public booleanhasDescriptor(java.lang.String classVMName)

        if ($assert.ENABLED) $assert.ASSERT (classVMName != null, "className is null");
        
        return m_classMap.containsKey (classVMName);
    
public booleanhasLineNumberData()

        return m_hasLineNumberInfo;
    
public booleanhasSrcFileData()

        return m_hasSrcFileInfo;
    
public booleanisEmpty()

        return m_classMap.isEmpty ();
    
public java.util.Iteratoriterator()

        return m_classMap.values ().iterator ();
    
public java.lang.Objectlock()

        return m_classMap;
    
public IMergeablemerge(IMergeable rhs)

        if ((rhs == null) || rhs.isEmpty () || (rhs == this))
            return this;
        else
        {
            final MetaData rhsmdata = (MetaData) rhs; // TODO: redesign to avoid this cast?
            final Map rhsclasses = rhsmdata.m_classMap;
            
            // rhs entries always override existing content:
            
            for (Iterator entries = rhsclasses.entrySet ().iterator (); entries.hasNext (); )
            {
                final Map.Entry entry = (Map.Entry) entries.next ();
                
                final String classVMName = (String) entry.getKey ();
                final Object rhsdescriptor = entry.getValue ();
                    
                m_classMap.put (classVMName, rhsdescriptor);
            }
            
            // update debug info flags if necessary:
            
            if (! rhsmdata.hasSrcFileData ()) m_hasSrcFileInfo = false;
            if (! rhsmdata.hasLineNumberData ()) m_hasLineNumberInfo = false;
                
            return this;
        }
    
static com.vladium.emma.data.MetaDatareadExternal(java.io.DataInput in)

        final CoverageOptions options = CoverageOptions.readExternal (in);
        
        final boolean hasSrcFileInfo = in.readBoolean ();
        final boolean hasLineNumberInfo = in.readBoolean ();
        
        final int size = in.readInt ();
        final HashMap classMap = new HashMap (size);
        
        for (int i = 0; i < size; ++ i)
        {
            final String classVMName = in.readUTF ();
            final ClassDescriptor cls = ClassDescriptor.readExternal (in);
            
            classMap.put (classVMName, cls);
        }
        
        // [m_packagesWarned is not part of persisted state]
        
        return new MetaData (options, classMap, hasSrcFileInfo, hasLineNumberInfo);
    
public IMetaDatashallowCopy()

        final MetaData _clone;
        try
        {
            _clone = (MetaData) super.clone ();
        }
        catch (CloneNotSupportedException cnse)
        {
            throw new Error (cnse.toString ());
        }
        
        final HashMap _classMap;
        
        synchronized (lock ())
        {
            _classMap = (HashMap) m_classMap.clone ();
        }
        
        // [m_packagesWarned is not cloned by design]
        
        _clone.m_classMap = _classMap;
        
        return _clone;  
    
public intsize()

        return m_classMap.size (); 
    
static voidwriteExternal(com.vladium.emma.data.MetaData mdata, java.io.DataOutput out)

        CoverageOptions.writeExternal (mdata.m_options, out);
        
        out.writeBoolean (mdata.m_hasSrcFileInfo);
        out.writeBoolean (mdata.m_hasLineNumberInfo);
        
        final Map classMap = mdata.m_classMap;
        
        final int size = classMap.size ();
        out.writeInt (size); // too bad the capacity is not visible
        
        final Iterator entries = classMap.entrySet ().iterator ();
        for (int i = 0; i < size; ++ i)
        {
            final Map.Entry entry = (Map.Entry) entries.next ();
            
            final String classVMName = (String) entry.getKey ();
            final ClassDescriptor cls = (ClassDescriptor) entry.getValue ();
            
            out.writeUTF (classVMName);
            ClassDescriptor.writeExternal (cls, out);
        }
        
        // [m_packagesWarned is not part of persisted state]