Check.hx 704 B

123456789101112131415161718192021222324252627
  1. import haxe.macro.Type;
  2. import haxe.macro.Context;
  3. class Check {
  4. static public function init() {
  5. Context.onGenerate(function(types:Array<Type>) {
  6. for(type in types) {
  7. switch type {
  8. case TInst(_.get() => cls, []) if(cls.name == 'Main'):
  9. for(field in cls.statics.get()) {
  10. if(field.name == 'testMeta') {
  11. var pureCount = field.meta.extract(':pure').length;
  12. if(pureCount != 1) {
  13. Context.error('Main.testMeta is expected to have exactly one @:pure meta, got $pureCount', field.pos);
  14. return;
  15. }
  16. //success
  17. return;
  18. }
  19. }
  20. case _:
  21. }
  22. }
  23. Context.error('Main.testMeta not found', (macro {}).pos);
  24. });
  25. }
  26. }