From 1b1188e2dee910eab2dac3dd1495b046a171a93d Mon Sep 17 00:00:00 2001 From: Ian Harrigan Date: Sun, 28 Jul 2024 15:24:49 +0200 Subject: [PATCH] add all property / vars in the rtti for type auto type conversion --- haxe/ui/macros/Macros.hx | 45 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/haxe/ui/macros/Macros.hx b/haxe/ui/macros/Macros.hx index 476ef51ce..9957fb7ea 100644 --- a/haxe/ui/macros/Macros.hx +++ b/haxe/ui/macros/Macros.hx @@ -95,6 +95,7 @@ class Macros { buildEvents(builder); applyProperties(builder); + addPropertiesToRTTI(builder); #if haxeui_macro_times stopTimer(); @@ -153,6 +154,42 @@ class Macros { stopTimer(); #end } + + static function addPropertiesToRTTI(builder:ClassBuilder) { + for (f in builder.fields) { + if (f.access.indexOf(APrivate) != -1 || f.access.indexOf(AStatic) != -1) { + continue; + } + if (f.name == "value") { + continue; + } + var isBehaviour = false; + for (m in f.meta) { + if (m.name == ":behaviour") { + isBehaviour = true; + break; + } + } + if (isBehaviour) { + continue; + } + var t = switch (f.kind) { + case FVar(t, _): t; + case FProp(_, _, t, _): t; + case _: null; + } + + if (t != null) { + var allowed = switch (t) { + case TFunction(args, ret): false; + case _: true; + } + if (allowed) { + RTTI.addClassProperty(builder.fullPath, f.name, ComplexTypeTools.toString(t)); + } + } + } + } static function buildFromXmlMeta(builder:ClassBuilder) { #if haxeui_macro_times @@ -581,14 +618,6 @@ class Macros { } } - // "hidden" isnt actually a behaviour (currently), however, we would like it in the RTTI so we can do - // automatic type conversions, but since its just a normal getter / setter it will never be included - // in this code, so we'll add it manually - it might make sense later to have some @:add-rtti type - // metadata, but for now, an explicit, obvious list is clearer - if (builder.fullPath == "haxe.ui.core.Component") { - RTTI.addClassProperty(builder.fullPath, "hidden", "bool"); - } - for (f in fields) { RTTI.addClassProperty(builder.fullPath, f.name, ComplexTypeTools.toString(f.type)); if (f.name == valueField) {