Macro.hx 674 B

12345678910111213141516171819202122232425262728
  1. import haxe.macro.Context;
  2. import haxe.macro.Expr;
  3. using haxe.macro.Tools;
  4. class Macro {
  5. static var counter = 0;
  6. static public function apply() {
  7. var local = Context.getLocalType();
  8. var expected = Context.getExpectedType();
  9. var superClass = switch (expected) {
  10. case TInst(c, [t]):
  11. var c = c.get();
  12. { pack: c.pack, name: c.name, params: [TPType(t.toComplexType())] };
  13. case _:
  14. throw false;
  15. }
  16. var name = 'Test${counter++}';
  17. var cls = macro class $name extends $superClass {
  18. public function new() {
  19. super($v{name} + " extends " + $v{expected.toString()});
  20. }
  21. }
  22. Context.defineType(cls);
  23. return TPath({pack: [], name: name});
  24. }
  25. }