Class SegmentConstantPool
- java.lang.Object
-
- org.apache.commons.compress.harmony.unpack200.SegmentConstantPool
-
public class SegmentConstantPool extends java.lang.Object
Manages the constant pool used for re-creating class files.
-
-
Field Summary
Fields Modifier and Type Field Description static intALLValue 0.static intCP_CLASSValue 7.static intCP_DESCRValue 9.static intCP_DOUBLEValue 5.static intCP_FIELDValue 10.static intCP_FLOATValue 3.static intCP_IMETHODValue 12.static intCP_INTValue 2.static intCP_LONGValue 4.static intCP_METHODValue 11.static intCP_STRINGValue 6.protected static java.lang.StringINITSTRINGValue "<init>".protected static java.lang.StringREGEX_MATCH_ALLValue ".*".protected static java.lang.StringREGEX_MATCH_INITValue "^<init>.*".static intSIGNATUREValue 8.static intUTF_8Value 1.
-
Constructor Summary
Constructors Constructor Description SegmentConstantPool(CpBands bands)Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConstantPoolEntrygetClassPoolEntry(java.lang.String name)Gets the CPClass associated with a class name.ConstantPoolEntrygetClassSpecificPoolEntry(int cp, long desiredIndex, java.lang.String desiredClassName)Gets the subset constant pool of the specified type to be just that which has the specified class name.ConstantPoolEntrygetConstantPoolEntry(int type, long index)Gets the constant pool entry of the given type and index.ConstantPoolEntrygetInitMethodPoolEntry(int cp, long value, java.lang.String desiredClassName)Gets theinitmethod for the specified class.ClassFileEntrygetValue(int cp, long longIndex)protected intmatchSpecificPoolEntryIndex(java.lang.String[] primaryArray, java.lang.String[] secondaryArray, java.lang.String primaryCompareString, java.lang.String secondaryCompareRegex, int desiredIndex)This method's function is to look through pairs of arrays.protected intmatchSpecificPoolEntryIndex(java.lang.String[] nameArray, java.lang.String compareString, int desiredIndex)A number of things make use of subsets of structures.protected static booleanregexMatches(java.lang.String regexString, java.lang.String compareString)We don't want a dependency on regex in Pack200.
-
-
-
Field Detail
-
ALL
public static final int ALL
Value 0.- See Also:
- Constant Field Values
-
UTF_8
public static final int UTF_8
Value 1.- See Also:
- Constant Field Values
-
CP_INT
public static final int CP_INT
Value 2.- See Also:
- Constant Field Values
-
CP_FLOAT
public static final int CP_FLOAT
Value 3.- See Also:
- Constant Field Values
-
CP_LONG
public static final int CP_LONG
Value 4.- See Also:
- Constant Field Values
-
CP_DOUBLE
public static final int CP_DOUBLE
Value 5.- See Also:
- Constant Field Values
-
CP_STRING
public static final int CP_STRING
Value 6.- See Also:
- Constant Field Values
-
CP_CLASS
public static final int CP_CLASS
Value 7.- See Also:
- Constant Field Values
-
SIGNATURE
public static final int SIGNATURE
Value 8.- See Also:
- Constant Field Values
-
CP_DESCR
public static final int CP_DESCR
Value 9.- See Also:
- Constant Field Values
-
CP_FIELD
public static final int CP_FIELD
Value 10.- See Also:
- Constant Field Values
-
CP_METHOD
public static final int CP_METHOD
Value 11.- See Also:
- Constant Field Values
-
CP_IMETHOD
public static final int CP_IMETHOD
Value 12.- See Also:
- Constant Field Values
-
REGEX_MATCH_ALL
protected static final java.lang.String REGEX_MATCH_ALL
Value ".*".- See Also:
- Constant Field Values
-
INITSTRING
protected static final java.lang.String INITSTRING
Value "<init>".- See Also:
- Constant Field Values
-
REGEX_MATCH_INIT
protected static final java.lang.String REGEX_MATCH_INIT
Value "^<init>.*".- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SegmentConstantPool
public SegmentConstantPool(CpBands bands)
Constructs a new instance.- Parameters:
bands- Constant pool bands.
-
-
Method Detail
-
regexMatches
protected static boolean regexMatches(java.lang.String regexString, java.lang.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 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
public ConstantPoolEntry getClassPoolEntry(java.lang.String name) throws Pack200Exception
Gets the CPClass associated with a class name. Returns 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.
- Throws:
Pack200Exception- if a type is not supported or an index not in the range [0,Integer.MAX_VALUE].
-
getClassSpecificPoolEntry
public ConstantPoolEntry getClassSpecificPoolEntry(int cp, long desiredIndex, java.lang.String desiredClassName) throws Pack200Exception
Gets the subset constant pool of the specified type to be just that which has the specified class name. Answer the ConstantPoolEntry at the desiredIndex of the subset pool.- Parameters:
cp- type of constant pool array to search.desiredIndex- index of the constant pool.desiredClassName- class to use to generate a subset of the pool.- Returns:
- ConstantPoolEntry
- Throws:
Pack200Exception- if a type is not supported or an index not in the range [0,Integer.MAX_VALUE].
-
getConstantPoolEntry
public ConstantPoolEntry getConstantPoolEntry(int type, long index) throws Pack200Exception
Gets the constant pool entry of the given type and index.- Parameters:
type- Constant pool type.index- Index into a specific constant pool.- Returns:
- a constant pool entry.
- Throws:
Pack200Exception- if a type is not supported or the index not in the range [0,Integer.MAX_VALUE].
-
getInitMethodPoolEntry
public ConstantPoolEntry getInitMethodPoolEntry(int cp, long value, java.lang.String desiredClassName) throws Pack200Exception
Gets theinitmethod for the specified class.- Parameters:
cp- constant pool to search, must beCP_METHOD.value- index ofinitmethod.desiredClassName- String class name of theinitmethod.- Returns:
- CPMethod
initmethod. - Throws:
Pack200Exception- if a type is not supported or an index not in the range [0,Integer.MAX_VALUE].
-
getValue
public ClassFileEntry getValue(int cp, long longIndex) throws Pack200Exception
- Throws:
Pack200Exception
-
matchSpecificPoolEntryIndex
protected int matchSpecificPoolEntryIndex(java.lang.String[] nameArray, java.lang.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(java.lang.String[] primaryArray, java.lang.String[] secondaryArray, java.lang.String primaryCompareString, java.lang.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
-
-