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