25
25
import java .util .OptionalInt ;
26
26
import java .util .OptionalLong ;
27
27
import java .util .function .Function ;
28
+ import java .util .regex .Pattern ;
28
29
import java .util .stream .Collectors ;
29
30
import java .util .stream .Stream ;
30
31
@@ -43,6 +44,7 @@ public class OptionalGenerator extends Generator {
43
44
private static final String CLASS_SCOPE = "class_scope:" ;
44
45
private static final String DEFAULT_OPTIONAL_CLASS = Optional .class .getName ();
45
46
private static final String DEFAULT_OPTIONAL_GETTER_METHOD = "get" ;
47
+ private static final Pattern METHOD_NAME_SPLIT_PATTERN = Pattern .compile ("(?<=\\ d)(?=[a-z])" );
46
48
private static final Map <JavaType , String > PRIMITIVE_CLASSES = ImmutableMap .<JavaType , String >builder ()
47
49
.put (JavaType .INT , Integer .class .getSimpleName ())
48
50
.put (JavaType .LONG , Long .class .getSimpleName ())
@@ -218,7 +220,9 @@ private String getFileName(FileDescriptorProto fileDescriptor, DescriptorProto m
218
220
}
219
221
220
222
private String getJavaMethodName (FieldDescriptorProto fieldDescriptor ) {
221
- return fieldDescriptor .getJsonName ().substring (0 , 1 ).toUpperCase (Locale .ROOT ) + fieldDescriptor .getJsonName ().substring (1 );
223
+ return Stream .of (METHOD_NAME_SPLIT_PATTERN .split (fieldDescriptor .getJsonName ()))
224
+ .map (OptionalGenerator ::capitalize )
225
+ .collect (Collectors .joining ());
222
226
}
223
227
224
228
private String getJavaTypeName (FieldDescriptorProto fieldDescriptor ) {
@@ -260,4 +264,8 @@ private static boolean hasFieldPresence(FieldDescriptorProto fieldDescriptor) {
260
264
private static String templatePath (String path ) {
261
265
return TEMPLATES_DIRECTORY + path ;
262
266
}
267
+
268
+ private static String capitalize (String value ) {
269
+ return value .substring (0 , 1 ).toUpperCase (Locale .ROOT ) + value .substring (1 );
270
+ }
263
271
}
0 commit comments