code: public static String cleanName(String name) {
          int index = name.indexOf('-');
          if (index > 0) {
              name = name.substring(0, index);
          }
  
          int length = name.length();
          StringBuffer buf = new StringBuffer(length + 1);
  
          if (!Character.isJavaIdentifierStart(name.charAt(0))) {
              buf.append('_');
          }
          else if (Character.isJavaIdentifierPart(name.charAt(0))) {
              buf.append(name.charAt(0));
          }
  
          for (int i=1; i<length; i++) {
              char c = name.charAt(i);
              if (Character.isJavaIdentifierPart(c)) {
                  buf.append(c);
              }
              else {
                  buf.append('$');
              }
          }
  
          return buf.toString();
      }
docs: Ensures that name only contains valid Java identifiers by converting
  non identifier characters to '$' characters. If name begins with a
  numeral, name is prefixed with an underscore. The returned name is also
  trimmed at the first hyphen character, if there is one. This allows
  multiple applications to appear to provide a unified set of functions.