check bindable meta from interfaces

This commit is contained in:
Dima Granetchi
2014-12-31 22:08:25 +02:00
parent 94575cac7b
commit b3385d1123
2 changed files with 38 additions and 7 deletions
+32 -5
View File
@@ -37,18 +37,26 @@ class BindMacros {
var classType = type.getClass();
if (classType.isInterface) {
return null;
}
if (bindingSignalProvider == null) {
bindingSignalProvider = new bindx.BindSignal.BindSignalProvider();
}
var fields = Context.getBuildFields();
if (classType.isInterface) {
for (f in fields) {
for (m in f.meta) if (m.name == MetaUtils.BINDABLE_META) {
if (m.params.length > 0)
Context.warning('Interface doesn\'t support @:bindable meta params', m.pos);
}
}
return null;
}
var meta = classType.bindableMeta();
if (meta != null) injectBindableMeta(fields, meta);
var interfaceFields = getBindableFieldsFromInterfaces(classType);
var res = [];
for (f in fields)
@@ -56,10 +64,29 @@ class BindMacros {
if (!isFieldBindable(f, fields)) Context.error('can\'t bind field \'${f.name}\'', f.pos);
bindField(f, fields, res);
} else res.push(f);
} else {
if (interfaceFields.exists(f.name))
Context.fatalError('Interface "${interfaceFields.get(f.name)}" expects @:bindable metadata', f.pos);
res.push(f);
}
return res;
}
static function getBindableFieldsFromInterfaces(classType:ClassType):Map<String, String> {
var interfaceFields = new Map();
for (i in classType.interfaces) {
var t = i.t.get();
if (@:privateAccess Bind.isBindable(t)) {
for (f in t.fields.get()) {
if (f.meta.has(MetaUtils.BINDABLE_META)) {
interfaceFields.set(f.name, t.module + (t.module.length > 0 ? "." + t.name : t.name));
}
}
}
}
return interfaceFields;
}
static function bindField(field:Field, fields:Array<Field>, res:Array<Field>):Void {
var meta = field.bindableMeta();
+6 -2
View File
@@ -12,12 +12,16 @@ import haxe.macro.Expr.Position;
}
class Warn {
static var level:WarnPriority = null;
@:isVar static var level(get, null):WarnPriority = null;
public static function w(msg:String, pos:Position, level:WarnPriority) {
static function get_level():WarnPriority {
if (Warn.level == null) {
Warn.level = Context.defined("bindx_log") ? Std.parseInt(Context.definedValue("bindx_log")) : LOW;
}
return Warn.level;
}
public static function w(msg:String, pos:Position, level:WarnPriority) {
if ((Warn.level : Int) >= (level : Int))
Context.warning(msg, pos);
}