parent
7bee1fdb71
commit
4458799e06
|
|
@ -694,7 +694,7 @@ final class MethodWriter extends MethodVisitor {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
if (lastRuntimeVisibleParameterAnnotations == null) {
|
if (lastRuntimeVisibleParameterAnnotations == null) {
|
||||||
lastRuntimeVisibleParameterAnnotations =
|
lastRuntimeVisibleParameterAnnotations =
|
||||||
new AnnotationWriter[Type.getArgumentTypes(descriptor).length];
|
new AnnotationWriter[Type.getArgumentCount(descriptor)];
|
||||||
}
|
}
|
||||||
return lastRuntimeVisibleParameterAnnotations[parameter] =
|
return lastRuntimeVisibleParameterAnnotations[parameter] =
|
||||||
AnnotationWriter.create(
|
AnnotationWriter.create(
|
||||||
|
|
@ -702,7 +702,7 @@ final class MethodWriter extends MethodVisitor {
|
||||||
} else {
|
} else {
|
||||||
if (lastRuntimeInvisibleParameterAnnotations == null) {
|
if (lastRuntimeInvisibleParameterAnnotations == null) {
|
||||||
lastRuntimeInvisibleParameterAnnotations =
|
lastRuntimeInvisibleParameterAnnotations =
|
||||||
new AnnotationWriter[Type.getArgumentTypes(descriptor).length];
|
new AnnotationWriter[Type.getArgumentCount(descriptor)];
|
||||||
}
|
}
|
||||||
return lastRuntimeInvisibleParameterAnnotations[parameter] =
|
return lastRuntimeInvisibleParameterAnnotations[parameter] =
|
||||||
AnnotationWriter.create(
|
AnnotationWriter.create(
|
||||||
|
|
|
||||||
|
|
@ -295,26 +295,12 @@ public final class Type {
|
||||||
*/
|
*/
|
||||||
public static Type[] getArgumentTypes(final String methodDescriptor) {
|
public static Type[] getArgumentTypes(final String methodDescriptor) {
|
||||||
// First step: compute the number of argument types in methodDescriptor.
|
// First step: compute the number of argument types in methodDescriptor.
|
||||||
int numArgumentTypes = 0;
|
int numArgumentTypes = getArgumentCount(methodDescriptor);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second step: create a Type instance for each argument type.
|
// Second step: create a Type instance for each argument type.
|
||||||
Type[] argumentTypes = new Type[numArgumentTypes];
|
Type[] argumentTypes = new Type[numArgumentTypes];
|
||||||
// Skip the first character, which is always a '('.
|
// Skip the first character, which is always a '('.
|
||||||
currentOffset = 1;
|
int currentOffset = 1;
|
||||||
// Parse and create the argument types, one at each loop iteration.
|
// Parse and create the argument types, one at each loop iteration.
|
||||||
int currentArgumentTypeIndex = 0;
|
int currentArgumentTypeIndex = 0;
|
||||||
while (methodDescriptor.charAt(currentOffset) != ')') {
|
while (methodDescriptor.charAt(currentOffset) != ')') {
|
||||||
|
|
@ -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
|
* 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.
|
* should only be used for method types.
|
||||||
|
|
@ -709,7 +732,8 @@ public final class Type {
|
||||||
* @return the size of the arguments of the method (plus one for the implicit this argument),
|
* @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 =
|
* 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
|
* {@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() {
|
public int getArgumentsAndReturnSizes() {
|
||||||
return getArgumentsAndReturnSizes(getDescriptor());
|
return getArgumentsAndReturnSizes(getDescriptor());
|
||||||
|
|
@ -722,7 +746,8 @@ public final class Type {
|
||||||
* @return the size of the arguments of the method (plus one for the implicit this argument),
|
* @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 =
|
* 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
|
* {@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) {
|
public static int getArgumentsAndReturnSizes(final String methodDescriptor) {
|
||||||
int argumentsSize = 1;
|
int argumentsSize = 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue