org.ow2.asmdex.structureWriter
Class Field

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

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

Class representing a Field. A Field, as described by the field_id_item format, consists in its name, the name of the class owning it, and its type. However, contrary to the field_id_item, it also own its access flags, and its value. The value is only used for Final Static fields, else it's Null. Having two fields equals does NOT mean their value is equal. Just that the name, owner and type are the same. Implements Comparable in order to easily sort the Fields. Like requested by the Dex documentation, two Fields are sorted according to the class owning type, the field name and then their own type.

Author:
Julien Névo

Constructor Summary
Field(java.lang.String fieldName, java.lang.String desc, java.lang.String classOwningName)
          Constructor of the Field.
 
Method Summary
 void addAnnotationItem(AnnotationItem annotationItem)
          Adds an annotation_item to the annotations_set_items.
static int calculateHashCode(java.lang.String fieldName, java.lang.String classOwningName, java.lang.String desc)
          Calculates the hashcode of a Field according to some of its attributes.
 int compareTo(Field field)
           
 void completeInformation(int access, java.lang.String[] signature, java.lang.Object value, ConstantPool constantPool)
          Adds information to the current Field.
 byte[] encodeValue(ConstantPool constantPool)
          Encode the value into an array of Bytes.
 boolean equals(java.lang.Object obj)
           
 int getAccess()
          Returns the access flags of the Field.
 AnnotationSetItem getAnnotationSetItem()
          Returns the annotation_set_item this structure currently contains.
 java.lang.String getClassName()
          Returns the Class owning the Field.
 java.lang.String getFieldName()
          Returns the Name of the Field.
 int getNbAnnotations()
          Returns the number of annotation_items this structure currently contains.
 java.lang.String[] getSignature()
          Returns the Signature of the Field.
 java.lang.String getTypeName()
          Returns the Type of the Field, described in the TypeDescriptor format.
 EncodedValue getValue()
          Returns the encoded value of the field.
 int hashCode()
           
 void init(int access, java.lang.String[] signature, java.lang.Object value, ConstantPool constantPool)
          Init if this is the one kept.
 boolean isFinalStatic()
          Indicates whether the Field is Final and Static.
 boolean isStatic()
          Indicates whether the Field is Static.
 boolean isUnknown()
          Indicates whether the Field is unknown (referred to, but not yet parsed).
 void setNoValue()
          Sets the value to 0 or Null according to its type.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Field

public Field(java.lang.String fieldName,
             java.lang.String desc,
             java.lang.String classOwningName)
Constructor of the Field.

Parameters:
fieldName - name of the Field.
desc - type of the Field, described in the TypeDescriptor format.
classOwningName - name of the Class, owner of the Field.
Method Detail

init

public void init(int access,
                 java.lang.String[] signature,
                 java.lang.Object value,
                 ConstantPool constantPool)
Init if this is the one kept.

Parameters:
access - the access flags of the Field.
signature - the Signature of the field. May be Null.
value - the value of the Field, or Null for non-static Fields.
constantPool - the Constant Pool.

calculateHashCode

public static int calculateHashCode(java.lang.String fieldName,
                                    java.lang.String classOwningName,
                                    java.lang.String desc)
Calculates the hashcode of a Field according to some of its attributes.

Parameters:
fieldName - the name of the Field.
classOwningName - the Class owning the Field.
desc - type of the Field, described in the TypeDescriptor format.
Returns:
the hashcode of a Field.

completeInformation

public void completeInformation(int access,
                                java.lang.String[] signature,
                                java.lang.Object value,
                                ConstantPool constantPool)
Adds information to the current Field. This is useful only if this Field has the ACC_UNKNOWN flag, which means Instructions referred to it while it has not yet been visited, declaring it but not giving all the information it should have.


isStatic

public boolean isStatic()
Indicates whether the Field is Static.


isFinalStatic

public boolean isFinalStatic()
Indicates whether the Field is Final and Static.


isUnknown

public boolean isUnknown()
Indicates whether the Field is unknown (referred to, but not yet parsed).

Returns:
true if the Field is unknown.

addAnnotationItem

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

Parameters:
annotationItem - the Annotation Item to add.

getClassName

public java.lang.String getClassName()
Returns the Class owning the Field.

Returns:
the Class owning the Field.

getTypeName

public java.lang.String getTypeName()
Returns the Type of the Field, described in the TypeDescriptor format.

Returns:
the Type of the Field, described in the TypeDescriptor format.

getFieldName

public java.lang.String getFieldName()
Returns the Name of the Field.

Returns:
the Name of the Field.

getAccess

public int getAccess()
Returns the access flags of the Field.

Returns:
the access flags of the Field.

getSignature

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

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

getValue

public EncodedValue getValue()
Returns the encoded value of the field. Null for non-static fields.

Returns:
the encoded value of the field, or Null.

encodeValue

public byte[] encodeValue(ConstantPool constantPool)
Encode the value into an array of Bytes.

Returns:
an array of bytes.

setNoValue

public void setNoValue()
Sets the value to 0 or Null according to its type.


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.

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(Field field)
Specified by:
compareTo in interface java.lang.Comparable<Field>