if (callReference != null) { String name = StringUtil.decapitalize(callReference.getIdentifier().getText()); for (String candidate : NameUtil.getSuggestionsByName(name, "", "", false, false, false)) { if (usedNames.contains(candidate)) continue; if (!isValidName(namesValidator, candidate)) continue; if (StringUtil.isNotEmpty(typeText)) { boolean array = GoTypeUtil.isIterable(type) && !GoTypeUtil.isString(type); for (String candidate : NameUtil.getSuggestionsByName(typeText, "", "", false, false, array)) { if (usedNames.contains(candidate) || typeText.equals(candidate)) continue; if (!isValidName(namesValidator, candidate)) continue;
@TestOnly @NotNull public static String toIdentifier(@NotNull String text, @Nullable NameFormat format, @NotNull Case cas) { if (text.isEmpty()) return ""; String fixed = text.replaceAll("[^:\\p{javaJavaIdentifierPart}]", "_"); boolean allCaps = Case.UPPER.apply(fixed).equals(fixed); StringBuilder sb = new StringBuilder(); if (!Character.isJavaIdentifierStart(fixed.charAt(0)) && sb.length() == 0) sb.append("_"); String[] strings = NameUtil.nameToWords(fixed); for (int i = 0, len = strings.length; i < len; i++) { String s = strings[i]; if (cas == Case.CAMEL && s.startsWith("_") && !(i == 0 || i == len - 1)) continue; if (cas == Case.UPPER && !s.startsWith("_") && !(i == 0 || StringUtil.endsWith(sb, "_"))) sb.append("_"); if (cas == Case.CAMEL && !allCaps && Case.UPPER.apply(s).equals(s)) sb.append(s); else sb.append(cas.apply(s)); } return format == null ? sb.toString() : format.apply(sb.toString()); }
@Nullable private static String getRuleDisplayNameRaw(BnfRule rule, boolean force) { String name = getAttribute(rule, KnownAttribute.NAME); BnfRule realRule = rule; if (name != null) { realRule = ((BnfFile)rule.getContainingFile()).getRule(name); if (realRule != null && realRule != rule) name = getAttribute(realRule, KnownAttribute.NAME); } if (name != null || (!force && realRule == rule)) { return name; } else { String[] parts = NameUtil.splitNameIntoWords(getFuncName(realRule)); return Case.LOWER.apply(StringUtil.join(parts, " ")); } }