private static Type doParse ( String str ) throws Exception { Class < ? > token = PRIMITIVES . get ( str ) ; if ( token != null ) { return token ; } int first = str . indexOf ( ' ' ) ; if ( first < 0 ) { return StringConvert . loadType ( str ) ; } int last = str . lastIndexOf ( ' ' ) ; String baseStr = str . substring ( 0 , first ) ; Class < ? > base = StringConvert . loadType ( baseStr ) ; String argsStr = str . substring ( first + 1 , last ) ; List < String > splitArgs = split ( argsStr ) ; List < Type > types = new ArrayList < Type > ( ) ; for ( String splitArg : splitArgs ) { Type argType ; if ( splitArg . startsWith ( EXTENDS ) ) { String remainder = splitArg . substring ( EXTENDS . length ( ) ) ; argType = wildExtendsType ( doParse ( remainder ) ) ; } else if ( splitArg . startsWith ( SUPER ) ) { String remainder = splitArg . substring ( SUPER . length ( ) ) ; argType = wildSuperType ( doParse ( remainder ) ) ; } else if ( splitArg . equals ( "?" ) ) { argType = wildExtendsType ( Object . class ) ; } else if ( splitArg . endsWith ( "[]" ) ) { String componentStr = splitArg . substring ( 0 , splitArg . length ( ) - 2 ) ; Class < ? > componentCls = StringConvert . loadType ( componentStr ) ; argType = Array . newInstance ( componentCls , 0 ) . getClass ( ) ; } else if ( splitArg . startsWith ( "[L" ) && splitArg . endsWith ( ";" ) ) { String componentStr = splitArg . substring ( 2 , splitArg . length ( ) - 1 ) ; Class < ? > componentCls = StringConvert . loadType ( componentStr ) ; argType = Array . newInstance ( componentCls , 0 ) . getClass ( ) ; } else { argType = doParse ( splitArg ) ; } types . add ( argType ) ; } return newParameterizedType ( base , types . toArray ( new Type [ types . size ( ) ] ) ) ; }
parse an element