public static TypeDesc forDescriptor ( final String desc ) throws IllegalArgumentException { TypeDesc type = cDescriptorsToInstances . get ( desc ) ; if ( type != null ) { return type ; } // TODO: Support generics in descriptor. String rootDesc = desc ; int cursor = 0 ; int dim = 0 ; try { char c ; while ( ( c = rootDesc . charAt ( cursor ++ ) ) == ' ' ) { dim ++ ; } switch ( c ) { case ' ' : type = VOID ; break ; case ' ' : type = BOOLEAN ; break ; case ' ' : type = CHAR ; break ; case ' ' : type = BYTE ; break ; case ' ' : type = SHORT ; break ; case ' ' : type = INT ; break ; case ' ' : type = LONG ; break ; case ' ' : type = FLOAT ; break ; case ' ' : type = DOUBLE ; break ; case ' ' : if ( dim > 0 ) { rootDesc = rootDesc . substring ( dim ) ; cursor = 1 ; } StringBuffer name = new StringBuffer ( rootDesc . length ( ) - 2 ) ; while ( ( c = rootDesc . charAt ( cursor ++ ) ) != ' ' ) { if ( c == ' ' ) { c = ' ' ; } name . append ( c ) ; } type = intern ( new ObjectType ( rootDesc , name . toString ( ) ) ) ; break ; default : throw invalidDescriptor ( desc ) ; } } catch ( NullPointerException e ) { throw invalidDescriptor ( desc ) ; } catch ( IndexOutOfBoundsException e ) { throw invalidDescriptor ( desc ) ; } if ( cursor != rootDesc . length ( ) ) { throw invalidDescriptor ( desc ) ; } while ( -- dim >= 0 ) { type = type . toArrayType ( ) ; } cDescriptorsToInstances . put ( desc , type ) ; return type ; }
Acquire a TypeDesc from a type descriptor .