jawa.fields module¶
-
class
jawa.fields.
Field
(cf)[source]¶ Bases:
object
-
descriptor
¶ The UTF8 Constant containing the field’s descriptor.
-
name
¶ The UTF8 Constant containing the field’s name.
-
pack
(out: IO)[source]¶ Write the Field to the file-like object out.
Note
Advanced usage only. You will typically never need to call this method as it will be called for you when saving a ClassFile.
Parameters: out – Any file-like object providing write()
-
unpack
(source: IO)[source]¶ Read the Field from the file-like object fio.
Note
Advanced usage only. You will typically never need to call this method as it will be called for you when loading a ClassFile.
Parameters: source – Any file-like object providing read()
-
value
¶ A shortcut for the field’s ConstantValue attribute, should one exist.
-
-
class
jawa.fields.
FieldTable
(cf)[source]¶ Bases:
object
-
create
(name: str, descriptor: str, value: jawa.constants.Constant = None) → jawa.fields.Field[source]¶ Creates a new field from name and descriptor. For example:
>>> from jawa.cf import ClassFile >>> cf = ClassFile.create('BeerCounter') >>> field = cf.fields.create('BeerCount', 'I')
To automatically create a static field, pass a value:
>>> from jawa.cf import ClassFile >>> cf = ClassFile.create('BeerCounter') >>> field = cf.fields.create( ... 'MaxBeer', ... 'I', ... cf.constants.create_integer(99) ... )
Parameters: - name – Name of the new field.
- descriptor – Type descriptor of the new field.
- value – Optional static value for the field.
-
find
(*, name: str = None, type_: str = None, f: Callable = None) → Iterator[jawa.fields.Field][source]¶ Iterates over the fields table, yielding each matching method. Calling without any arguments is equivalent to iterating over the table.
Parameters: - name – The name of the field(s) to find.
- type – The field descriptor (Ex: ‘I’)
- f – Any callable which takes one argument (the field).
-
find_one
(**kwargs) → Union[jawa.fields.Field, NoneType][source]¶ Same as
find()
but returns only the first result.
-