Package com.android.dx.dex.file
Class ClassDefItem
java.lang.Object
com.android.dx.dex.file.Item
com.android.dx.dex.file.IndexedItem
com.android.dx.dex.file.ClassDefItem
Representation of a Dalvik class, which is basically a set of
members (fields or methods) along with a few more pieces of
information.
-
Constructor Summary
ConstructorDescriptionClassDefItem
(CstType thisClass, int accessFlags, CstType superclass, TypeList interfaces, CstString sourceFile) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContents
(DexFile file) Populates aDexFile
with items from within this instance.void
addDirectMethod
(EncodedMethod method) Adds a direct (static
and/orprivate
) method.void
addFieldAnnotations
(CstFieldRef field, Annotations annotations, DexFile dexFile) Adds a field annotations item to this class.void
addInstanceField
(EncodedField field) Adds an instance field.void
addMethodAnnotations
(CstMethodRef method, Annotations annotations, DexFile dexFile) Adds a method annotations item to this class.void
addParameterAnnotations
(CstMethodRef method, AnnotationsList list, DexFile dexFile) Adds a parameter annotations item to this class.void
addStaticField
(EncodedField field, Constant value) Adds a static field.void
addVirtualMethod
(EncodedMethod method) Adds a virtual method.void
debugPrint
(Writer out, boolean verbose) Prints out the contents of this instance, in a debugging-friendly way.int
Gets the access flags.Gets the list of interfaces implemented.getMethodAnnotations
(CstMethodRef method) Gets the method annotations for a given method, if any.Gets all the methods in this class.getParameterAnnotations
(CstMethodRef method) Gets the parameter annotations for a given method, if any.Gets the source file name.Gets the superclass.Gets the constant corresponding to this class.itemType()
Returns the item type for this instance.void
setClassAnnotations
(Annotations annotations, DexFile dexFile) Sets the direct annotations on this class.int
Gets the size of this instance when written, in bytes.void
writeTo
(DexFile file, AnnotatedOutput out) Writes the representation of this instance to the given data section, using the givenDexFile
to look things up as needed.Methods inherited from class com.android.dx.dex.file.IndexedItem
getIndex, hasIndex, indexString, setIndex
-
Constructor Details
-
ClassDefItem
public ClassDefItem(CstType thisClass, int accessFlags, CstType superclass, TypeList interfaces, CstString sourceFile) Constructs an instance. Its sets of members and annotations are initially empty.- Parameters:
thisClass
-non-null;
type constant for this classaccessFlags
- access flagssuperclass
-null-ok;
superclass ornull
if this class is a/the root classinterfaces
-non-null;
list of implemented interfacessourceFile
-null-ok;
source file name ornull
if unknown
-
-
Method Details
-
itemType
Returns the item type for this instance. -
writeSize
public int writeSize()Gets the size of this instance when written, in bytes. -
addContents
Populates aDexFile
with items from within this instance. This will not add an item to the file for this instance itself (which should have been done by whatever refers to this instance).Note: Subclasses must override this to do something appropriate.
- Specified by:
addContents
in classItem
- Parameters:
file
-non-null;
the file to populate
-
writeTo
Writes the representation of this instance to the given data section, using the givenDexFile
to look things up as needed. If this instance keeps track of its offset, then this method will note the written offset and will also throw an exception if this instance has already been written. -
getThisClass
Gets the constant corresponding to this class.- Returns:
non-null;
the constant
-
getAccessFlags
public int getAccessFlags()Gets the access flags.- Returns:
- the access flags
-
getSuperclass
Gets the superclass.- Returns:
null-ok;
the superclass ornull
if this class is a/the root class
-
getInterfaces
Gets the list of interfaces implemented.- Returns:
non-null;
the interfaces list
-
getSourceFile
Gets the source file name.- Returns:
null-ok;
the source file name ornull
if unknown
-
addStaticField
Adds a static field.- Parameters:
field
-non-null;
the field to addvalue
-null-ok;
initial value for the field, if any
-
addInstanceField
Adds an instance field.- Parameters:
field
-non-null;
the field to add
-
addDirectMethod
Adds a direct (static
and/orprivate
) method.- Parameters:
method
-non-null;
the method to add
-
addVirtualMethod
Adds a virtual method.- Parameters:
method
-non-null;
the method to add
-
getMethods
Gets all the methods in this class. The returned list is not linked in any way to the underlying lists contained in this instance, but the objects contained in the list are shared.- Returns:
non-null;
list of all methods
-
setClassAnnotations
Sets the direct annotations on this class. These are annotations made on the class, per se, as opposed to on one of its members. It is only valid to call this method at most once per instance.- Parameters:
annotations
-non-null;
annotations to set for this classdexFile
-non-null;
dex output
-
addFieldAnnotations
Adds a field annotations item to this class.- Parameters:
field
-non-null;
field in questionannotations
-non-null;
associated annotations to adddexFile
-non-null;
dex output
-
addMethodAnnotations
Adds a method annotations item to this class.- Parameters:
method
-non-null;
method in questionannotations
-non-null;
associated annotations to adddexFile
-non-null;
dex output
-
addParameterAnnotations
Adds a parameter annotations item to this class.- Parameters:
method
-non-null;
method in questionlist
-non-null;
associated list of annotation sets to adddexFile
-non-null;
dex output
-
getMethodAnnotations
Gets the method annotations for a given method, if any. This is meant for use by debugging / dumping code.- Parameters:
method
-non-null;
the method- Returns:
null-ok;
the method annotations, if any
-
getParameterAnnotations
Gets the parameter annotations for a given method, if any. This is meant for use by debugging / dumping code.- Parameters:
method
-non-null;
the method- Returns:
null-ok;
the parameter annotations, if any
-
debugPrint
Prints out the contents of this instance, in a debugging-friendly way.- Parameters:
out
-non-null;
where to output toverbose
- whether to be verbose with the output
-