Class SegmentConstantPool
java.lang.Object
org.apache.commons.compress.harmony.unpack200.SegmentConstantPool
SegmentConstantPool manages the constant pool used for re-creating class files.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
protected static final String
protected static final String
protected static final String
static final int
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetClassPoolEntry
(String name) Given the name of a class, answer the CPClass associated with that class.getClassSpecificPoolEntry
(int cp, long desiredIndex, String desiredClassName) Subset the constant pool of the specified type to be just that which has the specified class name.getConstantPoolEntry
(int cp, long value) getInitMethodPoolEntry
(int cp, long value, String desiredClassName) Answer the init method for the specified class.getValue
(int cp, long value) protected int
matchSpecificPoolEntryIndex
(String[] primaryArray, String[] secondaryArray, String primaryCompareString, String secondaryCompareRegex, int desiredIndex) This method's function is to look through pairs of arrays.protected int
matchSpecificPoolEntryIndex
(String[] nameArray, String compareString, int desiredIndex) A number of things make use of subsets of structures.protected static boolean
regexMatches
(String regexString, String compareString) We don't want a dependency on regex in Pack200.
-
Field Details
-
ALL
- See Also:
-
UTF_8
- See Also:
-
CP_INT
- See Also:
-
CP_FLOAT
- See Also:
-
CP_LONG
- See Also:
-
CP_DOUBLE
- See Also:
-
CP_STRING
- See Also:
-
CP_CLASS
- See Also:
-
SIGNATURE
- See Also:
-
CP_DESCR
- See Also:
-
CP_FIELD
- See Also:
-
CP_METHOD
- See Also:
-
CP_IMETHOD
- See Also:
-
REGEX_MATCH_ALL
- See Also:
-
INITSTRING
- See Also:
-
REGEX_MATCH_INIT
- See Also:
-
-
Constructor Details
-
SegmentConstantPool
- Parameters:
bands
- TODO
-
-
Method Details
-
regexMatches
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 against which the compareString will be matchedcompareString
- String to match against the regexString- Returns:
- boolean true if the compareString matches the regexString; otherwise false.
-
getClassPoolEntry
Given the name of a class, answer the CPClass associated with that class. Answer null if the class doesn't exist.- Parameters:
name
- Class name to look for (form: java/lang/Object)- Returns:
- CPClass for that class name, or null if not found.
-
getClassSpecificPoolEntry
public ConstantPoolEntry getClassSpecificPoolEntry(int cp, long desiredIndex, 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
- type of constant pool array to searchdesiredIndex
- index of the constant pooldesiredClassName
- class to use to generate a subset of the pool- Returns:
- ConstantPoolEntry
- Throws:
Pack200Exception
- TODO
-
getConstantPoolEntry
- Throws:
Pack200Exception
-
getInitMethodPoolEntry
public ConstantPoolEntry getInitMethodPoolEntry(int cp, long value, String desiredClassName) throws Pack200Exception Answer the init method for the specified class.- Parameters:
cp
- constant pool to search (must be CP_METHOD)value
- index of init methoddesiredClassName
- String class name of the init method- Returns:
- CPMethod init method
- Throws:
Pack200Exception
- TODO
-
getValue
- Throws:
Pack200Exception
-
matchSpecificPoolEntryIndex
protected int matchSpecificPoolEntryIndex(String[] nameArray, String compareString, 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
- Array of Strings against which the compareString is testedcompareString
- String for which to searchdesiredIndex
- nth element with that match (counting from 0)- Returns:
- int index into nameArray, or -1 if not found.
-
matchSpecificPoolEntryIndex
protected int matchSpecificPoolEntryIndex(String[] primaryArray, String[] secondaryArray, String primaryCompareString, String secondaryCompareRegex, 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
- The first array to searchsecondaryArray
- The second array (must be same .length as primaryArray)primaryCompareString
- The String to compare against primaryArray using .equals()secondaryCompareRegex
- The String to compare against secondaryArray using .matches()desiredIndex
- The nth hit whose position we're seeking- Returns:
- int index that represents the position of the nth hit in primaryArray and secondaryArray
-