org.ow2.asmdex.structureWriter
Class Prototype

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

public class Prototype
extends java.lang.Object
implements java.lang.Comparable<Prototype>

Prototype of a method, like described in the proto_id_item structure. Implements Comparable in order to easily sort the Prototypes. Like requested by the Dex documentation, two prototypes are compared by their return types, and then their arguments.

Author:
Julien Névo.

Constructor Summary
Prototype(java.lang.String descriptor)
          Constructor of a Prototype.
 
Method Summary
static int calculateHashCode(java.lang.String descriptor)
          Calculates the hashcode of the Prototype from its descriptor in the TypeDescriptor format.
 int compareTo(Prototype prototype)
           
 boolean equals(java.lang.Object o)
           
 java.lang.String getDescriptor()
          Returns a String representing the whole prototype (return type and parameters) in the "TypeDescriptor" format.
static TypeList getDescriptors(java.lang.String descriptor, boolean skipFirst)
          Returns a TypeList containing descriptors in the TypeDescriptor format from a descriptor also in the TypeDescriptor format, or an empty array if nothing was found.
static java.lang.String getFirstDescriptor(java.lang.String descriptor)
          Returns the first Type found in the descriptor given.
 int getNbParameters()
          Returns the number of parameters this Prototype contains (doesn't count the return type).
static int getNbParametersFromTypeDescriptor(java.lang.String desc)
          Returns the number of parameters (return parameter not included) in the given descriptor.
 TypeList getParameterTypes()
          Returns a TypeList of the parameter types, in the "TypeDescriptor" format.
 java.lang.String getReturnType()
          Returns a String representing the return type, in the "TypeDescriptor" format.
 java.lang.String getShortyDescriptor()
          Returns a String representing the whole prototype (return type and parameters) in the "ShortyDescriptor" format.
static java.lang.String getShortyDescriptorFromTypeDescriptor(java.lang.String desc)
          Returns a ShortyDescriptor from a given TypeDescriptor.
static int getSizeOfDescriptor(java.lang.String descriptor, boolean skipReturnType)
          Returns the sum in bytes of the size of every type of the given descriptor, skipping or not the return type (the first information of the descriptor).
static int getSizeOfType(java.lang.String type)
          Returns the size in bytes of a given type, or 0 for a Void or unknown type.
 int hashCode()
           
 void initialize()
          Fix internal structure if this is the unique witness kept in the constantpool
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Prototype

public Prototype(java.lang.String descriptor)
Constructor of a Prototype. Builds the structure from a descriptor in the TypeDescriptor format.

Parameters:
descriptor - full descriptor in the TypeDescriptor format.
Method Detail

initialize

public void initialize()
Fix internal structure if this is the unique witness kept in the constantpool


calculateHashCode

public static int calculateHashCode(java.lang.String descriptor)
Calculates the hashcode of the Prototype from its descriptor in the TypeDescriptor format.

Returns:
the hashcode of the Prototype.

getDescriptor

public java.lang.String getDescriptor()
Returns a String representing the whole prototype (return type and parameters) in the "TypeDescriptor" format.

Returns:
a String representing the whole prototype (return type and parameters) in the "TypeDescriptor" format.

getShortyDescriptor

public java.lang.String getShortyDescriptor()
Returns a String representing the whole prototype (return type and parameters) in the "ShortyDescriptor" format.

Returns:
a String representing the whole prototype (return type and parameters) in the "ShortyDescriptor" format.

getReturnType

public java.lang.String getReturnType()
Returns a String representing the return type, in the "TypeDescriptor" format.

Returns:
a String representing the return type, in the "TypeDescriptor" format.

getParameterTypes

public TypeList getParameterTypes()
Returns a TypeList of the parameter types, in the "TypeDescriptor" format. It may be an empty array.

Returns:
a TypeList of the parameter types, in the "TypeDescriptor" format.

getNbParameters

public int getNbParameters()
Returns the number of parameters this Prototype contains (doesn't count the return type). May be 0.

Returns:
the number of parameters this Prototype contains.

getFirstDescriptor

public static java.lang.String getFirstDescriptor(java.lang.String descriptor)
Returns the first Type found in the descriptor given. Returns Null if the String is empty, Null or invalid.

Parameters:
descriptor - descriptor.
Returns:
the first Type found in the descriptor given, or Null if the String is empty, Null or invalid.

getSizeOfType

public static int getSizeOfType(java.lang.String type)
Returns the size in bytes of a given type, or 0 for a Void or unknown type.

Parameters:
type - type.
Returns:
the size in bytes of a given type, or 0 for a Void or unknown type.

getSizeOfDescriptor

public static int getSizeOfDescriptor(java.lang.String descriptor,
                                      boolean skipReturnType)
Returns the sum in bytes of the size of every type of the given descriptor, skipping or not the return type (the first information of the descriptor).

Parameters:
descriptor - the descriptor.
skipReturnType - true to skip the first type found.
Returns:
the sum in bytes of the size of every type of the given descriptor.

getShortyDescriptorFromTypeDescriptor

public static java.lang.String getShortyDescriptorFromTypeDescriptor(java.lang.String desc)
Returns a ShortyDescriptor from a given TypeDescriptor.

Parameters:
desc - the descriptor.
Returns:
a ShortyDescriptor.

getNbParametersFromTypeDescriptor

public static int getNbParametersFromTypeDescriptor(java.lang.String desc)
Returns the number of parameters (return parameter not included) in the given descriptor.

Parameters:
desc - the descriptor.
Returns:
the number of parameters (return parameter not included).

getDescriptors

public static TypeList getDescriptors(java.lang.String descriptor,
                                      boolean skipFirst)
Returns a TypeList containing descriptors in the TypeDescriptor format from a descriptor also in the TypeDescriptor format, or an empty array if nothing was found.

Parameters:
descriptor - descriptors in the TypeDescriptor format.
skipFirst - true to skip the first descriptor, usually the return type.
Returns:
a TypeList of descriptors in the TypeDescriptor format.

compareTo

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

equals

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

hashCode

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