jawa.constants module

class jawa.constants.Constant(pool, index)[source]

Bases: object

The base class for all Constant* types.

index
pool
class jawa.constants.ConstantClass(pool, index, name_index)[source]

Bases: jawa.constants.Constant

TAG = 7
name
name_index
pack()[source]
class jawa.constants.ConstantPool[source]

Bases: object

append(constant)[source]

Appends a new constant to the end of the pool.

create_class(name: str) → jawa.constants.ConstantClass[source]

Creates a new ConstantClass, adding it to the pool and returning it.

Parameters:name – The name of the new class.
create_double(value: float) → jawa.constants.Double[source]

Creates a new ConstantDouble, adding it to the pool and returning it.

Parameters:value – The value of the new Double.
create_field_ref(class_: str, field: str, descriptor: str) → jawa.constants.FieldReference[source]

Creates a new ConstantFieldRef, adding it to the pool and returning it.

Parameters:
  • class – The name of the class to which field belongs.
  • field – The name of the field.
  • descriptor – The descriptor for field.
create_float(value: float) → jawa.constants.Float[source]

Creates a new ConstantFloat, adding it to the pool and returning it.

Parameters:value – The value of the new float.
create_integer(value: int) → jawa.constants.Integer[source]

Creates a new ConstantInteger, adding it to the pool and returning it.

Parameters:value – The value of the new integer.
create_interface_method_ref(class_: str, if_method: str, descriptor: str) → jawa.constants.InterfaceMethodRef[source]

Creates a new ConstantInterfaceMethodRef, adding it to the pool and returning it.

Parameters:
  • class – The name of the class to which if_method belongs.
  • if_method – The name of the interface method.
  • descriptor – The descriptor for if_method.
create_long(value: int) → jawa.constants.Long[source]

Creates a new ConstantLong, adding it to the pool and returning it.

Parameters:value – The value of the new long.
create_method_ref(class_: str, method: str, descriptor: str) → jawa.constants.MethodReference[source]

Creates a new ConstantMethodRef, adding it to the pool and returning it.

Parameters:
  • class – The name of the class to which method belongs.
  • method – The name of the method.
  • descriptor – The descriptor for method.
create_name_and_type(name: str, descriptor: str) → jawa.constants.NameAndType[source]

Creates a new ConstantNameAndType, adding it to the pool and returning it.

Parameters:
  • name – The name of the class.
  • descriptor – The descriptor for name.
create_string(value: str) → jawa.constants.String[source]

Creates a new ConstantString, adding it to the pool and returning it.

Parameters:value – The value of the new string as a UTF8 string.
create_utf8(value)[source]

Creates a new ConstantUTF8, adding it to the pool and returning it.

Parameters:value – The value of the new UTF8 string.
find(type_=None, f=None)[source]

Iterates over the pool, yielding each matching Constant. Calling without any arguments is equivalent to iterating over the pool.

Parameters:
  • type – Any subclass of Constant or None.
  • f – Any callable which takes one argument (the constant).
find_one(*args, **kwargs)[source]

Same as find() but returns only the first result, or None if nothing was found.

get(index)[source]

Returns the Constant at index, raising a KeyError if it does not exist.

pack(fout)[source]

Write the ConstantPool to the file-like object fout.

Note

Advanced usage only. You will typically never need to call this method as it will be calle=d for you when saving a ClassFile.

Parameters:fout – Any file-like object providing write()
raw_count

The number of Constants in the ConstantPool, including padding.

unpack(fio)[source]

Read the ConstantPool 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:fio – Any file-like object providing read()
class jawa.constants.Double(pool, index, value)[source]

Bases: jawa.constants.Number

TAG = 6
pack()[source]
class jawa.constants.FieldReference(pool, index, class_index, name_and_type_index)[source]

Bases: jawa.constants.Reference

TAG = 9
class jawa.constants.Float(pool, index, value)[source]

Bases: jawa.constants.Number

TAG = 4
pack()[source]
class jawa.constants.Integer(pool, index, value)[source]

Bases: jawa.constants.Number

TAG = 3
pack()[source]
class jawa.constants.InterfaceMethodRef(pool, index, class_index, name_and_type_index)[source]

Bases: jawa.constants.Reference

TAG = 11
class jawa.constants.InvokeDynamic(pool, index, bootstrap_method_attr_index, name_and_type_index)[source]

Bases: jawa.constants.Constant

TAG = 18
bootstrap_method_attr_index
method_attr_index
name_and_type
name_and_type_index
pack()[source]
class jawa.constants.Long(pool, index, value)[source]

Bases: jawa.constants.Number

TAG = 5
pack()[source]
class jawa.constants.MethodHandle(pool, index, reference_kind, reference_index)[source]

Bases: jawa.constants.Constant

TAG = 15
pack()[source]
reference
reference_index
reference_kind
class jawa.constants.MethodReference(pool, index, class_index, name_and_type_index)[source]

Bases: jawa.constants.Reference

TAG = 10
class jawa.constants.MethodType(pool, index, descriptor_index)[source]

Bases: jawa.constants.Constant

TAG = 16
descriptor
descriptor_index
pack()[source]
class jawa.constants.Module(pool, index, name_index)[source]

Bases: jawa.constants.ConstantClass

TAG = 19
name_index
class jawa.constants.NameAndType(pool, index, name_index, descriptor_index)[source]

Bases: jawa.constants.Constant

TAG = 12
descriptor
descriptor_index
name
name_index
pack()[source]
class jawa.constants.Number(pool, index, value)[source]

Bases: jawa.constants.Constant

value
class jawa.constants.PackageInfo(pool, index, name_index)[source]

Bases: jawa.constants.ConstantClass

TAG = 20
name_index
class jawa.constants.Reference(pool, index, class_index, name_and_type_index)[source]

Bases: jawa.constants.Constant

TAG = None
class_
class_index
name_and_type
name_and_type_index
pack()[source]
class jawa.constants.String(pool, index, string_index)[source]

Bases: jawa.constants.Constant

TAG = 8
pack()[source]
string
string_index
class jawa.constants.UTF8(pool, index, value)[source]

Bases: jawa.constants.Constant

TAG = 1
pack()[source]
value