public static int getArgumentsAndReturnSizes ( final String methodDescriptor ) { int argumentsSize = 1 ; // Skip the first character, which is always a '('. int currentOffset = 1 ; int currentChar = methodDescriptor . charAt ( currentOffset ) ; // Parse the argument types and compute their size, one at a each loop iteration. while ( currentChar != ' ' ) { if ( currentChar == ' ' || currentChar == ' ' ) { currentOffset ++ ; argumentsSize += 2 ; } else { while ( methodDescriptor . charAt ( currentOffset ) == ' ' ) { currentOffset ++ ; } if ( methodDescriptor . charAt ( currentOffset ++ ) == ' ' ) { // Skip the argument descriptor content. currentOffset = methodDescriptor . indexOf ( ' ' , currentOffset ) + 1 ; } argumentsSize += 1 ; } currentChar = methodDescriptor . charAt ( currentOffset ) ; } currentChar = methodDescriptor . charAt ( currentOffset + 1 ) ; if ( currentChar == ' ' ) { return argumentsSize << 2 ; } else { int returnSize = ( currentChar == ' ' || currentChar == ' ' ) ? 2 : 1 ; return argumentsSize << 2 | returnSize ; } }
Computes the size of the arguments and of the return value of a method .