String (@NotNull String name) { // All non-alphanumeric characters ([^A-Za-z0-9]) are replaced with a dot (".") ... name = NON_NAME.matcher(name).replaceAll("."); // ... all repeating dots are replaced with one dot ... name = DOT_SEQUENCE.matcher(name).replaceAll("."); // ... and all leading and trailing dots are removed. name = StringUtil.trimLeading(StringUtil.trimTrailing(name, '.'), '.'); // sanitize keywords and leading digits String[] parts = splitByDots(name); StringBuilder builder = new StringBuilder(); boolean first = true; for (String part : parts) { if (part.length() == 0) { continue; } if (Character.isJavaIdentifierStart(part.charAt(0))) { if (!first) { builder.append('.'); } builder.append(part); if (JavaLexer.isKeyword(part, LanguageLevel.JDK_1_9)) { builder.append('x'); } } else { // it's a leading digit if (first) { builder.append("module"); } builder.append(part); } first = false; } return builder.toString(); }