public String parseNext ( ) { StringBuilder result = new StringBuilder ( ) ; if ( signature . startsWith ( "[" ) ) { int dimensions = 0 ; do { ++ dimensions ; signature = signature . substring ( 1 ) ; } while ( signature . charAt ( 0 ) == ' ' ) ; result . append ( parseNext ( ) ) ; while ( dimensions -- > 0 ) { result . append ( "[]" ) ; } } else if ( signature . startsWith ( "L" ) ) { int semi = signature . indexOf ( ' ' ) ; if ( semi < 0 ) { throw new IllegalStateException ( "missing semicolon in signature " + signature ) ; } result . append ( signature . substring ( 1 , semi ) . replace ( ' ' , ' ' ) ) ; signature = signature . substring ( semi + 1 ) ; } else { switch ( signature . charAt ( 0 ) ) { case ' ' : result . append ( "byte" ) ; break ; case ' ' : result . append ( "char" ) ; break ; case ' ' : result . append ( "double" ) ; break ; case ' ' : result . append ( "float" ) ; break ; case ' ' : result . append ( "int" ) ; break ; case ' ' : result . append ( "long" ) ; break ; case ' ' : result . append ( "short" ) ; break ; case ' ' : result . append ( "boolean" ) ; break ; case ' ' : result . append ( "void" ) ; break ; default : throw new IllegalArgumentException ( "bad signature " + signature ) ; } skip ( ) ; } return result . toString ( ) ; }
Parse a single type out of the signature starting at the beginning of the remaining part of the signature . For example if the first character of the remaining part is I then this method will return int and the I will be consumed . Arrays reference types and basic types are all handled .