String getClassName ( String name ) { char [ ] s = new char [ name . length ( ) + 1 ] ; char c ; int j = 0 ; if ( ! Character . isJavaIdentifierStart ( name . charAt ( 0 ) ) ) { s [ j ++ ] = ' ' ; } for ( int i = 0 ; i < name . length ( ) ; i ++ , j ++ ) { c = name . charAt ( i ) ; if ( Character . isJavaIdentifierPart ( c ) ) { s [ j ] = c ; } else { s [ j ] = ' ' ; } } return ( new String ( s ) ) . trim ( ) ; }
Verify that class file names are legal Java identifiers . Substitute illegal characters with underscores and prepend the name with an underscore if the file name does not begin with a JavaLetter .