java_gen: add support for properties to specify a custom code template
This will be used for getCanonical()
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index 2b17afa..c2d43c2 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -983,9 +983,10 @@
class JavaVirtualMember(JavaMember):
""" Models a virtual property (member) of an openflow class that is not backed by a loxi ir member """
- def __init__(self, msg, name, java_type, value=None):
+ def __init__(self, msg, name, java_type, value=None, custom_template=None):
JavaMember.__init__(self, msg, name, java_type, member=None)
self._value = value
+ self.custom_template = custom_template
@property
def is_fixed_value(self):
diff --git a/java_gen/templates/_field_accessors.java b/java_gen/templates/_field_accessors.java
index c7aa3a0..030388c 100644
--- a/java_gen/templates/_field_accessors.java
+++ b/java_gen/templates/_field_accessors.java
@@ -1,10 +1,13 @@
//:: import os
//:: for prop in msg.interface.members:
-//:: getter_template_file_name = "%s/custom/%s_%s.java" % (template_dir, msg.name if not builder else msg.name + '.Builder', prop.getter_name)
-//:: if os.path.exists(getter_template_file_name):
-//:: include(getter_template_file_name, msg=msg, builder=builder, has_parent=has_parent)
-
-//:: else:
+//:: if hasattr(prop, "custom_template") and prop.custom_template != None:
+//:: getter_template_file_name = "%s/custom/%s" % (template_dir, prop.custom_template(builder=builder))
+//:: else:
+//:: getter_template_file_name = "%s/custom/%s_%s.java" % (template_dir, msg.name if not builder else msg.name + '.Builder', prop.getter_name)
+//:: #endif
+//:: if os.path.exists(getter_template_file_name):
+//:: include(getter_template_file_name, msg=msg, builder=builder, has_parent=has_parent, prop=prop)
+//:: else:
@Override
public ${prop.java_type.public_type} ${prop.getter_name}()${ "" if prop in msg.members else "throws UnsupportedOperationException"} {
//:: if prop in msg.members: