com.vladium.jcd.cls
Class FieldCollection

java.lang.Object
  extended by com.vladium.jcd.cls.FieldCollection
All Implemented Interfaces:
IFieldCollection, IClassFormatOutput, java.lang.Cloneable

final class FieldCollection
extends java.lang.Object
implements IFieldCollection

Author:
(C) 2001, Vlad Roubtsov

Field Summary
private  java.util.List m_fields
           
 
Constructor Summary
FieldCollection(int capacity)
           
 
Method Summary
 void accept(IClassDefVisitor visitor, java.lang.Object ctx)
           
 int add(Field_info field)
          Adds a new Field_info descriptor to this collection.
 java.lang.Object clone()
          Performs a deep copy.
 int[] get(ClassDef cls, java.lang.String name)
          Returns an array of offsets for fields named 'name' (empty array if no matching fields found).
 Field_info get(int offset)
          Returns Field_info descriptor at a given offset.
 Field_info set(int offset, Field_info field)
          Replaces the Field_info descriptor at a given offset.
 int size()
          Returns the number of fields in this collection [can be 0].
 void writeInClassFormat(UDataOutputStream out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_fields

private java.util.List m_fields
Constructor Detail

FieldCollection

FieldCollection(int capacity)
Method Detail

get

public Field_info get(int offset)
Description copied from interface: IFieldCollection
Returns Field_info descriptor at a given offset.

Specified by:
get in interface IFieldCollection
Parameters:
offset - field offset [must be in [0, size()) range; input not checked]
Returns:
Field_info descriptor [never null]

get

public int[] get(ClassDef cls,
                 java.lang.String name)
Description copied from interface: IFieldCollection
Returns an array of offsets for fields named 'name' (empty array if no matching fields found). Note: even though Java syntax disallows for a class to have multiple fields with the same name it is possible at the bytecode level (as long as the type descriptors disambiguate).

Specified by:
get in interface IFieldCollection
Parameters:
cls - class definition providing the constant pool against which to resolve names [may not be null]
name - field name [null or empty will result in no matches]
Returns:
array of field offsets in no particular order [never null; could be empty]

size

public int size()
Description copied from interface: IFieldCollection
Returns the number of fields in this collection [can be 0].

Specified by:
size in interface IFieldCollection

clone

public java.lang.Object clone()
Performs a deep copy.

Specified by:
clone in interface IFieldCollection
Overrides:
clone in class java.lang.Object

writeInClassFormat

public void writeInClassFormat(UDataOutputStream out)
                        throws java.io.IOException
Specified by:
writeInClassFormat in interface IClassFormatOutput
Throws:
java.io.IOException

accept

public void accept(IClassDefVisitor visitor,
                   java.lang.Object ctx)
Specified by:
accept in interface IFieldCollection

add

public int add(Field_info field)
Description copied from interface: IFieldCollection
Adds a new Field_info descriptor to this collection. No duplicate checks are made. It is the responsibility of the caller to ensure that all data referenced in 'field' will eventually appear in the constant pool.

Specified by:
add in interface IFieldCollection
Parameters:
field - new field descriptor [may not be null]
Returns:
new field's offset

set

public Field_info set(int offset,
                      Field_info field)
Description copied from interface: IFieldCollection
Replaces the Field_info descriptor at a given offset. No duplicate checks are made. No field type compatibility checks are made. It is the responsibility of the caller to ensure that all data referenced in 'field' will eventually appear in the constant pool.

Specified by:
set in interface IFieldCollection
Parameters:
offset - field offset [must be in [0, size()) range; input not checked]
field - new field descriptor [may not be null]
Returns:
previous field descriptor at this offset [never null]