@@ -3219,21 +3219,15 @@ protected void addParentContainer(CodegenModel m, String name, Property property
32193219 * @return The underscored version of the word
32203220 */
32213221 public static String underscore (String word ) {
3222- String firstPattern = "( [A-Z]+)( [A-Z][a-z][a-z]+)" ;
3223- String secondPattern = "( [a-z\\ d])([A-Z])" ;
3222+ Pattern firstPattern = Pattern . compile ( "(?<= [A-Z])(?= [A-Z][a-z]{2,})" ) ;
3223+ Pattern secondPattern = Pattern . compile ( "(?<= [a-z\\ d])(?= [A-Z])") ;
32243224 String replacementPattern = "$1_$2" ;
3225- // Replace package separator with slash.
3226- word = word .replaceAll ("\\ ." , "/" ); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
3227- // Replace $ with two underscores for inner classes.
3228- word = word .replaceAll ("\\ $" , "__" );
3229- // Replace capital letter with _ plus lowercase letter.
3230- word = word .replaceAll (firstPattern , replacementPattern );
3231- word = word .replaceAll (secondPattern , replacementPattern );
3232- word = word .replace ('-' , '_' );
3233- // replace space with underscore
3234- word = word .replace (' ' , '_' );
3235- word = word .toLowerCase ();
3236- return word ;
3225+
3226+ String replaced = word .replace ('.' , '/' ).replace ("$" , "__" );
3227+ replaced = firstPattern .matcher (replaced ).replaceAll ("_" );
3228+ replaced = secondPattern .matcher (replaced ).replaceAll ("_" );
3229+ replaced = replaced .replace ('-' , '_' ).replace (' ' , '_' ).toLowerCase ();
3230+ return replaced ;
32373231 }
32383232
32393233 /**
0 commit comments