org.ow2.asmdex.structureWriter
Class ClassDefinitionItem

java.lang.Object
  extended by org.ow2.asmdex.structureWriter.ClassDefinitionItem
All Implemented Interfaces:
java.lang.Comparable<ClassDefinitionItem>, IAnnotationsHolder

public class ClassDefinitionItem
extends java.lang.Object
implements java.lang.Comparable<ClassDefinitionItem>, IAnnotationsHolder

Simple class representing one class_def_item, for the writer. The equals and hashCode methods have been overridden in order to detect easily duplicates in Sets. ONLY className is used to differentiate the classes. Implements Comparable in order to easily sort the Classes. The test is minimalist is is only useful as a first-pass sort. A second pass, after the Dex file is parsed, will be done to ensure SuperClass are encoded before their children. It is IMPORTANT to note that the encoded Fields/Methods are NOT sorted according to their ids, but in the order of appearance of the fields/methods.

Author:
Julien Névo

Field Summary
static int ACCESS_FLAGS_OFFSET
          Offset in bytes of the access_flags field in the class_def_item structure.
static int ANNOTATIONS_OFF_OFFSET
          Offset in bytes of the annotations_off field in the class_def_item structure.
static int CLASS_DATA_OFF_OFFSET
          Offset in bytes of the class_data_off field in the class_def_item structure.
static int INTERFACES_OFFSET
          Offset in bytes of the interfaces_off field in the class_def_item structure.
static int SOURCE_FILE_IDX_OFFSET
          Offset in bytes of the source_file_idx field in the class_def_item structure.
static int SUPERCLASS_IDX_OFFSET
          Offset in bytes of the superclass_idx field in the class_def_item structure.
 
Constructor Summary
ClassDefinitionItem(java.lang.String className, java.lang.String superClassName, int accessFlags, TypeList interfaceNames, java.lang.String[] signature, ConstantPool constantPool)
          Constructor of a ClassDefinitionItem.
 
Method Summary
 void addAnnotationItem(AnnotationItem annotationItem)
          Adds an annotation_item to the annotations_set_items.
 void addAnnotationItemForDefaultAnnotation(AnnotationItem annotationItem)
          Adds an AnnotationItem to the list of AnnotationItem of Default Annotation.
 void addField(Field field)
          Adds a Field to the Field list of the Class, whether is it a Static or Instance Field.
 void addMemberClassValue(java.lang.String memberClassType, ConstantPool constantPool)
          Adds a Member Class Encoded Value to the Member Classes.
 void addMethod(Method method)
          Adds a Method (direct or virtual) to the method list of the Class.
 void buildAnnotationDirectoryItem()
          Builds the annotation_directory_item.
 int compareTo(ClassDefinitionItem cdi)
           
 boolean equals(java.lang.Object obj)
           
 int getAccessFlags()
          Returns the access flags of the Class.
 AnnotationDirectoryItem getAnnotationDirectoryItem()
          Returns the annotation_directory_item, filled after the whole Class has been parsed.
 java.util.List<AnnotationItem> getAnnotationItemsForDefaultAnnotation()
          Return the list of AnnotationItems containing each Default Annotation for this Class.
 AnnotationSetItem getAnnotationSetItem()
          Returns the annotation_set_item this structure currently contains.
 java.lang.String getClassName()
          Returns the name of the Class.
 java.util.ArrayList<Method> getDirectMethods()
          Returns the direct methods this class contains.
 java.util.ArrayList<Field> getInstanceFields()
          Returns the instance fields of this class.
 TypeList getInterfaces()
          Returns the Interfaces used by the Class.
 EncodedValueArray getMemberClassArray()
          Returns the Encoded Array containing the Member Classes, or null if none were added.
 int getNbAnnotatedFields()
          Returns the count of annotated Fields, whether they are static or instance Fields.
 int getNbAnnotatedMethods()
          Returns the count of annotated Methods, whether they are direct or virtual.
 int getNbAnnotations()
          Returns the number of annotation_items this structure currently contains.
 int getNbDirectMethods()
          Returns the number of direct methods this class currently contains.
 int getNbInstanceFields()
          Returns the number of instance fields this class currently contains.
 int getNbMethodWithAnnotatedParameters()
          Returns the count of Methods that have annotated Parameters.
 int getNbStaticFields()
          Returns the number of static fields this class currently contains.
 int getNbVirtualMethods()
          Returns the number of virtual methods this class currently contains.
 java.lang.String[] getSignature()
          Returns the Signature of the Class.
 java.lang.String getSourceFileName()
          Returns the source file that defines the Class.
 java.util.ArrayList<Field> getStaticFields()
          Returns the static fields of this class.
 java.lang.String getSuperClassName()
          Returns the Super Class of this Class.
 java.util.ArrayList<Method> getVirtualMethods()
          Returns the virtual methods this class contains.
 int hashCode()
           
 boolean isInterface()
          Indicates if the Class is an Interface.
 void setSourceFileName(java.lang.String sourceFileName)
          Sets the source file that defines the Class.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCESS_FLAGS_OFFSET

public static final int ACCESS_FLAGS_OFFSET
Offset in bytes of the access_flags field in the class_def_item structure.

See Also:
Constant Field Values

SUPERCLASS_IDX_OFFSET

public static final int SUPERCLASS_IDX_OFFSET
Offset in bytes of the superclass_idx field in the class_def_item structure.

See Also:
Constant Field Values

INTERFACES_OFFSET

public static final int INTERFACES_OFFSET
Offset in bytes of the interfaces_off field in the class_def_item structure.

See Also:
Constant Field Values

SOURCE_FILE_IDX_OFFSET

public static final int SOURCE_FILE_IDX_OFFSET
Offset in bytes of the source_file_idx field in the class_def_item structure.

See Also:
Constant Field Values

ANNOTATIONS_OFF_OFFSET

public static final int ANNOTATIONS_OFF_OFFSET
Offset in bytes of the annotations_off field in the class_def_item structure.

See Also:
Constant Field Values

CLASS_DATA_OFF_OFFSET

public static final int CLASS_DATA_OFF_OFFSET
Offset in bytes of the class_data_off field in the class_def_item structure.

See Also:
Constant Field Values
Constructor Detail

ClassDefinitionItem

public ClassDefinitionItem(java.lang.String className,
                           java.lang.String superClassName,
                           int accessFlags,
                           TypeList interfaceNames,
                           java.lang.String[] signature,
                           ConstantPool constantPool)
Constructor of a ClassDefinitionItem.

Parameters:
className - the name of the Class, fully qualified.
superClassName - the possible name of the super Class, or Null.
accessFlags - the access flags.
interfaceNames - names of the interface, or Null.
signature - the Signature of this Class, or Null if there is none.
constantPool - the Constant Pool of this Application.
Method Detail

getClassName

public java.lang.String getClassName()
Returns the name of the Class.

Returns:
the name of the Class.

getSuperClassName

public java.lang.String getSuperClassName()
Returns the Super Class of this Class. May be Null is the Class has no Super Class.

Returns:
the Super Class of this Class, or Null.

getInterfaces

public TypeList getInterfaces()
Returns the Interfaces used by the Class. The list it contains may be empty.

Returns:
the Interfaces used by the Class.

getAccessFlags

public int getAccessFlags()
Returns the access flags of the Class.

Returns:
the access flags of the Class.

getSourceFileName

public java.lang.String getSourceFileName()
Returns the source file that defines the Class. May be Null.

Returns:
the source file that defines the Class. May be Null.

setSourceFileName

public void setSourceFileName(java.lang.String sourceFileName)
Sets the source file that defines the Class. May be Null.


getSignature

public java.lang.String[] getSignature()
Returns the Signature of the Class. May be Null.

Returns:
the Signature of the Class. May be Null.

getDirectMethods

public java.util.ArrayList<Method> getDirectMethods()
Returns the direct methods this class contains.

Returns:
the direct methods this class contains.

getVirtualMethods

public java.util.ArrayList<Method> getVirtualMethods()
Returns the virtual methods this class contains.

Returns:
the virtual methods this class contains.

getStaticFields

public java.util.ArrayList<Field> getStaticFields()
Returns the static fields of this class.

Returns:
the static fields of this class.

getInstanceFields

public java.util.ArrayList<Field> getInstanceFields()
Returns the instance fields of this class.

Returns:
the instance fields of this class.

getNbDirectMethods

public int getNbDirectMethods()
Returns the number of direct methods this class currently contains.

Returns:
the number of direct methods this class currently contains.

getNbVirtualMethods

public int getNbVirtualMethods()
Returns the number of virtual methods this class currently contains.

Returns:
the number of virtual methods this class currently contains.

getNbStaticFields

public int getNbStaticFields()
Returns the number of static fields this class currently contains.

Returns:
the number of static fields this class currently contains.

getNbInstanceFields

public int getNbInstanceFields()
Returns the number of instance fields this class currently contains.

Returns:
the number of instance fields this class currently contains.

getAnnotationSetItem

public AnnotationSetItem getAnnotationSetItem()
Returns the annotation_set_item this structure currently contains.

Specified by:
getAnnotationSetItem in interface IAnnotationsHolder
Returns:
the annotation_set_item this structure currently contains.

getNbAnnotations

public int getNbAnnotations()
Returns the number of annotation_items this structure currently contains.

Specified by:
getNbAnnotations in interface IAnnotationsHolder
Returns:
the number of annotation_items this structure currently contains.

getNbAnnotatedMethods

public int getNbAnnotatedMethods()
Returns the count of annotated Methods, whether they are direct or virtual. This number is only set when parsing the Class is fully done.

Returns:
the count of annotated Methods.

getNbMethodWithAnnotatedParameters

public int getNbMethodWithAnnotatedParameters()
Returns the count of Methods that have annotated Parameters. This number is only set when parsing the Class is fully done.

Returns:
the count of Methods that have annotated Parameters.

getNbAnnotatedFields

public int getNbAnnotatedFields()
Returns the count of annotated Fields, whether they are static or instance Fields. This number is only set when parsing the Class is fully done.

Returns:
the count of annotated Fields.

getMemberClassArray

public EncodedValueArray getMemberClassArray()
Returns the Encoded Array containing the Member Classes, or null if none were added.

Returns:
the Encoded Array containing the Member Classes, or null if none were added.

getAnnotationDirectoryItem

public AnnotationDirectoryItem getAnnotationDirectoryItem()
Returns the annotation_directory_item, filled after the whole Class has been parsed. It may be Null if no Annotation is present in the Class, or the Methods, Fields, Parameters it possesses.

Returns:
the annotation_directory_item, or Null.

getAnnotationItemsForDefaultAnnotation

public java.util.List<AnnotationItem> getAnnotationItemsForDefaultAnnotation()
Return the list of AnnotationItems containing each Default Annotation for this Class. It may be Null if none were found.

Returns:
the list of AnnotationItems, or Null.

isInterface

public boolean isInterface()
Indicates if the Class is an Interface.

Returns:
true if the Class is an Interface.

addMethod

public void addMethod(Method method)
Adds a Method (direct or virtual) to the method list of the Class.

Parameters:
method - method to add.

addField

public void addField(Field field)
Adds a Field to the Field list of the Class, whether is it a Static or Instance Field.

Parameters:
field - the field to add.

addAnnotationItem

public void addAnnotationItem(AnnotationItem annotationItem)
Adds an annotation_item to the annotations_set_items.

Parameters:
annotationItem - the Annotation Item to add.

addMemberClassValue

public void addMemberClassValue(java.lang.String memberClassType,
                                ConstantPool constantPool)
Adds a Member Class Encoded Value to the Member Classes. They will be encoded as a dalvik.annotation.MemberClasses Annotation.

Parameters:
memberClassType - the value to add.
constantPool - the Constant Pool of the Application.

addAnnotationItemForDefaultAnnotation

public void addAnnotationItemForDefaultAnnotation(AnnotationItem annotationItem)
Adds an AnnotationItem to the list of AnnotationItem of Default Annotation. It must only be used in that case.

Parameters:
annotationItem - the AnnotationItem to add.

buildAnnotationDirectoryItem

public void buildAnnotationDirectoryItem()
Builds the annotation_directory_item. This must be done only after the Class has been fully parsed. The structure is kept only if it possesses at least one annotation.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(ClassDefinitionItem cdi)
Specified by:
compareTo in interface java.lang.Comparable<ClassDefinitionItem>