Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions code-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-tools</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.forge.roaster</groupId>
<artifactId>roaster-api</artifactId>
Expand All @@ -60,6 +55,12 @@
<artifactId>roaster-jdt</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import java.io.PrintWriter;

import org.jibx.schema.codegen.extend.DefaultNameConverter;
import org.jibx.schema.codegen.extend.NameConverter;

import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.LOWER_UNDERSCORE;

Expand Down Expand Up @@ -66,14 +63,37 @@ public static String upperCase(String... parts) {
return sb.toString().toUpperCase();
}

private static final NameConverter nameTools = new DefaultNameConverter();

public static String plural(String s) {
return nameTools.pluralize(s);
// pluralize/singular rules vendored from JiBX NameUtilities
// (Copyright (c) 2008-2010, Dennis M. Sosnoski, BSD 3-clause license).
public static String plural(String name) {
if (name.endsWith("List") || (name.endsWith("s") && !name.endsWith("ss"))) {
return name;
}
if (name.endsWith("y") && !name.endsWith("ay") && !name.endsWith("ey") && !name.endsWith("iy")
&& !name.endsWith("oy") && !name.endsWith("uy")) {
if (name.equalsIgnoreCase("any")) {
return name;
}
return name.substring(0, name.length() - 1) + "ies";
} else if (name.endsWith("ss")) {
return name + "es";
} else {
return name + 's';
}
}

public static String singular(String s) {
return nameTools.depluralize(s);
public static String singular(String name) {
if (name.endsWith("ies")) {
return name.substring(0, name.length() - 3) + 'y';
} else if (name.endsWith("sses")) {
return name.substring(0, name.length() - 2);
} else if (name.endsWith("s") && !name.endsWith("ss")) {
return name.substring(0, name.length() - 1);
} else if (name.endsWith("List")) {
return name.substring(0, name.length() - 4);
} else {
return name;
}
}

public static void writeJavadoc(PrintWriter w, String doc, String indent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright 2026 StreamNative
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.streamnative.lightproto.generator;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

/**
* Locks the pluralize/singular behavior inherited from JiBX NameUtilities.
* These functions feed into generated public API names (e.g. {@code addItem},
* {@code getItemsCount}), so changing their output is an ABI break.
*/
class UtilTest {

@ParameterizedTest
@CsvSource({
// default case: append 's'
"item, items",
"book, books",
"Message, Messages",
// ends with 'ss': append 'es'
"address, addresses",
"class, classes",
// ends with consonant+'y': replace with 'ies'
"city, cities",
"category, categories",
"company, companies",
// ends with vowel+'y': default rule, append 's'
"day, days",
"key, keys",
"boy, boys",
"guy, guys",
"way, ways",
// 'any' is a hardcoded exception (case-insensitive match), but
// only reached when endsWith("y") matches, which is case-sensitive.
// So "ANY" slips through to the default rule.
"any, any",
"Any, Any",
"ANY, ANYs",
// already plural ('s' but not 'ss'): unchanged
"items, items",
"books, books",
// ends with 'List': treated as already plural
"itemList, itemList",
"userList, userList",
})
void pluralizes(String input, String expected) {
assertEquals(expected, Util.plural(input));
}

@ParameterizedTest
@CsvSource({
// ends with 'ies': replace with 'y'
"cities, city",
"categories, category",
"companies, company",
// ends with 'sses': strip 'es'
"addresses, address",
"classes, class",
// ends with 's' (not 'ss'): strip 's'
"items, item",
"books, book",
"days, day",
// ends with 'List': strip suffix
"itemList, item",
"userList, user",
// ends with 'ss': unchanged (not a plural)
"address, address",
"class, class",
// no recognized plural marker: unchanged
"item, item",
"any, any",
})
void singularizes(String input, String expected) {
assertEquals(expected, Util.singular(input));
}
}
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
<junit.version>5.7.0</junit.version>
<guava.version>32.0.0-jre</guava.version>
<netty.version>4.1.131.Final</netty.version>
<jibx.version>1.3.3</jibx.version>
<roaster.version>2.22.2.Final</roaster.version>
<grpc.version>1.68.0</grpc.version>

Expand Down Expand Up @@ -177,12 +176,6 @@
<version>${protobuf.version}</version>
</dependency>

<dependency>
<groupId>org.jibx</groupId>
<artifactId>jibx-tools</artifactId>
<version>${jibx.version}</version>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand Down
Loading