際際滷

際際滷Share a Scribd company logo
Vampire Methods
ScalaSyd
Can you do this?
@xeno_by jumps in
Kittens!
Kittens!
Generate a local class!
Local CatMatcher
Paradise plugin
Just for quasi-quotes
Local CatMatcher
Batman
Local CatMatcher
http://stackoverflow.com/questions/18480707/method-cannot-
be-accessed-in-macro-generated-class
Dont forget the {}!
Real incremental recompilation
Lets dive
Grab the Cat
TypeTag not accessible in a macro!
Wash the Cat
Inception matcher
Builder pattern
Matcher methods
// CatMatcher
Inception matcher
Cat matcher
Internal state
Inception matcher
new constraint =>
new matcher function
name/age/kitten methods
list of c.Expr[_]
Mirror, mirror
structural type =>
reflection :-(
// age
// matchA[Cat].age(6)
// Int
Yo, I heard you like macros
No structural type!
Yo, I heard you like macros
Annotation code
// @fieldMatcherBody(expected => cat.age must_== expected)
// val expected = 6
// cat.age must_== expected
Yo, I heard you like macros
extract parameter/body
Transformers
// 6
// `prefix` represents an equivalent of
// `this` for normal instance methods
// body:
// CatMatcher.this.addMatcher((_:Cat).age must_== arg)
Transformers
http://stackoverflow.com/questions/18523871/use-this-in-a-
generated-macro-method
Transformers -Yrangepos
Can you do this?
YES !!!
Thank you!
If you followed that far

More Related Content

Vampire methods