|
|
|
@ -295,26 +295,12 @@ public final class Type {
@@ -295,26 +295,12 @@ public final class Type {
|
|
|
|
|
*/ |
|
|
|
|
public static Type[] getArgumentTypes(final String methodDescriptor) { |
|
|
|
|
// First step: compute the number of argument types in methodDescriptor.
|
|
|
|
|
int numArgumentTypes = 0; |
|
|
|
|
// Skip the first character, which is always a '('.
|
|
|
|
|
int currentOffset = 1; |
|
|
|
|
// Parse the argument types, one at a each loop iteration.
|
|
|
|
|
while (methodDescriptor.charAt(currentOffset) != ')') { |
|
|
|
|
while (methodDescriptor.charAt(currentOffset) == '[') { |
|
|
|
|
currentOffset++; |
|
|
|
|
} |
|
|
|
|
if (methodDescriptor.charAt(currentOffset++) == 'L') { |
|
|
|
|
// Skip the argument descriptor content.
|
|
|
|
|
int semiColumnOffset = methodDescriptor.indexOf(';', currentOffset); |
|
|
|
|
currentOffset = Math.max(currentOffset, semiColumnOffset + 1); |
|
|
|
|
} |
|
|
|
|
++numArgumentTypes; |
|
|
|
|
} |
|
|
|
|
int numArgumentTypes = getArgumentCount(methodDescriptor); |
|
|
|
|
|
|
|
|
|
// Second step: create a Type instance for each argument type.
|
|
|
|
|
Type[] argumentTypes = new Type[numArgumentTypes]; |
|
|
|
|
// Skip the first character, which is always a '('.
|
|
|
|
|
currentOffset = 1; |
|
|
|
|
int currentOffset = 1; |
|
|
|
|
// Parse and create the argument types, one at each loop iteration.
|
|
|
|
|
int currentArgumentTypeIndex = 0; |
|
|
|
|
while (methodDescriptor.charAt(currentOffset) != ')') { |
|
|
|
@ -702,6 +688,43 @@ public final class Type {
@@ -702,6 +688,43 @@ public final class Type {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the number of arguments of this method type. This method should only be used for method |
|
|
|
|
* types. |
|
|
|
|
* |
|
|
|
|
* @return the number of arguments of this method type. Each argument counts for 1, even long and |
|
|
|
|
* double ones. The implicit @literal{this} argument is not counted. |
|
|
|
|
*/ |
|
|
|
|
public int getArgumentCount() { |
|
|
|
|
return getArgumentCount(getDescriptor()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the number of arguments in the given method descriptor. |
|
|
|
|
* |
|
|
|
|
* @param methodDescriptor a method descriptor. |
|
|
|
|
* @return the number of arguments in the given method descriptor. Each argument counts for 1, |
|
|
|
|
* even long and double ones. The implicit @literal{this} argument is not counted. |
|
|
|
|
*/ |
|
|
|
|
public static int getArgumentCount(final String methodDescriptor) { |
|
|
|
|
int argumentCount = 0; |
|
|
|
|
// Skip the first character, which is always a '('.
|
|
|
|
|
int currentOffset = 1; |
|
|
|
|
// Parse the argument types, one at a each loop iteration.
|
|
|
|
|
while (methodDescriptor.charAt(currentOffset) != ')') { |
|
|
|
|
while (methodDescriptor.charAt(currentOffset) == '[') { |
|
|
|
|
currentOffset++; |
|
|
|
|
} |
|
|
|
|
if (methodDescriptor.charAt(currentOffset++) == 'L') { |
|
|
|
|
// Skip the argument descriptor content.
|
|
|
|
|
int semiColumnOffset = methodDescriptor.indexOf(';', currentOffset); |
|
|
|
|
currentOffset = Math.max(currentOffset, semiColumnOffset + 1); |
|
|
|
|
} |
|
|
|
|
++argumentCount; |
|
|
|
|
} |
|
|
|
|
return argumentCount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the size of the arguments and of the return value of methods of this type. This method |
|
|
|
|
* should only be used for method types. |
|
|
|
@ -709,7 +732,8 @@ public final class Type {
@@ -709,7 +732,8 @@ public final class Type {
|
|
|
|
|
* @return the size of the arguments of the method (plus one for the implicit this argument), |
|
|
|
|
* argumentsSize, and the size of its return value, returnSize, packed into a single int i = |
|
|
|
|
* {@code (argumentsSize << 2) | returnSize} (argumentsSize is therefore equal to {@code |
|
|
|
|
* i >> 2}, and returnSize to {@code i & 0x03}). |
|
|
|
|
* i >> 2}, and returnSize to {@code i & 0x03}). Long and double values have size 2, |
|
|
|
|
* the others have size 1. |
|
|
|
|
*/ |
|
|
|
|
public int getArgumentsAndReturnSizes() { |
|
|
|
|
return getArgumentsAndReturnSizes(getDescriptor()); |
|
|
|
@ -722,7 +746,8 @@ public final class Type {
@@ -722,7 +746,8 @@ public final class Type {
|
|
|
|
|
* @return the size of the arguments of the method (plus one for the implicit this argument), |
|
|
|
|
* argumentsSize, and the size of its return value, returnSize, packed into a single int i = |
|
|
|
|
* {@code (argumentsSize << 2) | returnSize} (argumentsSize is therefore equal to {@code |
|
|
|
|
* i >> 2}, and returnSize to {@code i & 0x03}). |
|
|
|
|
* i >> 2}, and returnSize to {@code i & 0x03}). Long and double values have size 2, |
|
|
|
|
* the others have size 1. |
|
|
|
|
*/ |
|
|
|
|
public static int getArgumentsAndReturnSizes(final String methodDescriptor) { |
|
|
|
|
int argumentsSize = 1; |
|
|
|
|