import haxe.macro.Context; import haxe.macro.Expr; class FunctionArgMacro { macro static function build():Array { var fields = Context.getBuildFields(); for (field in fields) { switch (field.kind) { case FFun(fun): var checks = []; for (arg in fun.args) { switch (arg.type) { case macro : String: for (m in arg.meta) { switch (m.name) { case "notNullOrEmpty": checks.push(macro if ($i{arg.name} == null) throw $v{arg.name + " is null"}); checks.push(macro if ($i{arg.name}.length == 0) throw $v{arg.name + " is empty"}); } } default: } } fun.expr = macro { $b{checks}; ${fun.expr}; } default: } } return fields; } }