private static String buildClassName ( Class < ? > type ) { if ( type . isArray ( ) ) { throw new IllegalArgumentException ( "type is an array: " + type ) ; } // get the classname String typeName = type . getName ( ) ; int endIndex = typeName . lastIndexOf ( ' ' ) ; if ( endIndex < 0 ) { return typeName ; } StringBuilder className = new StringBuilder ( typeName . substring ( endIndex + 1 ) ) ; // for innerclasses replace the $ separator with two underscores // we can't just blindly replace all $ characters since class names can contain the $ character if ( type . getDeclaringClass ( ) != null ) { String declaringClassName = getClassName ( type . getDeclaringClass ( ) ) ; assert className . toString ( ) . startsWith ( declaringClassName + "$" ) ; className . replace ( declaringClassName . length ( ) , declaringClassName . length ( ) + 1 , "__" ) ; } // if we have a leading underscore prepend with J if ( className . charAt ( 0 ) == ' ' ) { className . insert ( 0 , "J" ) ; } return className . toString ( ) ; }
Returns a string contianing an encoded class name .