jawa.methods module

class jawa.methods.Method(cf)[source]

Bases: object

args

A list of JVMType representing the method’s argument list.

code

A shortcut for method.attributes.find_one(name='Code').

descriptor

The UTF8 Constant containing the method’s descriptor.

name

The UTF8 Constant containing the method’s name.

pack(out: IO)[source]

Write the Method 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()
returns

A JVMType representing the method’s return type.

unpack(source: IO)[source]

Read the Method 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()
class jawa.methods.MethodTable(cf)[source]

Bases: object

append(method: jawa.methods.Method)[source]
create(name: str, descriptor: str, code: jawa.attributes.code.CodeAttribute = None) → jawa.methods.Method[source]

Creates a new method from name and descriptor. If code is not None, add a Code attribute to this method.

find(*, name: str = None, args: str = None, returns: str = None, f: Callable = None) → Iterator[jawa.methods.Method][source]

Iterates over the methods table, yielding each matching method. Calling without any arguments is equivalent to iterating over the table. For example, to get all methods that take three integers and return void:

for method in cf.methods.find(args='III', returns='V'):
    print(method.name.value)

Or to get all private methods:

is_private = lambda m: m.access_flags.acc_private
for method in cf.methods.find(f=is_private):
    print method.name.value
Parameters:
  • name – The name of the method(s) to find.
  • args – The arguments descriptor (ex: III)
  • returns – The returns descriptor (Ex: V)
  • f – Any callable which takes one argument (the method).
find_and_remove(f: Callable)[source]

Removes any and all methods for which f(method) returns True.

find_one(**kwargs) → Union[jawa.methods.Method, NoneType][source]

Same as find() but returns only the first result.

pack(out: IO)[source]

Write the MethodTable 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()
remove(method: jawa.methods.Method)[source]

Removes a method from the table by identity.

unpack(source: IO)[source]

Read the MethodTable from the file-like object source.

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()