Annotations and values¶
Annotations on classes, methods and fields, and the values of their elements. See annotations in the code guide.
Annotation
¶
One annotation on a class, a method or a field.
An annotation is a copy of the data. It stays valid on its own.
type_descriptor
property
¶
Descriptor of the annotation's class, such as Ljava/lang/Deprecated;.
elements
property
¶
elements: dict[str, AnnotationValue]
The elements the source set, by name.
An element left at its default value is not in the dictionary. The DEX format stores defaults once, on the annotation's own class.
AnnotationVisibility
¶
Bases: Enum
Who can see an annotation.
BUILD
class-attribute
instance-attribute
¶
Only tools that read the file. The annotation is not visible to the running app.
@Override is an example in source code.
RUNTIME
class-attribute
instance-attribute
¶
The running app can read the annotation through reflection.
SYSTEM
class-attribute
instance-attribute
¶
Data the compiler writes for the runtime in dalvik.annotation.* annotations:
generic signatures, default values, inner-class information.
AnnotationValue
module-attribute
¶
AnnotationValue = Union[
None,
bool,
int,
float,
str,
TypeValue,
EnumValue,
FieldValue,
MethodValue,
MethodTypeValue,
MethodHandleValue,
list["AnnotationValue"],
"Annotation",
]
The value of an annotation element, and the type of Field.initial_value.
Numbers, booleans, strings and null become plain Python values. All integer types
(byte, short, char, int, long) become int, and float and double
become float, so the original width is not kept. An array becomes a list. A value
that names a type, a member, a prototype or a method handle is one of the small
value classes (TypeValue, EnumValue, FieldValue, MethodValue,
MethodTypeValue, MethodHandleValue), and a nested annotation is an Annotation.
TypeValue
¶
A class literal as an annotation value, such as String.class.
It is a plain value: two are equal when their content is equal, and it can be a dictionary key or a set member.
EnumValue
¶
FieldValue
¶
MethodValue
¶
MethodTypeValue
¶
A method prototype as an annotation value: a java.lang.invoke.MethodType
constant.
It is a plain value: two are equal when their content is equal, and it can be a dictionary key or a set member.
MethodHandleValue
¶
A method handle as an annotation value: a java.lang.invoke.MethodHandle
constant, which reads or writes a field, or calls a method.
It is a plain value: two are equal when their content is equal, and it can be a dictionary key or a set member.
member
property
¶
The member the handle works on: a FieldId for the four field kinds
(STATIC_PUT, STATIC_GET, INSTANCE_PUT, INSTANCE_GET), a MethodId for
the five invoke kinds.
In a damaged file, where the handle cannot be read, the kind is
INVOKE_STATIC and the member is a MethodId of empty strings.
MethodHandleKind
¶
Bases: Enum
What a method handle does, as MethodHandleValue.kind gives it. The values are
the method handle type codes of the DEX format.
INVOKE_INSTANCE
class-attribute
instance-attribute
¶
Calls an instance method, with virtual dispatch.
INVOKE_CONSTRUCTOR
class-attribute
instance-attribute
¶
Creates an object with a constructor.
INVOKE_DIRECT
class-attribute
instance-attribute
¶
Calls an instance method without dispatch, such as a private method.
INVOKE_INTERFACE
class-attribute
instance-attribute
¶
Calls an interface method.