@@ -51,31 +51,20 @@ def java_constant_name(c):
5151 'Date'
5252 ])
5353
54- # the scalar types in the range of javaTypeMap must be in java_scala_types
55- java_scalar_types = set ([
54+ # the scalar types in the range of javaTypeMap must be in javaScalarTypes
55+ javaScalarTypes = set ([
5656 'int' ,
5757 'long' ,
5858 'boolean'
5959 ])
60- javaScalarDefaultMap = {
61- 'int' : '0' ,
62- 'long' : '0L' ,
63- 'boolean' : 'false'
64- }
65- def java_scalar_default (jtype ):
66- if jtype in java_scalar_types :
67- return javaScalarDefaultMap [jtype ]
68- else :
69- return 'null'
70-
71- # the java_scalar_types must be in the domain of javaBoxedTypeMap
60+ # the javaScalarTypes must be in the domain of javaBoxedTypeMap
7261javaBoxedTypeMap = {
7362 'int' : 'Integer' ,
7463 'long' : 'Long' ,
7564 'boolean' : 'Boolean'
7665 }
7766def java_boxed_type (jtype ):
78- if jtype in java_scalar_types :
67+ if jtype in javaScalarTypes :
7968 return javaBoxedTypeMap [jtype ]
8069 else :
8170 return jtype
@@ -248,56 +237,37 @@ def printClassInterfaces():
248237 def printReadProperties (c ):
249238 if c .fields :
250239 for f in c .fields :
251- (jfName , jfType ) = (java_field_name (f .name ), java_field_type (spec , f .domain ))
252- if jfType in java_scalar_types :
253- print " this.%sIsSet = reader.readPresence();" % (jfName )
254- else :
255- print " boolean %s_present = reader.readPresence();" % (jfName )
240+ print " boolean %s_present = reader.readPresence();" % (java_field_name (f .name ))
256241 print
257242
258243 print " reader.finishPresence();"
259244
260245 if c .fields :
261246 print
262247 for f in c .fields :
263- (jfName , jfType , jfClass ) = (java_field_name (f .name ), java_field_type (spec , f .domain ), java_class_name (f .domain ))
264- if jfType in java_scalar_types :
265- print " if (this.%sIsSet) { this.%s = reader.read%s(); }" % (jfName , jfName , jfClass )
266- print " else { this.%s = %s; }" % (jfName , java_scalar_default (jfType ))
267- else :
268- print " this.%s = %s_present ? reader.read%s() : null;" % (jfName , jfName , jfClass )
248+ (jfName , jfClass ) = (java_field_name (f .name ), java_class_name (f .domain ))
249+ print " this.%s = %s_present ? reader.read%s() : null;" % (jfName , jfName , jfClass )
269250
270251 def printWritePropertiesTo (c ):
271252 print
272253 print " public void writePropertiesTo(ContentHeaderPropertyWriter writer)"
273254 print " throws IOException"
274255 print " {"
275- for f in c .fields :
276- (jfName , jfType ) = (java_field_name (f .name ), java_field_type (spec , f .domain ))
277- if jfType in java_scalar_types :
278- print " writer.writePresence(this.%sIsSet);" % (jfName )
279- else :
280- print " writer.writePresence(this.%s != null);" % (jfName )
281-
256+ if c .fields :
257+ for f in c .fields :
258+ print " writer.writePresence(this.%s != null);" % (java_field_name (f .name ))
259+ print
282260 print " writer.finishPresence();"
283-
284- for f in c .fields :
285- (jfName , jfType , jfClass ) = (java_field_name (f .name ), java_field_type (spec , f .domain ), java_class_name (f .domain ))
286- if jfType in java_scalar_types :
287- print " if (this.%sIsSet) writer.write%s(this.%s);" % (jfName , jfClass , jfName )
288- else :
261+ if c .fields :
262+ print
263+ for f in c .fields :
264+ (jfName , jfClass ) = (java_field_name (f .name ), java_class_name (f .domain ))
289265 print " if (this.%s != null) writer.write%s(this.%s);" % (jfName , jfClass , jfName )
290266 print " }"
291267
292268 def printAppendArgumentDebugStringTo (c ):
293- def optionalValueClause (jField , jType ):
294- if jType in java_scalar_types :
295- return "this.%sIsSet ? String.valueOf(this.%s) : \" unset\" " % (jField , jField )
296- else :
297- return "this.%s" % (jField )
298-
299- appendList = [ "%s=\" )\n .append(%s)\n .append(\" "
300- % (f .name , optionalValueClause (java_field_name (f .name ), java_field_type (spec , f .domain )))
269+ appendList = [ "%s=\" )\n .append(this.%s)\n .append(\" "
270+ % (f .name , java_field_name (f .name ))
301271 for f in c .fields ]
302272 print
303273 print " public void appendArgumentDebugStringTo(StringBuffer acc) {"
@@ -306,35 +276,21 @@ def optionalValueClause(jField, jType):
306276
307277 def printPropertiesBuilderClass (c ):
308278 def printBuilderSetter (fieldType , fieldName ):
309- if fieldType in java_scalar_types :
310- print " public Builder %s(%s %s)" % (fieldName , fieldType , fieldName )
311- print " { this.%s = %s; this.%sIsSet = true; return this; }" % (fieldName , fieldName , fieldName )
312- print " public Builder %sUnSet() { this.%sIsSet = false; return this; }" % (fieldName , fieldName )
313- if fieldType == "boolean" :
314- print " public Builder %s()" % (fieldName )
315- print " { return this.%s(true); }" % (fieldName )
316- else :
317- print " public Builder %s(%s %s)" % (fieldName , fieldType , fieldName )
318- print " { this.%s = %s; return this; }" % (fieldName , fieldName )
319- if fieldType == "LongString" :
320- print " public Builder %s(String %s)" % (fieldName , fieldName )
321- print " { return this.%s(LongStringHelper.asLongString(%s)); }" % (fieldName , fieldName )
322-
323- def ctorParm (field ):
324- (fType , fName ) = (java_field_type (spec , field .domain ), java_field_name (field .name ))
325- if fType in java_scalar_types :
326- return "%sIsSet ? %s : null" % (fName , fName )
327- else :
328- return fName
279+ print " public Builder %s(%s %s)" % (fieldName , java_boxed_type (fieldType ), fieldName )
280+ print " { this.%s = %s; return this; }" % (fieldName , fieldName )
281+ if fieldType == "boolean" :
282+ print " public Builder %s()" % (fieldName )
283+ print " { return this.%s(true); }" % (fieldName )
284+ elif fieldType == "LongString" :
285+ print " public Builder %s(String %s)" % (fieldName , fieldName )
286+ print " { return this.%s(LongStringHelper.asLongString(%s)); }" % (fieldName , fieldName )
329287
330288 print
331289 print " public static final class Builder {"
332290 # fields
333291 for f in c .fields :
334292 (fType , fName ) = (java_field_type (spec , f .domain ), java_field_name (f .name ))
335- if fType in java_scalar_types :
336- print " private boolean %sIsSet = false;" % (fName )
337- print " private %s %s;" % (fType , fName )
293+ print " private %s %s;" % (java_boxed_type (fType ), fName )
338294 # ctor
339295 print
340296 print " public Builder() {};"
@@ -346,7 +302,7 @@ def ctorParm(field):
346302 jClassName = java_class_name (c .name )
347303 # build()
348304 objName = "%sProperties" % (jClassName )
349- ctor_parm_list = [ ctorParm ( f ) for f in c .fields ]
305+ ctor_parm_list = [ java_field_name ( f . name ) for f in c .fields ]
350306 print " public %s build() {" % (objName )
351307 print " return new %s" % (objName )
352308 print " ( %s" % ("\n , " .join (ctor_parm_list ))
@@ -360,31 +316,33 @@ def printPropertiesBuilder(c):
360316 print " public Builder builder() {"
361317 print " Builder builder = new Builder();"
362318 setFieldList = [ "%s(%s)" % (fn , fn )
363- for fn in [ java_field_name (f .name )
364- for f in c . fields if java_field_type ( spec , f . domain ) not in java_scalar_types ] ]
319+ for fn in [ java_field_name (f .name ) for f in c . fields ]
320+ ]
365321 print " builder.%s;" % ("\n ." .join (setFieldList ))
366- for f in c .fields :
367- if java_field_type (spec , f .domain ) in java_scalar_types :
368- fn = java_field_name (f .name )
369- print " if (%sIsSet) { builder.%s(%s); }" % (fn , fn , fn )
370322 print " return builder;"
371323 print " }"
372324
373325 def printPropertiesClass (c ):
374326 def printGetter (fieldType , fieldName ):
375327 capFieldName = fieldName [0 ].upper () + fieldName [1 :]
376- print " public %s get%s() { return this.%s; }" % (fieldType , capFieldName , fieldName )
328+ print " public %s get%s() { return this.%s; }" % (java_boxed_type (fieldType ), capFieldName , fieldName )
329+ def printSetter (fieldType , fieldName ):
330+ capFieldName = fieldName [0 ].upper () + fieldName [1 :]
331+ print " @Deprecated"
332+ if fieldType == "Map<String,Object>" :
333+ print " public void set%s(%s %s)" % (capFieldName , fieldType , fieldName )
334+ print " { this.%s = %s==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(%s)); }" % (fieldName , fieldName , fieldName )
335+ else :
336+ print " public void set%s(%s %s) { this.%s = %s; }" % (capFieldName , java_boxed_type (fieldType ), fieldName , fieldName , fieldName )
377337
378338 jClassName = java_class_name (c .name )
379339
380340 print
381341 print " public static class %sProperties extends com.rabbitmq.client.impl.AMQ%sProperties {" % (jClassName , jClassName )
382342 #property fields
383343 for f in c .fields :
384- (fType , fName ) = (java_field_type (spec , f .domain ), java_field_name (f .name ))
385- if fType in java_scalar_types :
386- print " private final boolean %sIsSet;" % (fName )
387- print " private final %s %s;" % (fType , fName )
344+ (fType , fName ) = (java_boxed_type (java_field_type (spec , f .domain )), java_field_name (f .name ))
345+ print " private %s %s;" % (fType , fName )
388346
389347 #explicit constructor
390348 if c .fields :
@@ -396,14 +354,10 @@ def printGetter(fieldType, fieldName):
396354 print " {"
397355 for f in c .fields :
398356 (fType , fName ) = (java_field_type (spec , f .domain ), java_field_name (f .name ))
399- if fType in java_scalar_types :
400- print " if (%s == null) { this.%sIsSet = false; this.%s = %s; }" % (fName , fName , fName , java_scalar_default (fType ))
401- print " else { this.%sIsSet = true; this.%s = %s; }" % (fName , fName , fName )
357+ if fType == "Map<String,Object>" :
358+ print " this.%s = %s==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(%s));" % (fName , fName , fName )
402359 else :
403- if fType == "Map<String,Object>" :
404- print " this.%s = %s==null ? null : Collections.unmodifiableMap(new HashMap<String,Object>(%s));" % (fName , fName , fName )
405- else :
406- print " this.%s = %s;" % (fName , fName )
360+ print " this.%s = %s;" % (fName , fName )
407361 print " }"
408362
409363 #datainputstream constructor
@@ -425,7 +379,9 @@ def printGetter(fieldType, fieldName):
425379 #accessor methods
426380 print
427381 for f in c .fields :
428- printGetter (java_field_type (spec , f .domain ), java_field_name (f .name ))
382+ (jType , jName ) = (java_field_type (spec , f .domain ), java_field_name (f .name ))
383+ printGetter (jType , jName )
384+ printSetter (jType , jName )
429385
430386 printWritePropertiesTo (c )
431387 printAppendArgumentDebugStringTo (c )
0 commit comments