Skip to content

Commit

Permalink
add all property / vars in the rtti for type auto type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Jul 28, 2024
1 parent 3dee235 commit 1b1188e
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions haxe/ui/macros/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Macros {

buildEvents(builder);
applyProperties(builder);
addPropertiesToRTTI(builder);

#if haxeui_macro_times
stopTimer();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1b1188e

Please sign in to comment.