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