Top Description Fields Constructors Methods
org.apache.commons.compress.harmony.unpack200

public Class SegmentConstantPool

extends Object
Class Inheritance
Imports
java.util.List, org.apache.commons.compress.harmony.pack200.Pack200Exception, org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry, .ConstantPoolEntry

SegmentConstantPool manages the constant pool used for re-creating class files.

Field Summary

Modifier and TypeField and Description
public static final int
private final SegmentConstantPoolArrayCache
private final CpBands
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
protected static final String
protected static final String
protected static final String
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public
SegmentConstantPool(final CpBands
TODO
bands
)

Method Summary

Modifier and TypeMethod and Description
public ConstantPoolEntry

Returns:

CPClass for that class name, or null if not found.
getClassPoolEntry
(final String
Class name to look for (form: java/lang/Object)
name
)

Given the name of a class, answer the CPClass associated with that class.

public ConstantPoolEntry

Returns:

ConstantPoolEntry
getClassSpecificPoolEntry
(final int
type of constant pool array to search
cp
,
final long
index of the constant pool
desiredIndex
,
final String
class to use to generate a subset of the pool
desiredClassName
)

Subset the constant pool of the specified type to be just that which has the specified class name.

public ConstantPoolEntry
getConstantPoolEntry(final int cp, final long value)

public ConstantPoolEntry

Returns:

CPMethod init method
getInitMethodPoolEntry
(final int
constant pool to search (must be CP_METHOD)
cp
,
final long
index of init method
value
,
final String
String class name of the init method
desiredClassName
)

Answer the init method for the specified class.

public ClassFileEntry
getValue(final int cp, final long value)

protected int

Returns:

int index into nameArray, or -1 if not found.
matchSpecificPoolEntryIndex
(final String[]
Array of Strings against which the compareString is tested
nameArray
,
final String
String for which to search
compareString
,
final int
nth element with that match (counting from 0)
desiredIndex
)

A number of things make use of subsets of structures.

protected int

Returns:

int index that represents the position of the nth hit in primaryArray and secondaryArray
matchSpecificPoolEntryIndex
(final String[]
The first array to search
primaryArray
,
final String[]
The second array (must be same .length as primaryArray)
secondaryArray
,
final String
The String to compare against primaryArray using .equals()
primaryCompareString
,
final String
The String to compare against secondaryArray using .matches()
secondaryCompareRegex
,
final int
The nth hit whose position we're seeking
desiredIndex
)

This method's function is to look through pairs of arrays.

protected static boolean

Returns:

boolean true if the compareString matches the regexString; otherwise false.
regexMatches
(final String
String against which the compareString will be matched
regexString
,
final String
String to match against the regexString
compareString
)

We don't want a dependency on regex in Pack200.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLback to summary
public static final int ALL
arrayCacheback to summary
private final SegmentConstantPoolArrayCache arrayCache
bandsback to summary
private final CpBands bands
CP_CLASSback to summary
public static final int CP_CLASS
CP_DESCRback to summary
public static final int CP_DESCR
CP_DOUBLEback to summary
public static final int CP_DOUBLE
CP_FIELDback to summary
public static final int CP_FIELD
CP_FLOATback to summary
public static final int CP_FLOAT
CP_IMETHODback to summary
public static final int CP_IMETHOD
CP_INTback to summary
public static final int CP_INT
CP_LONGback to summary
public static final int CP_LONG
CP_METHODback to summary
public static final int CP_METHOD
CP_STRINGback to summary
public static final int CP_STRING
INITSTRINGback to summary
protected static final String INITSTRING
REGEX_MATCH_ALLback to summary
protected static final String REGEX_MATCH_ALL
REGEX_MATCH_INITback to summary
protected static final String REGEX_MATCH_INIT
SIGNATUREback to summary
public static final int SIGNATURE
UTF_8back to summary
public static final int UTF_8

Constructor Detail

SegmentConstantPoolback to summary
public SegmentConstantPool(final CpBands bands)
Parameters
bands:CpBands

TODO

Method Detail

getClassPoolEntryback to summary
public ConstantPoolEntry getClassPoolEntry(final String name)

Given the name of a class, answer the CPClass associated with that class. Answer null if the class doesn't exist.

Parameters
name:String

Class name to look for (form: java/lang/Object)

Returns:ConstantPoolEntry

CPClass for that class name, or null if not found.

getClassSpecificPoolEntryback to summary
public ConstantPoolEntry getClassSpecificPoolEntry(final int cp, final long desiredIndex, final String desiredClassName) throws Pack200Exception

Subset the constant pool of the specified type to be just that which has the specified class name. Answer the ConstantPoolEntry at the desiredIndex of the subsetted pool.

Parameters
cp:int

type of constant pool array to search

desiredIndex:long

index of the constant pool

desiredClassName:String

class to use to generate a subset of the pool

Returns:ConstantPoolEntry

ConstantPoolEntry

Exceptions
Pack200Exception:
TODO
getConstantPoolEntryback to summary
public ConstantPoolEntry getConstantPoolEntry(final int cp, final long value) throws Pack200Exception
getInitMethodPoolEntryback to summary
public ConstantPoolEntry getInitMethodPoolEntry(final int cp, final long value, final String desiredClassName) throws Pack200Exception

Answer the init method for the specified class.

Parameters
cp:int

constant pool to search (must be CP_METHOD)

value:long

index of init method

desiredClassName:String

String class name of the init method

Returns:ConstantPoolEntry

CPMethod init method

Exceptions
Pack200Exception:
TODO
getValueback to summary
public ClassFileEntry getValue(final int cp, final long value) throws Pack200Exception
matchSpecificPoolEntryIndexback to summary
protected int matchSpecificPoolEntryIndex(final String[] nameArray, final String compareString, final int desiredIndex)

A number of things make use of subsets of structures. In one particular example, _super bytecodes will use a subset of method or field classes which have just those methods / fields defined in the superclass. Similarly, _this bytecodes use just those methods/fields defined in this class, and _init bytecodes use just those methods that start with <init>. This method takes an array of names, a String to match for, an index and a boolean as parameters, and answers the array position in the array of the indexth element which matches (or equals) the String (depending on the state of the boolean) In other words, if the class array consists of: Object [position 0, 0th instance of Object] String [position 1, 0th instance of String] String [position 2, 1st instance of String] Object [position 3, 1st instance of Object] Object [position 4, 2nd instance of Object] then matchSpecificPoolEntryIndex(..., "Object", 2, false) will answer 4. matchSpecificPoolEntryIndex(..., "String", 0, false) will answer 1.

Parameters
nameArray:String[]

Array of Strings against which the compareString is tested

compareString:String

String for which to search

desiredIndex:int

nth element with that match (counting from 0)

Returns:int

int index into nameArray, or -1 if not found.

matchSpecificPoolEntryIndexback to summary
protected int matchSpecificPoolEntryIndex(final String[] primaryArray, final String[] secondaryArray, final String primaryCompareString, final String secondaryCompareRegex, final int desiredIndex)

This method's function is to look through pairs of arrays. It keeps track of the number of hits it finds using the following basis of comparison for a hit: - the primaryArray[index] must be .equals() to the primaryCompareString - the secondaryArray[index] .matches() the secondaryCompareString. When the desiredIndex number of hits has been reached, the index into the original two arrays of the element hit is returned.

Parameters
primaryArray:String[]

The first array to search

secondaryArray:String[]

The second array (must be same .length as primaryArray)

primaryCompareString:String

The String to compare against primaryArray using .equals()

secondaryCompareRegex:String

The String to compare against secondaryArray using .matches()

desiredIndex:int

The nth hit whose position we're seeking

Returns:int

int index that represents the position of the nth hit in primaryArray and secondaryArray

regexMatchesback to summary
protected static boolean regexMatches(final String regexString, final String compareString)

We don't want a dependency on regex in Pack200. The only place one exists is in matchSpecificPoolEntryIndex(). To eliminate this dependency, we've implemented the world's stupidest regexMatch. It knows about the two forms we care about: .* (aka REGEX_MATCH_ALL) ^<init>;.* (aka REGEX_MATCH_INIT) and will answer correctly if those are passed as the regexString.

Parameters
regexString:String

String against which the compareString will be matched

compareString:String

String to match against the regexString

Returns:boolean

boolean true if the compareString matches the regexString; otherwise false.