@@ -41,15 +41,33 @@ public static String capitalize(final String name, final int index) {
4141 return Character .toUpperCase (name .charAt (index )) + name .substring (index + 1 );
4242 }
4343
44- public static @ Nullable String decapitalize (final String name , final int index ) {
45- if (!Character .isUpperCase (name .charAt (index ))) {
46- // If the char isn't uppercase, that means it isn't following the typical `lowerCamelCase`
47- // Java method naming scheme how we expect, so we can't be sure it means what we think it
48- // means in this instance
49- return null ;
50- } else {
51- return Character .toLowerCase (name .charAt (index )) + name .substring (index + 1 );
44+ public static String decapitalize (final String name ) {
45+ boolean capturingGroup = false ;
46+ final StringBuilder result = new StringBuilder ();
47+
48+ for (int i = 0 ; i < name .length (); i ++) {
49+ final char character = name .charAt (i );
50+ if (Character .isUpperCase (character )) {
51+ if (capturingGroup ) {
52+ if (i < name .length () - 1 && Character .isLowerCase (name .charAt (i + 1 ))) {
53+ // Next char is lowercase, so this is the start of a new word
54+ result .append (character );
55+ } else {
56+ // Convert the leading capital to lowercase and append to the result
57+ result .append (Character .toLowerCase (character ));
58+ }
59+ } else {
60+ // let's start a group, making sure to lowercase if it's the first char of the name
61+ capturingGroup = true ;
62+ result .append (i == 0 ? Character .toLowerCase (character ) : character );
63+ }
64+ } else {
65+ capturingGroup = false ;
66+ result .append (character );
67+ }
5268 }
69+
70+ return result .toString ();
5371 }
5472
5573 public static Predicate <String > equalsAny (final String ... strings ) {
@@ -108,4 +126,31 @@ public static boolean isStringAllUppercase(final String input) {
108126 public static boolean hasPrefix (final String text , final String prefix ) {
109127 return text .length () > prefix .length () && text .startsWith (prefix );
110128 }
129+
130+ public static String parseSimpleTypeName (final String simpleName ) {
131+ // Parse all capitalized types into lowercase
132+ // UUID -> uuid
133+ // AABB -> aabb
134+ if (LvtUtil .isStringAllUppercase (simpleName )) {
135+ return simpleName .toLowerCase ();
136+ }
137+
138+ // Decapitalize
139+ // HelloWorld -> helloWorld
140+ // abstractUUIDFix -> abstractUuidFix
141+ // myCoolAABBClass -> myCoolAabbClass
142+ return LvtUtil .decapitalize (simpleName );
143+ }
144+
145+ @ Nullable
146+ public static String parseSimpleTypeNameFromMethod (final String methodName , int prefix ) {
147+ if (!Character .isUpperCase (methodName .charAt (prefix ))) {
148+ // If the char isn't uppercase, that means it isn't following the typical `lowerCamelCase`
149+ // Java method naming scheme how we expect, so we can't be sure it means what we think it
150+ // means in this instance
151+ return null ;
152+ } else {
153+ return LvtUtil .parseSimpleTypeName (methodName .substring (prefix ));
154+ }
155+ }
111156}
0 commit comments