blob: 8e5b0e9d2b68a6b2eb1af41158e118d9b8c78efd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
object test {
class Tree
class Apply(val fun: Tree, val args: List[Tree]) extends Tree
trait DeconstructorCommon[T >: Null <: AnyRef] {
var field: T = null
def get: this.type = this
def isEmpty: Boolean = field eq null
def isDefined = !isEmpty
def unapply(s: T): this.type ={
field = s
this
}
}
trait ApplyDeconstructor extends DeconstructorCommon[Apply] {
def _1: Tree
def _2: List[Tree]
}
object Apply extends ApplyDeconstructor {
def _1: Tree = field.fun
def _2: List[Tree] = field.args
}
def assocsFromApply(tree: Tree) = {
tree match {
case Apply(fun, args) => ???
}
}
}
|