diff options
author | Tibor Král <tibor.kral@pantheon.tech> | 2019-03-14 16:02:38 +0100 |
---|---|---|
committer | Michal Cmarada <mcmarada@cisco.com> | 2019-03-20 13:53:15 +0000 |
commit | cb48eef7770e0782c686337b577064905e1edb8d (patch) | |
tree | 9315c3abc4febd271b1592d1cfe7741801dc550e | |
parent | e599b1319651e2e5a4415033913d615e3617effa (diff) |
Fixes EnumSet translation
Change-Id: Ic78a2523b766456e888c3468452a4685b8798dbe
Signed-off-by: Tibor Král <tibor.kral@pantheon.tech>
-rwxr-xr-x | java/jvpp/gen/jvppgen/enumsets_gen.py | 38 | ||||
-rwxr-xr-x | java/jvpp/gen/jvppgen/jni_type_handlers_gen.py | 4 |
2 files changed, 34 insertions, 8 deletions
diff --git a/java/jvpp/gen/jvppgen/enumsets_gen.py b/java/jvpp/gen/jvppgen/enumsets_gen.py index 029c4ec..e1f5c8d 100755 --- a/java/jvpp/gen/jvppgen/enumsets_gen.py +++ b/java/jvpp/gen/jvppgen/enumsets_gen.py @@ -53,7 +53,17 @@ $json_definition */ public final class $java_name { - private final EnumSet<$java_enum_name> options = EnumSet.noneOf($java_enum_name.class); + private final EnumSet<$java_enum_name> options; + + public $java_name() { + options = EnumSet.noneOf($java_enum_name.class); + setOptionsValue(0); + } + + public $java_name($value_type value) { + options = EnumSet.noneOf($java_enum_name.class); + setOptionsValue(value); + } @Override public boolean equals(final Object obj) { @@ -92,19 +102,35 @@ public final class $java_name { } public boolean add($java_enum_name option) { + if (option.value == 0) return false; + + if (getOptionsValue() == 0) { + options.clear(); + } return options.add(option); } public boolean remove($java_enum_name option) { - return options.remove(option); + if (option.value == 0) return false; + + options.remove(option); + if (options.isEmpty()) { + clear(); + } + return true; } - public boolean removeAll(EnumSet<$java_enum_name> options) { - return options.removeAll(options); + public boolean removeAll(EnumSet<$java_enum_name> optionsToRemove) { + boolean retVal = options.removeAll(optionsToRemove); + if (options.isEmpty()) { + clear(); + retVal = true; + } + return retVal; } public void clear() { - options.clear(); + setOptionsValue(0); } public boolean contains($java_enum_name option) { @@ -135,7 +161,7 @@ $constants; return enumeration; } } - return null; + return $java_enum_name.values()[0]; } } } diff --git a/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py b/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py index 657972d..d0d123a 100755 --- a/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py +++ b/java/jvpp/gen/jvppgen/jni_type_handlers_gen.py @@ -186,9 +186,9 @@ $json_definition static inline jobject _net_to_host_${c_name}(JNIEnv * env, vl_api_${c_name}_t _net) { jclass enumClass = (*env)->FindClass(env, "${class_FQN}"); - jmethodID enumInit = (*env)->GetMethodID(env, enumClass, "setOptionsValue", "(I)V"); + jmethodID constructor = (*env)->GetMethodID(env, enumClass, "<init>", "(I)V"); ${jni_type} value = (${jni_type}) $type_swap - return (*env)->NewObject(env, enumClass, enumInit, value); + return (*env)->NewObject(env, enumClass, constructor, value); }""") |