public static String sanitizeMethodName(String methodName){
  assert (methodName != null && methodName.length() > 0);
  StringBuilder sb=new StringBuilder();
  char firstChar=methodName.charAt(0);
  if (Character.isJavaIdentifierStart(firstChar)) {
    if (Character.isUpperCase(firstChar)) {
      firstChar=Character.toLowerCase(firstChar);
    }
    sb.append(firstChar);
  }
  boolean previousCharWasDropped=false;
  for (int i=1; i < methodName.length(); i++) {
    char ch=methodName.charAt(i);
    if (Character.isLetterOrDigit(ch)) {
      if (previousCharWasDropped) {
        ch=Character.toUpperCase(ch);
      }
      sb.append(ch);
      previousCharWasDropped=false;
    }
 else {
      previousCharWasDropped=true;
    }
  }
  if (sb.length() == 0) {
    sb.append("_method");
  }
  return sb.toString();
}

public static String sanitizeMethodName ( String methodName ) { assert ( methodName != null && methodName . length ( ) > 0 ) ; StringBuilder sb = new StringBuilder ( ) ; char firstChar = methodName . charAt ( 0 ) ; if ( Character . isJavaIdentifierStart ( firstChar ) ) { if ( Character . isUpperCase ( firstChar ) ) { firstChar = Character . toLowerCase ( firstChar ) ; } sb . append ( firstChar ) ; } boolean previousCharWasDropped = false ; for ( int i = 1 ; i < methodName . length ( ) ; i ++ ) { char ch = methodName . charAt ( i ) ; if ( Character . isLetterOrDigit ( ch ) ) { if ( previousCharWasDropped ) { ch = Character . toUpperCase ( ch ) ; } sb . append ( ch ) ; previousCharWasDropped = false ; } else { previousCharWasDropped = true ; } } if ( sb . length ( ) == 0 ) { sb . append ( "_method" ) ; } return sb . toString ( ) ; }
sanitizes a potential method name so it is both valid and follows java conventions ( camel - cased , no underscores , etc . ) .
