com.vladium.jcd.cls
Interface IFieldCollection

All Superinterfaces:
java.lang.Cloneable, IClassFormatOutput
All Known Implementing Classes:
FieldCollection

public interface IFieldCollection
extends java.lang.Cloneable, IClassFormatOutput

An abstraction of the 'fields' component of .class format. The contents are Field_info structures corresponding to all fields directly declared by this class/interface. The order in which they appear is unspecified.

Author:
(C) 2001, Vlad Roubtsov

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()
           
 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].
 
Methods inherited from interface com.vladium.jcd.compiler.IClassFormatOutput
writeInClassFormat
 

Method Detail

get

Field_info get(int offset)
Returns Field_info descriptor at a given offset.

Parameters:
offset - field offset [must be in [0, size()) range; input not checked]
Returns:
Field_info descriptor [never null]
Throws:
java.lang.IndexOutOfBoundsException - if 'offset' is outside of valid range

get

int[] get(ClassDef cls,
          java.lang.String name)
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).

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]
Throws:
java.lang.IllegalArgumentException - if 'cls' is null

size

int size()
Returns the number of fields in this collection [can be 0].


clone

java.lang.Object clone()

accept

void accept(IClassDefVisitor visitor,
            java.lang.Object ctx)

add

int add(Field_info field)
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.

Parameters:
field - new field descriptor [may not be null]
Returns:
new field's offset

set

Field_info set(int offset,
               Field_info field)
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.

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]
Throws:
java.lang.IndexOutOfBoundsException - if 'offset' is outside of valid range