private String reduceName ( String newClassName , String suffix ) { if ( newClassName . length ( ) < MAX_FILE_NAME_LENGTH ) { return newClassName ; } // String sufx = "_Gen_GwtJackEncDec_"; //Lets first try to reduce the package name of the parametrized types // according to parametersName2ClassName parametrized types //Lets find if there are parametrized types String noSufix = newClassName . substring ( 0 , newClassName . length ( ) - suffix . length ( ) ) ; if ( newClassName . indexOf ( "__" ) > 0 ) { //has generic String primaryName = noSufix . substring ( 0 , noSufix . indexOf ( "__" ) ) ; String genericPart = noSufix . substring ( noSufix . indexOf ( "__" ) + 2 ) ; StringBuilder stringBuilder = new StringBuilder ( ) ; String [ ] eachGeneric = genericPart . split ( "__" ) ; for ( String genericType : eachGeneric ) { stringBuilder . append ( "__" ) ; stringBuilder . append ( reduceType ( genericType ) ) ; } String finalName = primaryName + stringBuilder . toString ( ) + suffix ; if ( finalName . length ( ) > MAX_FILE_NAME_LENGTH ) { //File name is still too long wrapping it out aggressively String baseName = primaryName + stringBuilder . toString ( ) ; int firstPosition = baseName . indexOf ( "__" ) ; int lastPosition = baseName . lastIndexOf ( "__" ) ; String middle = baseName . substring ( firstPosition , lastPosition ) ; finalName = baseName . substring ( 0 , firstPosition ) + middle . subSequence ( 0 , 4 ) + "_" + ( middle . length ( ) - 5 ) + "_" + middle . substring ( middle . length ( ) - 9 ) + baseName . substring ( lastPosition ) + suffix ; return finalName ; } return finalName ; } //If there is no generic type lets give an error and force the client to reduce className return newClassName ; }
Lets have class name less than 200 to allow new generators safelly to add more sufixes there if needed