org.ow2.asmdex
Class ApplicationWriter

java.lang.Object
  extended by org.ow2.asmdex.ApplicationVisitor
      extended by org.ow2.asmdex.ApplicationWriter

public class ApplicationWriter
extends ApplicationVisitor

A ApplicationVisitor that generates an Android dex file in bytecode form. More precisely this visitor generates a byte array conforming to the dex file format. It can be used alone, to generate Android classes "from scratch", or with one or more ApplicationReader and adapter Application visitor to generate a modified class from one or more existing Java applications.

KNOWN ISSUES

DIFFERENCES WITH THE DX BYTECODE : NOTES:

Author:
Julien Névo, based on the ASM Framework.

Field Summary
static boolean DISPLAY_WRITER_INFORMATION
          Indicates if the writer information must be displayed.
static boolean SKIP_DEBUG_INFO_ITEMS
          Indicates if the writer must encode the Debug information that it is given.
 
Fields inherited from class org.ow2.asmdex.ApplicationVisitor
api, av
 
Constructor Summary
ApplicationWriter()
          Constructs an new ClassWriter.
ApplicationWriter(ApplicationReader applicationReader)
          Constructs a new ClassWriter object and enables optimizations for "mostly add" bytecode transformations.
 
Method Summary
 void addFieldFromApplicationReader(java.lang.String className, java.lang.String type, java.lang.String fieldName)
          When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Fields into the Constant Pool of the Writer.
 void addMethodFromApplicationReader(java.lang.String className, java.lang.String prototype, java.lang.String methodName)
          When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Methods into the Constant Pool of the Writer.
 void addStringFromApplicationReader(java.lang.String string)
          When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Strings into the Constant Pool of the Writer.
 void addTypeNameFromApplicationReader(java.lang.String type)
          When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Types into the Constant Pool of the Writer.
 ApplicationReader getApplicationReader()
          Returns the ApplicationReader that may be linked to this ApplicationWriter.
 ConstantPool getConstantPool()
          Gets the Constant Pool.
 byte[] toByteArray()
          Returns the bytecode of the class that was built with this application writer.
 void visit()
          Visits the header of the application.
 ClassVisitor visitClass(int access, java.lang.String name, java.lang.String[] signature, java.lang.String superName, java.lang.String[] interfaces)
          Visits a class of the application.
 void visitEnd()
          Visits the end of the application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISPLAY_WRITER_INFORMATION

public static final boolean DISPLAY_WRITER_INFORMATION
Indicates if the writer information must be displayed.

See Also:
Constant Field Values

SKIP_DEBUG_INFO_ITEMS

public static final boolean SKIP_DEBUG_INFO_ITEMS
Indicates if the writer must encode the Debug information that it is given. If the flag is true, the debug_info_items are not encoded at all, which is different from the SKIP_DEBUG from ApplicationReader that just doesn't emit visitLocalVariable and visitLineNumber, but has no power over the creation of the debug_info_items.

See Also:
Constant Field Values
Constructor Detail

ApplicationWriter

public ApplicationWriter()
Constructs an new ClassWriter.


ApplicationWriter

public ApplicationWriter(ApplicationReader applicationReader)
Constructs a new ClassWriter object and enables optimizations for "mostly add" bytecode transformations. These optimizations are the following:

Parameters:
applicationReader - the ApplicationReader used to read the original application. It will be used to copy the entire constant pool from the original application and also to copy other fragments of original bytecode where applicable.
Method Detail

visit

public void visit()
Description copied from class: ApplicationVisitor
Visits the header of the application.

Overrides:
visit in class ApplicationVisitor

visitClass

public ClassVisitor visitClass(int access,
                               java.lang.String name,
                               java.lang.String[] signature,
                               java.lang.String superName,
                               java.lang.String[] interfaces)
Description copied from class: ApplicationVisitor
Visits a class of the application. This method must return a new ClassVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Overrides:
visitClass in class ApplicationVisitor
Parameters:
access - the access flags of the class (see Opcodes).
name - the internal name of the class.
signature - the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
superName - the internal of name of the super class. For interfaces, the super class is Object. May be null, but only for the Object class.
interfaces - the internal names of the class's interfaces. May be null.
Returns:
an object to visit the byte code of the application, or null if this application visitor is not interested in visiting the code of this class.

visitEnd

public void visitEnd()
Description copied from class: ApplicationVisitor
Visits the end of the application. This method, which is the last one to be called, is used to inform the visitor that the whole Application has been visited.

Overrides:
visitEnd in class ApplicationVisitor

toByteArray

public byte[] toByteArray()
Returns the bytecode of the class that was built with this application writer. The application Dex file must have been parsed before.

Returns:
the bytecode of the class that was build with this application writer, or Null if the application has not been parsed yet.

getConstantPool

public ConstantPool getConstantPool()
Gets the Constant Pool.

Returns:
the Constant Pool.

getApplicationReader

public ApplicationReader getApplicationReader()
Returns the ApplicationReader that may be linked to this ApplicationWriter. May be null.


addStringFromApplicationReader

public void addStringFromApplicationReader(java.lang.String string)
When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Strings into the Constant Pool of the Writer. This method is used for that. Note that the String added should be considered by the Writer as symbolic, as more of them can be added later.

Parameters:
string - the String to add to the Constant Pool.

addTypeNameFromApplicationReader

public void addTypeNameFromApplicationReader(java.lang.String type)
When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Types into the Constant Pool of the Writer. This method is used for that. Note that the Type added should be considered by the Writer as symbolic, as more of them can be added later.

Parameters:
type - the Type to add to the Constant Pool.

addFieldFromApplicationReader

public void addFieldFromApplicationReader(java.lang.String className,
                                          java.lang.String type,
                                          java.lang.String fieldName)
When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Fields into the Constant Pool of the Writer. This method is used for that. Note that the Field added should be considered by the Writer as symbolic, as more of them can be added later.

Parameters:
className - the Class owner name.
type - the type of the Field.
fieldName - the name of the Field.

addMethodFromApplicationReader

public void addMethodFromApplicationReader(java.lang.String className,
                                           java.lang.String prototype,
                                           java.lang.String methodName)
When the optimization about the ApplicationReader/ApplicationWriter is enabled, the ApplicationReader will want to register Methods into the Constant Pool of the Writer. This method is used for that. Note that the Method added should be considered by the Writer as symbolic, as more of them can be added later.

Parameters:
className - the Class owner name.
prototype - the prototype of the method, in TypeDescriptor format.
methodName - the name of the Method.