Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.dex.file

public final Class ValueEncoder

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.annotation.Annotation, .NameValuePair, org.droidparts.dexmaker.dx.rop.cst.*, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .Hex, java.util.Collection

Handler for writing out encoded_values and parts thereof.

Field Summary

Modifier and TypeField and Description
private final DexFile
file

non-null; file being written

private final AnnotatedOutput
out

non-null; output stream to write to

private static final int
VALUE_ANNOTATION

annotation value type constant: annotation

private static final int
VALUE_ARRAY

annotation value type constant: array

private static final int
VALUE_BOOLEAN

annotation value type constant: boolean

private static final int
VALUE_BYTE

annotation value type constant: byte

private static final int
VALUE_CHAR

annotation value type constant: char

private static final int
VALUE_DOUBLE

annotation value type constant: double

private static final int
VALUE_ENUM

annotation value type constant: enum

private static final int
VALUE_FIELD

annotation value type constant: field

private static final int
VALUE_FLOAT

annotation value type constant: float

private static final int
VALUE_INT

annotation value type constant: int

private static final int
VALUE_LONG

annotation value type constant: long

private static final int
VALUE_METHOD

annotation value type constant: method

private static final int
VALUE_NULL

annotation value type constant: null

private static final int
VALUE_SHORT

annotation value type constant: short

private static final int
VALUE_STRING

annotation value type constant: string

private static final int
VALUE_TYPE

annotation value type constant: type

Constructor Summary

AccessConstructor and Description
public
ValueEncoder(DexFile
non-null; file being written
file
,
AnnotatedOutput
non-null; output stream to write to
out
)

Construct an instance.

Method Summary

Modifier and TypeMethod and Description
public static void
addContents(DexFile
non-null; the file to add to
file
,
Annotation
non-null; the annotation to add contents for
annotation
)

Helper for addContents() methods, which adds contents for a particular Annotation, calling itself recursively should it encounter a nested annotation.

public static void
addContents(DexFile
non-null; the file to add to
file
,
Constant
non-null; the constant to add contents for
cst
)

Helper for addContents() methods, which adds contents for a particular constant, calling itself recursively should it encounter a CstArray and calling addContents(DexFile, Annotation) recursively should it encounter a CstAnnotation.

public static String

Returns:

non-null; its type name and human form
constantToHuman
(Constant
non-null; the constant
cst
)

Gets the colloquial type name and human form of the type of the given constant, when used as an encoded value.

private static int

Returns:

the value type; one of the VALUE_* constants defined by this class
constantToValueType
(Constant
non-null; the constant
cst
)

Gets the value type for the given constant.

public void
writeAnnotation(Annotation
non-null; annotation instance to write
annotation
,
boolean
true iff the given annotation is the top-level annotation or false if it is a sub-annotation of some other annotation
topLevel
)

Writes out the encoded form of the given annotation, that is, as an encoded_annotation and not including a value_type prefix.

public void
writeArray(CstArray
non-null; array instance to write
array
,
boolean
true iff the given annotation is the top-level annotation or false if it is a sub-annotation of some other annotation
topLevel
)

Writes out the encoded form of the given array, that is, as an encoded_array and not including a value_type prefix.

public void
writeConstant(Constant
non-null; the constant to write
cst
)

Writes out the encoded form of the given constant.

private void
writeRightZeroExtendedValue(int
the type constant
type
,
long
long bits of the value
value
)

Helper for writeConstant, which writes out a right-zero-extended value.

private void
writeSignedIntegralValue(int
the type constant
type
,
long
long bits of the value
value
)

Helper for writeConstant, which writes out the value for any signed integral type.

private void
writeUnsignedIntegralValue(int
the type constant
type
,
long
long bits of the value
value
)

Helper for writeConstant, which writes out the value for any unsigned integral type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fileback to summary
private final DexFile file

non-null; file being written

outback to summary
private final AnnotatedOutput out

non-null; output stream to write to

VALUE_ANNOTATIONback to summary
private static final int VALUE_ANNOTATION

annotation value type constant: annotation

VALUE_ARRAYback to summary
private static final int VALUE_ARRAY

annotation value type constant: array

VALUE_BOOLEANback to summary
private static final int VALUE_BOOLEAN

annotation value type constant: boolean

VALUE_BYTEback to summary
private static final int VALUE_BYTE

annotation value type constant: byte

VALUE_CHARback to summary
private static final int VALUE_CHAR

annotation value type constant: char

VALUE_DOUBLEback to summary
private static final int VALUE_DOUBLE

annotation value type constant: double

VALUE_ENUMback to summary
private static final int VALUE_ENUM

annotation value type constant: enum

VALUE_FIELDback to summary
private static final int VALUE_FIELD

annotation value type constant: field

VALUE_FLOATback to summary
private static final int VALUE_FLOAT

annotation value type constant: float

VALUE_INTback to summary
private static final int VALUE_INT

annotation value type constant: int

VALUE_LONGback to summary
private static final int VALUE_LONG

annotation value type constant: long

VALUE_METHODback to summary
private static final int VALUE_METHOD

annotation value type constant: method

VALUE_NULLback to summary
private static final int VALUE_NULL

annotation value type constant: null

VALUE_SHORTback to summary
private static final int VALUE_SHORT

annotation value type constant: short

VALUE_STRINGback to summary
private static final int VALUE_STRING

annotation value type constant: string

VALUE_TYPEback to summary
private static final int VALUE_TYPE

annotation value type constant: type

Constructor Detail

ValueEncoderback to summary
public ValueEncoder(DexFile file, AnnotatedOutput out)

Construct an instance.

Parameters
file:DexFile

non-null; file being written

out:AnnotatedOutput

non-null; output stream to write to

Method Detail

addContentsback to summary
public static void addContents(DexFile file, Annotation annotation)

Helper for addContents() methods, which adds contents for a particular Annotation, calling itself recursively should it encounter a nested annotation.

Parameters
file:DexFile

non-null; the file to add to

annotation:Annotation

non-null; the annotation to add contents for

addContentsback to summary
public static void addContents(DexFile file, Constant cst)

Helper for addContents() methods, which adds contents for a particular constant, calling itself recursively should it encounter a CstArray and calling addContents(DexFile, Annotation) recursively should it encounter a CstAnnotation.

Parameters
file:DexFile

non-null; the file to add to

cst:Constant

non-null; the constant to add contents for

constantToHumanback to summary
public static String constantToHuman(Constant cst)

Gets the colloquial type name and human form of the type of the given constant, when used as an encoded value.

Parameters
cst:Constant

non-null; the constant

Returns:String

non-null; its type name and human form

constantToValueTypeback to summary
private static int constantToValueType(Constant cst)

Gets the value type for the given constant.

Parameters
cst:Constant

non-null; the constant

Returns:int

the value type; one of the VALUE_* constants defined by this class

writeAnnotationback to summary
public void writeAnnotation(Annotation annotation, boolean topLevel)

Writes out the encoded form of the given annotation, that is, as an encoded_annotation and not including a value_type prefix. If the output stream keeps (debugging) annotations and topLevel is true, then this method will write (debugging) annotations.

Parameters
annotation:Annotation

non-null; annotation instance to write

topLevel:boolean

true iff the given annotation is the top-level annotation or false if it is a sub-annotation of some other annotation

writeArrayback to summary
public void writeArray(CstArray array, boolean topLevel)

Writes out the encoded form of the given array, that is, as an encoded_array and not including a value_type prefix. If the output stream keeps (debugging) annotations and topLevel is true, then this method will write (debugging) annotations.

Parameters
array:CstArray

non-null; array instance to write

topLevel:boolean

true iff the given annotation is the top-level annotation or false if it is a sub-annotation of some other annotation

writeConstantback to summary
public void writeConstant(Constant cst)

Writes out the encoded form of the given constant.

Parameters
cst:Constant

non-null; the constant to write

writeRightZeroExtendedValueback to summary
private void writeRightZeroExtendedValue(int type, long value)

Helper for writeConstant, which writes out a right-zero-extended value.

Parameters
type:int

the type constant

value:long

long bits of the value

writeSignedIntegralValueback to summary
private void writeSignedIntegralValue(int type, long value)

Helper for writeConstant, which writes out the value for any signed integral type.

Parameters
type:int

the type constant

value:long

long bits of the value

writeUnsignedIntegralValueback to summary
private void writeUnsignedIntegralValue(int type, long value)

Helper for writeConstant, which writes out the value for any unsigned integral type.

Parameters
type:int

the type constant

value:long

long bits of the value