Vampire methods

1,968 views
1,762 views

Published on

Presentated at ScalaSyd on Wednesday, October 9th

Published in: Technology, Lifestyle, Sports
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,968
On SlideShare
0
From Embeds
0
Number of Embeds
108
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Vampire methods

  1. 1. Vampire Methods ScalaSyd
  2. 2. Can you do this?
  3. 3. @xeno_by jumps in
  4. 4. Kittens!
  5. 5. Kittens! Generate a local class!
  6. 6. Local CatMatcher
  7. 7. Paradise plugin Just for quasi-quotes
  8. 8. Local CatMatcher
  9. 9. Batman
  10. 10. Local CatMatcher http://stackoverflow.com/questions/18480707/method-cannot- be-accessed-in-macro-generated-class Don’t forget the {}!
  11. 11. Real incremental recompilation
  12. 12. Let’s dive
  13. 13. Grab the Cat TypeTag not accessible in a macro!
  14. 14. Wash the Cat
  15. 15. Inception matcher Builder pattern Matcher methods // CatMatcher
  16. 16. Inception matcher Cat matcher Internal state
  17. 17. Inception matcher new constraint => new matcher function name/age/kitten methods list of c.Expr[_]
  18. 18. Mirror, mirror structural type => reflection :-( // age // matchA[Cat].age(6) // Int
  19. 19. Yo, I heard you like macros No structural type!
  20. 20. Yo, I heard you like macros Annotation code // @fieldMatcherBody(expected => cat.age must_== expected) // val expected = 6 // cat.age must_== expected
  21. 21. Yo, I heard you like macros extract parameter/body
  22. 22. Transformers // 6 // `prefix` represents an equivalent of // `this` for normal instance methods // body: // CatMatcher.this.addMatcher((_:Cat).age must_== arg)
  23. 23. Transformers http://stackoverflow.com/questions/18523871/use-this-in-a- generated-macro-method
  24. 24. Transformers -Yrangepos
  25. 25. Can you do this? YES !!!
  26. 26. Thank you! If you followed that far…

×