diff --git a/extraParams.hxml b/extraParams.hxml new file mode 100644 index 0000000..6c9604f --- /dev/null +++ b/extraParams.hxml @@ -0,0 +1 @@ +--macro haxework.parser.Parser.auto() \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index 27ce23f..2d955ee 100755 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "BSD", "tags": ["flash", "openfl"], "description": "Framework.", - "version": "0.7.1", + "version": "0.7.2", "releasenote": "Update.", "contributors": ["shmyga"], "classPath": "src/main", diff --git a/src/main/haxework/gui/ViewBuilder.hx b/src/main/haxework/gui/ViewBuilder.hx index 75d5733..5750193 100755 --- a/src/main/haxework/gui/ViewBuilder.hx +++ b/src/main/haxework/gui/ViewBuilder.hx @@ -1,14 +1,16 @@ package haxework.gui; +#if macro import haxework.gui.build.Builder; +#end @:remove @:autoBuild(haxework.gui.ViewBuilderImpl.build()) extern interface ViewBuilder {} class ViewBuilderImpl { #if macro - public static function build() { - return new Builder().build(); - } + public static function build() { + return new Builder().build(); + } #end } \ No newline at end of file diff --git a/src/main/haxework/parser/Parser.hx b/src/main/haxework/parser/Parser.hx new file mode 100644 index 0000000..e8958c4 --- /dev/null +++ b/src/main/haxework/parser/Parser.hx @@ -0,0 +1,75 @@ +package haxework.parser; + +import haxe.macro.Expr; +#if macro +import haxe.macro.Context; +#end +import haxe.macro.Type; +import haxe.macro.Type.ClassType; +import haxe.macro.Type.Ref; + + +class Parser { + + #if macro + private static function auto():Void { + haxe.macro.Compiler.addGlobalMetadata("", "@:build(haxework.parser.Parser.autoRun())", true, true, false); + } + + private static macro function autoRun():Array { + var t:Type = Context.getLocalType(); + switch (t) { + case null: return null; + case Type.TInst(_.get() => ct, _): + var hasMeta:Bool = false; + var hasAutoBuild:Bool = false; + for (md in ct.meta.get()) + if (md.name == ":haxework") { + hasMeta = true; + } + if (hasMeta) { + var result:Array = []; + var fields:Array = Context.getBuildFields(); + for (field in fields) { + var remove:Bool = false; + for (md in field.meta) + if (md.name == ":provide") { + var type:ComplexType = switch field.kind { + case FieldType.FVar(t): t; + default: null; + } + var name:String = switch type { + case ComplexType.TPath(p): p.name; + default: null; + } + remove = true; + result.push({ + name: field.name, + access: [Access.APublic], + pos: field.pos, + kind: FieldType.FProp('get', 'never', type) + }); + result.push({ + name: 'get_${field.name}', + access: field.access, + pos: field.pos, + kind: FieldType.FFun({ + args: [], + expr: Context.parse('return haxework.provider.Provider.get(${name})', field.pos), + params: [], + ret: type + }) + }); + } + if (!remove) { + result.push(field); + } + } + return result; + } + return null; + default: return null; + } + } + #end +}