26
Vampire Methods ScalaSyd

Vampire methods

Embed Size (px)

DESCRIPTION

Presentated at ScalaSyd on Wednesday, October 9th

Citation preview

Page 1: Vampire methods

Vampire Methods

ScalaSyd

Page 2: Vampire methods

Can you do this?

Page 3: Vampire methods

@xeno_by jumps in

Page 4: Vampire methods

Kittens!

Page 5: Vampire methods

Kittens!

Generate a loca

l class!

Page 6: Vampire methods

Local CatMatcher

Page 7: Vampire methods

Paradise plugin

Just for q

uasi-quotes

Page 8: Vampire methods

Local CatMatcher

Page 9: Vampire methods

Batman

Page 10: Vampire methods

Local CatMatcher

http://stackoverflow.com/questions/18480707/method-cannot-be-accessed-in-macro-generated-class

Don’t forg

et the {}!

Page 11: Vampire methods

Real incremental recompilation

Page 12: Vampire methods

Let’s dive

Page 13: Vampire methods

Grab the Cat

TypeTag not acc

essible in

a macro

!

Page 14: Vampire methods

Wash the Cat

Page 15: Vampire methods

Inception matcher

Builder pattern

Matcher methods

// CatMatcher

Page 16: Vampire methods

Inception matcher

Cat matcher

Internal state

Page 17: Vampire methods

Inception matcher

new constraint =>new matcher function

name/age/kitten methods

list of c.Expr[_]

Page 18: Vampire methods

Mirror, mirror

structu

ral type =

>

reflection :-(

// age

// matchA[Cat].age(6)

// Int

Page 19: Vampire methods

Yo, I heard you like macros

No stru

ctural ty

pe!

Page 20: Vampire methods

Yo, I heard you like macros

Annotation code

// @fieldMatcherBody(expected => cat.age must_== expected)

// val expected = 6

// cat.age must_== expected

Page 21: Vampire methods

Yo, I heard you like macros

extract parameter/body

Page 22: Vampire methods

Transformers

// 6

// `prefix` represents an equivalent of // `this` for normal instance methods

// body:// CatMatcher.this.addMatcher((_:Cat).age must_== arg)

Page 23: Vampire methods

Transformers

http://stackoverflow.com/questions/18523871/use-this-in-a-generated-macro-method

Page 24: Vampire methods

Transformers -Yrangepos

Page 25: Vampire methods

Can you do this?

YES !!!

Page 26: Vampire methods

Thank you!

If you followed that far…