Created
March 19, 2020 17:11
-
-
Save fal-works/96d1bb1e024f7c58f50786b1e26e5973 to your computer and use it in GitHub Desktop.
Haxe: Build macro doesn't find namespaced metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--display Main.hx@0@position |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-main Main | |
--interp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if macro | |
import haxe.macro.Context; | |
import haxe.macro.Expr.Field; | |
using StringTools; | |
class Macro { | |
static macro function checkMeta():Null<Array<Field>> { | |
warnIfNotFound(":myMeta"); | |
return null; | |
} | |
static macro function checkNsMeta():Null<Array<Field>> { | |
warnIfNotFound(":myMeta.x"); | |
return null; | |
} | |
static function warnIfNotFound(metaName:String) { | |
final localClass = Context.getLocalClass().get(); | |
final className = localClass.name; | |
final metaExists = localClass.meta.has(metaName); | |
final mode = #if display " display " #else "!display " #end; | |
Sys.println(mode + '[$className]'.rpad(" ", 22) + '@$metaName'.rpad(" ", 11) + '=> $metaExists'); | |
if (!metaExists) { | |
Context.warning('$mode [$className] Metadata not found: @$metaName', Context.currentPos()); | |
} | |
} | |
} | |
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
static function main() {} | |
} | |
// 1. build -> meta --------------------------------------- | |
@:build(Macro.checkMeta()) // ok | |
@:myMeta | |
class _1_BuildMeta {} | |
// 2. meta -> build --------------------------------------- | |
@:myMeta | |
@:build(Macro.checkMeta()) // ok | |
class _2_MetaBuild {} | |
// 3. autoBuild -> meta ----------------------------------- | |
@:autoBuild(Macro.checkMeta()) // ok | |
interface IAutoBuildMeta {} | |
@:myMeta | |
class _3_AutoBuildMeta implements IAutoBuildMeta {} | |
// 4. build -> namespaced meta ---------------------------- | |
@:build(Macro.checkNsMeta()) // not recognized | |
@:myMeta.x | |
class _4_BuildNsMeta {} | |
// 5. namespaced meta -> build ---------------------------- | |
@:myMeta.x | |
@:build(Macro.checkNsMeta()) // cannot find metadata | |
class _5_NsMetaBuild {} | |
// 6. autoBuild -> namespaced meta ------------------------ | |
@:autoBuild(Macro.checkNsMeta()) // cannot find metadata | |
interface IAutoBuildNsMeta {} | |
@:myMeta.x | |
class _6_AutoBuildNsMeta implements IAutoBuildNsMeta {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment