Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 1 | //:: import os |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 2 | //:: for prop in msg.interface.members: |
Andreas Wundsam | 4b8661f | 2013-11-05 17:17:28 -0800 | [diff] [blame] | 3 | //:: if hasattr(prop, "custom_template") and prop.custom_template != None: |
| 4 | //:: getter_template_file_name = "%s/custom/%s" % (template_dir, prop.custom_template(builder=builder)) |
| 5 | //:: else: |
| 6 | //:: getter_template_file_name = "%s/custom/%s_%s.java" % (template_dir, msg.name if not builder else msg.name + '.Builder', prop.getter_name) |
| 7 | //:: #endif |
| 8 | //:: if os.path.exists(getter_template_file_name): |
| 9 | //:: include(getter_template_file_name, msg=msg, builder=builder, has_parent=has_parent, prop=prop) |
| 10 | //:: else: |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 11 | @Override |
Andreas Wundsam | 99e931d | 2013-08-22 07:53:53 -0700 | [diff] [blame] | 12 | public ${prop.java_type.public_type} ${prop.getter_name}()${ "" if prop in msg.members else "throws UnsupportedOperationException"} { |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 13 | //:: if prop in msg.members: |
Andreas Wundsam | c8912c1 | 2013-11-15 13:44:48 -0800 | [diff] [blame] | 14 | //:: version_prop = msg.member_by_name(prop.name) |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 15 | //:: if version_prop.is_fixed_value: |
| 16 | return ${version_prop.enum_value}; |
| 17 | //:: elif version_prop.is_length_value: |
| 18 | // FIXME: Hacky and inperformant way to determine a message length. Should be replaced with something better |
| 19 | ChannelBuffer c = new LengthCountingPseudoChannelBuffer(); |
| 20 | WRITER.write(c, ${ "this" if not builder else "({0}) this.getMessage()".format(msg.name) }); |
| 21 | return c.writerIndex(); |
| 22 | //:: else: |
| 23 | return ${version_prop.name}; |
| 24 | //:: #endif |
| 25 | //:: else: |
| 26 | throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}"); |
| 27 | //:: #endif |
| 28 | } |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 29 | //:: #endif |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 30 | |
| 31 | //:: if generate_setters and prop.is_writeable: |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 32 | //:: setter_template_file_name = "%s/custom/%s_%s.java" % (template_dir, msg.name if not builder else msg.name + '.Builder', prop.setter_name) |
| 33 | //:: if os.path.exists(setter_template_file_name): |
| 34 | //:: include(setter_template_file_name, msg=msg, builder=builder, has_parent=has_parent) |
Yotam Harchol | 0936bfb | 2013-09-10 16:34:20 -0700 | [diff] [blame] | 35 | |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 36 | //:: else: |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 37 | @Override |
Andreas Wundsam | 99e931d | 2013-08-22 07:53:53 -0700 | [diff] [blame] | 38 | public ${msg.interface.name}.Builder ${prop.setter_name}(${prop.java_type.public_type} ${prop.name})${ "" if prop in msg.members else " throws UnsupportedOperationException"} { |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 39 | //:: if prop in msg.members: |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 40 | this.${prop.name} = ${prop.name}; |
| 41 | this.${prop.name}Set = true; |
| 42 | return this; |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 43 | //:: else: |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 44 | throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}"); |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 45 | //:: #endif |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 46 | } |
Yotam Harchol | f25e814 | 2013-09-09 14:30:13 -0700 | [diff] [blame] | 47 | //:: #endif |
| 48 | //:: #endif |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 49 | //:: #endfor |