MCPcopy Create free account
hub / github.com/defold/defold / gen_enum

Function gen_enum

engine/jni/scripts/gen_java.py:426–463  ·  view source on GitHub ↗
(decl, prefix)

Source from the content-addressed store, hash-verified

424 l(f" public static final {field_type} {item_name} = {decl['value']}{suffix};")
425
426def gen_enum(decl, prefix):
427 enum_name = check_override(decl['name'])
428
429 has_values = any(['value' in item for item in decl['items']])
430
431 l(f' public enum {enum_name} {{')
432
433 last_value = -1
434 count = len(decl['items'])
435 for i, item in enumerate(decl['items']):
436 lend = ','
437 if i == (count-1):
438 lend = ';'
439 item_name = check_override(item['name'])
440 if item_name != "FORCE_U32":
441 if 'value' in item:
442 l(f" {item_name}({item['value']})" + lend)
443 last_value = int(item['value'])
444 else:
445 l(f" {item_name}({last_value+1})" + lend)
446 last_value += 1
447 l(f' private final int value;')
448 l(f' private {enum_name}(int value) {{')
449 l(f' this.value = value;')
450 l(f' }}')
451 l(f' public int getValue() {{')
452 l(f' return this.value;')
453 l(f' }}')
454 l(f' static public {enum_name} fromValue(int value) throws IllegalArgumentException {{')
455 l(f' for ({enum_name} e : {enum_name}.values()) {{')
456 l(f' if (e.value == value)')
457 l(f' return e;')
458 l(f' }}')
459 l(f' throw new IllegalArgumentException(String.format("Invalid value to {enum_name}: %d", value) );')
460 l(f' }}')
461
462 l(" };")
463 l("")
464
465def pre_parse(inp):
466 global struct_types

Callers 1

gen_namespaceFunction · 0.85

Calls 3

check_overrideFunction · 0.85
anyFunction · 0.85
lFunction · 0.70

Tested by

no test coverage detected