FileDocCategorySizeDatePackage
AttributeCollection.javaAPI DocAndroid 1.5 API7122Wed May 06 22:41:16 BST 2009com.vladium.jcd.cls

AttributeCollection

public final class AttributeCollection extends Object implements IAttributeCollection
author
(C) 2001, Vlad Roubtsov

Fields Summary
private List
m_attributes
private transient int
m_syntheticRefCount
private transient int
m_bridgeRefCount
private transient int
m_innerClassesAttributeOffset
private static final boolean
DISALLOW_MULTIPLE_SYNTHETIC_ATTRIBUTES
Constructors Summary
AttributeCollection(int capacity)

        m_attributes = capacity < 0 ? new ArrayList () : new ArrayList (capacity);
        m_innerClassesAttributeOffset = -1;
    
Methods Summary
public voidaccept(IClassDefVisitor visitor, java.lang.Object ctx)

        visitor.visit (this, ctx);
    
public intadd(Attribute_info attribute)

        final List/* Attribute_info */ attributes = m_attributes;
        
        final int result = attributes.size ();
        attributes.add (attribute);
        
        if (attribute instanceof SyntheticAttribute_info)
            ++ m_syntheticRefCount;
        else if (attribute instanceof InnerClassesAttribute_info)
        {
            if (m_innerClassesAttributeOffset >= 0)
                throw new IllegalArgumentException ("this attribute collection already has an InnerClasses attribute");
            
            m_innerClassesAttributeOffset = result;
        }
        else if (attribute instanceof BridgeAttribute_info)
            ++ m_bridgeRefCount;
            
        if (DISALLOW_MULTIPLE_SYNTHETIC_ATTRIBUTES && $assert.ENABLED)
            $assert.ASSERT (m_syntheticRefCount >= 0 && m_syntheticRefCount <= 1,
            "bad synthetic attribute count: " + m_syntheticRefCount);
        
        return result;
    
public java.lang.Objectclone()
Performs a deep copy.

        try
        {
            final AttributeCollection _clone = (AttributeCollection) super.clone ();
            
            // deep clone:
            
            final int attributes_count = m_attributes.size (); // use size() if this class becomes non-final
            _clone.m_attributes = new ArrayList (attributes_count);
            for (int a = 0; a < attributes_count; ++ a)
            {
                _clone.m_attributes.add (((Attribute_info) m_attributes.get (a)).clone ());
            }
            
            return _clone;
        }
        catch (CloneNotSupportedException e)
        {
            throw new InternalError (e.toString ());
        }        
    
public final Attribute_infoget(int offset)

        return (Attribute_info) m_attributes.get (offset);
    
public final InnerClassesAttribute_infogetInnerClassesAttribute()

        final int innerClassesAttributeOffset = m_innerClassesAttributeOffset;
        if (innerClassesAttributeOffset < 0)
            return null;
        else
            return (InnerClassesAttribute_info) get (innerClassesAttributeOffset);
    
public final booleanhasBridge()

        return m_bridgeRefCount > 0;
    
public final booleanhasSynthetic()

        return m_syntheticRefCount > 0;
    
public final longlength()

        // TODO: cache?
        
        long result = 2;
        
        int _attributes_count = m_attributes.size (); // use size() if this class becomes non-final
        for (int i = 0; i < _attributes_count; i++) result += get (i).length ();
        
        return result;
    
public Attribute_inforemove(int offset)

        final Attribute_info result = (Attribute_info) m_attributes.remove (offset);
        
        if (result instanceof SyntheticAttribute_info)
            -- m_syntheticRefCount;
        else if (result instanceof InnerClassesAttribute_info)
            m_innerClassesAttributeOffset = -1;
        else if (result instanceof BridgeAttribute_info)
            -- m_bridgeRefCount;
            
        if (DISALLOW_MULTIPLE_SYNTHETIC_ATTRIBUTES && $assert.ENABLED)
            $assert.ASSERT (m_syntheticRefCount >= 0 && m_syntheticRefCount <= 1,
            "bad synthetic attribute count: " + m_syntheticRefCount);
            
        return result;
    
public Attribute_infoset(int offset, Attribute_info attribute)

        final Attribute_info result = (Attribute_info) m_attributes.set (offset, attribute);
         
        if (result instanceof SyntheticAttribute_info)
            -- m_syntheticRefCount;
        else if (result instanceof InnerClassesAttribute_info)
            m_innerClassesAttributeOffset = -1;
        else if (result instanceof BridgeAttribute_info)
            -- m_bridgeRefCount;
            
        if (attribute instanceof SyntheticAttribute_info)
            ++ m_syntheticRefCount;
        else if (attribute instanceof InnerClassesAttribute_info)
            m_innerClassesAttributeOffset = offset;
        else if (attribute instanceof BridgeAttribute_info)
            ++ m_bridgeRefCount;
            
        if (DISALLOW_MULTIPLE_SYNTHETIC_ATTRIBUTES && $assert.ENABLED)
            $assert.ASSERT (m_syntheticRefCount >= 0 && m_syntheticRefCount <= 1,
            "bad synthetic attribute count: " + m_syntheticRefCount);
            
        return result; 
    
public final intsize()

        return m_attributes.size (); 
    
public voidwriteInClassFormat(com.vladium.jcd.lib.UDataOutputStream out)

        int attributes_count = size ();
        out.writeU2 (attributes_count);
        
        for (int i = 0; i < attributes_count; i++)
        {
            get (i).writeInClassFormat (out);
        }