README.md 1.0 KB
Newer Older
梦境迷离's avatar
梦境迷离 已提交
1 2 3 4 5 6
# scala-macro-tools

scala macro and abstract syntax tree learning code.

# @toString

梦境迷离's avatar
梦境迷离 已提交
7 8 9 10
- Argument
    - `verbose` Whether to enable detailed log.
    - `withFieldName` Whether to include the name of the field in the toString.
    - `containsCtorParams` Whether to include the fields of the primary constructor.
梦境迷离's avatar
梦境迷离 已提交
11

梦境迷离's avatar
梦境迷离 已提交
12
- source code1
梦境迷离's avatar
梦境迷离 已提交
13

梦境迷离's avatar
梦境迷离 已提交
14
```scala
梦境迷离's avatar
梦境迷离 已提交
15 16 17 18 19
class TestClass(val i: Int = 0, var j: Int) {
  val y: Int = 0
  var z: String = "hello"
  var x: String = "world"
}
梦境迷离's avatar
梦境迷离 已提交
20

梦境迷离's avatar
梦境迷离 已提交
21
case class TestClass2(i: Int = 0, var j: Int) // No method body, only have primary constructor.
梦境迷离's avatar
梦境迷离 已提交
22
```
梦境迷离's avatar
梦境迷离 已提交
23

梦境迷离's avatar
梦境迷离 已提交
24 25 26 27 28
- when withFieldName=false containsCtorParams=false

```
println(new TestClass(1, 2))
TestClass(0, hello, world)
梦境迷离's avatar
梦境迷离 已提交
29 30
```

梦境迷离's avatar
梦境迷离 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
- when withFieldName=false containsCtorParams=true

```
println(new TestClass(1, 2))
TestClass(1, 2, 0, hello, world)
```

- when withFieldName=true containsCtorParams=false

```
println(new TestClass(1, 2))
TestClass(y=0, z=hello, x=world)
```

- when withFieldName=true containsCtorParams=true

```
println(new TestClass(1, 2))
TestClass(i=1, j=2, y=0, z=hello, x=world)
```