public static Name getInterfaceName(String defaultInterfaceName) { String[] pieces = defaultInterfaceName.split(REGEX_DELIMITER); String resource = pieces[pieces.length - 1]; return Name.anyCamel(Inflector.singularize(resource)); }
private String getAndSaveResourceTypeFactoryName( ImportTypeTable typeTable, FieldConfig fieldConfig) { String resourceClassName = publicClassName(getResourceTypeNameObject(fieldConfig.getResourceNameConfig())); return typeTable.getAndSaveNicknameForTypedResourceName( fieldConfig, Inflector.pluralize(resourceClassName)); }
/** Get the request type name from a method. */ public static Name getRequestName(Method method) { String[] pieces = method.id().split(REGEX_DELIMITER); String methodName = pieces[pieces.length - 1]; String resourceName = pieces[pieces.length - 2]; if (!method.isPluralMethod()) { resourceName = Inflector.singularize(resourceName); } return Name.anyCamel(methodName, resourceName, "http", "request"); }
/** * Return the name of the fully qualified resource from a given canonicalized path. Use {@link * #getCanonicalPath(String)}} for canonicalization of the parameter. This method includes all * segments from the input path in the resulting Name except for consecutive duplicate segments. */ public static Name getQualifiedResourceIdentifier(String canonicalPath) { String[] pieces = canonicalPath.split(PATH_DELIMITER); Name name = Name.from(); String previous = null; for (String segment : pieces) { String next = segment; if (segment.contains("}")) { next = segment.substring(1, segment.length() - 1); } next = Inflector.singularize(next); if (!next.equals(previous)) { // Only append to the name if this segment is not identical to the previous segment. name = name.join(stringToName(next)); previous = next; } } return name; }
@Test public void testSingularize() { assertThat(Inflector.singularize("blesses")).isEqualTo("bless"); assertThat(Inflector.singularize("cares")).isEqualTo("care"); assertThat(Inflector.singularize("cars")).isEqualTo("car"); assertThat(Inflector.singularize("fishes")).isEqualTo("fish"); assertThat(Inflector.singularize("fuzzes")).isEqualTo("fuzz"); assertThat(Inflector.singularize("halves")).isEqualTo("half"); assertThat(Inflector.singularize("licenses")).isEqualTo("license"); assertThat(Inflector.singularize("scarves")).isEqualTo("scarf"); assertThat(Inflector.singularize("sneezes")).isEqualTo("sneeze"); } }
if (lastSegment != null && lastSegment instanceof LiteralSegment) { name = LanguageUtil.upperCamelToLowerUnderscore(Inflector.singularize(lastSegment.syntax()));
/** * Formats the method as a Name. Methods are generally in the format * "[api].[resource].[function]". */ public static Name methodAsName(Method method) { String[] pieces = method.id().split(REGEX_DELIMITER); String resourceLastName = pieces[pieces.length - 2]; if (!method.isPluralMethod()) { resourceLastName = Inflector.singularize(resourceLastName); } Name resource = Name.anyCamel(resourceLastName); for (int i = pieces.length - 3; i > 0; i--) { resource = Name.anyCamel(pieces[i]).join(resource); } Name function = Name.anyCamel(pieces[pieces.length - 1]); return function.join(resource); }