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

public final Class CatchStructs

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.dex.code.CatchHandlerList, .CatchTable, .DalvCode, org.droidparts.dexmaker.dx.util.AnnotatedOutput, .ByteArrayAnnotatedOutput, .Hex, java.io.PrintWriter, java.util.Map, .TreeMap

List of exception handlers (tuples of covered range, catch type, handler address) for a particular piece of code. Instances of this class correspond to a try_item[] and a catch_handler_item[].

Field Summary

Modifier and TypeField and Description
private final DalvCode
code

non-null; code that contains the catches

private int
encodedHandlerHeaderSize

length of the handlers header (encoded size), if known; used for annotation

private byte[]
encodedHandlers

null-ok; the encoded handler list, if calculated; set in encode

private TreeMap<CatchHandlerList, Integer>
handlerOffsets

null-ok; map from handler lists to byte offsets, if calculated; set in encode

private CatchTable
table

null-ok; the underlying table; set in finishProcessingIfNecessary

private static final int
TRY_ITEM_WRITE_SIZE

the size of a try_item: a uint and two ushorts

Constructor Summary

AccessConstructor and Description
public
CatchStructs(DalvCode
non-null; code that contains the catches
code
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
private static void
annotateAndConsumeHandlers(CatchHandlerList
non-null; handlers to annotate
handlers
,
int
>= 0; the offset of this handler
offset
,
int
>= 1; the number of bytes the handlers consume
size
,
String
non-null; prefix for each line
prefix
,
PrintWriter
null-ok; where to print to
printTo
,
AnnotatedOutput
non-null; where to annotate to
annotateTo
)

Helper for annotateEntries to annotate a catch handler list while consuming it.

private void
annotateEntries(String
non-null; prefix for each line
prefix
,
PrintWriter
null-ok; where to print to
printTo
,
AnnotatedOutput
null-ok; where to consume bytes and annotate to
annotateTo
)

Helper method to annotate or simply print the exception handlers.

public void
debugPrint(PrintWriter
non-null; where to dump
out
,
String
non-null; prefix to attach to each line of output
prefix
)

Does a human-friendly dump of this instance.

public void
encode(DexFile
non-null; file this instance is part of
file
)

Encodes the handler lists.

private void
finishProcessingIfNecessary()

Finish processing the catches, if necessary.

public int

Returns:

>= 0; the tries list size
triesSize
()

Gets the size of the tries list, in entries.

public int

Returns:

>= 0; the write size
writeSize
()

Gets the write size of this instance, in bytes.

public void
writeTo(DexFile
non-null; file this instance is part of
file
,
AnnotatedOutput
non-null; where to write to
out
)

Writes this instance to the given stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

codeback to summary
private final DalvCode code

non-null; code that contains the catches

encodedHandlerHeaderSizeback to summary
private int encodedHandlerHeaderSize

length of the handlers header (encoded size), if known; used for annotation

encodedHandlersback to summary
private byte[] encodedHandlers

null-ok; the encoded handler list, if calculated; set in encode

handlerOffsetsback to summary
private TreeMap<CatchHandlerList, Integer> handlerOffsets

null-ok; map from handler lists to byte offsets, if calculated; set in encode

tableback to summary
private CatchTable table

null-ok; the underlying table; set in finishProcessingIfNecessary

TRY_ITEM_WRITE_SIZEback to summary
private static final int TRY_ITEM_WRITE_SIZE

the size of a try_item: a uint and two ushorts

Constructor Detail

CatchStructsback to summary
public CatchStructs(DalvCode code)

Constructs an instance.

Parameters
code:DalvCode

non-null; code that contains the catches

Method Detail

annotateAndConsumeHandlersback to summary
private static void annotateAndConsumeHandlers(CatchHandlerList handlers, int offset, int size, String prefix, PrintWriter printTo, AnnotatedOutput annotateTo)

Helper for annotateEntries to annotate a catch handler list while consuming it.

Parameters
handlers:CatchHandlerList

non-null; handlers to annotate

offset:int

>= 0; the offset of this handler

size:int

>= 1; the number of bytes the handlers consume

prefix:String

non-null; prefix for each line

printTo:PrintWriter

null-ok; where to print to

annotateTo:AnnotatedOutput

non-null; where to annotate to

annotateEntriesback to summary
private void annotateEntries(String prefix, PrintWriter printTo, AnnotatedOutput annotateTo)

Helper method to annotate or simply print the exception handlers. Only one of printTo or annotateTo should be non-null.

Parameters
prefix:String

non-null; prefix for each line

printTo:PrintWriter

null-ok; where to print to

annotateTo:AnnotatedOutput

null-ok; where to consume bytes and annotate to

debugPrintback to summary
public void debugPrint(PrintWriter out, String prefix)

Does a human-friendly dump of this instance.

Parameters
out:PrintWriter

non-null; where to dump

prefix:String

non-null; prefix to attach to each line of output

encodeback to summary
public void encode(DexFile file)

Encodes the handler lists.

Parameters
file:DexFile

non-null; file this instance is part of

finishProcessingIfNecessaryback to summary
private void finishProcessingIfNecessary()

Finish processing the catches, if necessary.

triesSizeback to summary
public int triesSize()

Gets the size of the tries list, in entries.

Returns:int

>= 0; the tries list size

writeSizeback to summary
public int writeSize()

Gets the write size of this instance, in bytes.

Returns:int

>= 0; the write size

writeToback to summary
public void writeTo(DexFile file, AnnotatedOutput out)

Writes this instance to the given stream.

Parameters
file:DexFile

non-null; file this instance is part of

out:AnnotatedOutput

non-null; where to write to