README.md 749 字节
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
- Argument
    - `verbose` Whether to enable detailed log.
    - `withFieldName` Whether to include the name of the field in the toString.
梦境迷离's avatar
pre  
梦境迷离 已提交
10 11
    - `withInternalField` Whether to include the fields defined within a class.
    - Support `case class` and `class`.
梦境迷离's avatar
梦境迷离 已提交
12

梦境迷离's avatar
pre  
梦境迷离 已提交
13
- Example
梦境迷离's avatar
梦境迷离 已提交
14

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

梦境迷离's avatar
pre  
梦境迷离 已提交
22
println(new TestClass(1, 2));
梦境迷离's avatar
梦境迷离 已提交
23
```
梦境迷离's avatar
梦境迷离 已提交
24

梦境迷离's avatar
pre  
梦境迷离 已提交
25 26 27 28
|   withInternalField / withFieldName  | false  |true
|  ----  | ----  |----|
|false|```TestClass(1, 2)``` |```TestClass(i=0, j=2)```|
|true|```TestClass(1, 2, 0, hello, world)```|```TestClass(i=1, j=2, y=0, z=hello, x=world)```|