@@ -308,7 +308,7 @@ def get_underlying_type(data_type, allow_lists=True):
308
308
return data_type
309
309
310
310
311
- def union_factory_create_method_name (data_type , value_fields_subset ):
311
+ def union_create_with_method_name (data_type , value_fields_subset ):
312
312
if len (value_fields_subset ) > 0 :
313
313
method_suffix = 'And%s' % _capwords (value_fields_subset [0 ].name )
314
314
else :
@@ -2976,8 +2976,8 @@ def generate_data_type_union(self, data_type):
2976
2976
for field in static_fields :
2977
2977
singleton_args = ', ' .join (["Tag.%s" % j .field_tag_enum_name (field )])
2978
2978
w .javadoc (field )
2979
- method_name = union_factory_create_method_name (data_type , [])
2980
- w .out ('public static final %s %s = %s .%s(%s);' ,
2979
+ method_name = union_create_with_method_name (data_type , [])
2980
+ w .out ('public static final %s %s = new %s() .%s(%s);' ,
2981
2981
j .java_class (data_type ),
2982
2982
j .field_static_instance (field ),
2983
2983
j .java_class (data_type ),
@@ -2997,7 +2997,14 @@ def generate_data_type_union(self, data_type):
2997
2997
#
2998
2998
# Constructors
2999
2999
#
3000
- def _gen_factory_method (data_type , value_fields_subset ):
3000
+
3001
+ w .out ('' )
3002
+ w .javadoc ('Private default constructor, so that object is uninitializable publicly.' )
3003
+ with w .block ('private %s()' , j .java_class (data_type )):
3004
+ pass
3005
+ w .out ('' )
3006
+
3007
+ def _gen_create_with_method (data_type , value_fields_subset ):
3001
3008
w .out ('' )
3002
3009
w .javadoc (data_type ,
3003
3010
fields = value_fields_subset ,
@@ -3009,18 +3016,18 @@ def _gen_factory_method(data_type, value_fields_subset):
3009
3016
for f in value_fields_subset
3010
3017
],
3011
3018
))
3012
- method_name = union_factory_create_method_name (data_type , value_fields_subset )
3013
- with w .block ('private static %s %s(%s)' , j .java_class (data_type ), method_name , formatted_args ):
3014
- w .out ('final %s result = new %s();' , j .java_class (data_type ), j .java_class (data_type ))
3019
+ method_name = union_create_with_method_name (data_type , value_fields_subset )
3020
+ with w .block ('private %s %s(%s)' , j .java_class (data_type ), method_name , formatted_args ):
3021
+ w .out ('%s result = new %s();' , j .java_class (data_type ), j .java_class (data_type ))
3015
3022
w .out ('result._tag = _tag;' )
3016
3023
for field in value_fields_subset :
3017
3024
# don't perform validation in the private constructor
3018
3025
w .out ('result.%s = %s;' , j .param_name (field ), j .param_name (field ))
3019
3026
w .out ('return result;' )
3020
3027
3021
- _gen_factory_method (data_type , [])
3028
+ _gen_create_with_method (data_type , [])
3022
3029
for f in value_fields :
3023
- _gen_factory_method (data_type , [f ])
3030
+ _gen_create_with_method (data_type , [f ])
3024
3031
3025
3032
#
3026
3033
# Field getters/constructors
@@ -3120,8 +3127,8 @@ def generate_data_type_union_field_methods(self, data_type):
3120
3127
j .java_class (field ),
3121
3128
):
3122
3129
self .generate_field_validation (field , value_name = "value" , omit_arg_name = True , allow_default = False )
3123
- method_name = union_factory_create_method_name (data_type , [field ])
3124
- w .out ('return %s .%s(Tag.%s, %s);' ,
3130
+ method_name = union_create_with_method_name (data_type , [field ])
3131
+ w .out ('return new %s() .%s(Tag.%s, %s);' ,
3125
3132
j .java_class (data_type ),
3126
3133
method_name ,
3127
3134
j .field_tag_enum_name (field ),
0 commit comments