|
1 | 1 | package org.scalanative.bindgen |
2 | 2 |
|
| 3 | +import java.io.File |
| 4 | + |
3 | 5 | import scala.collection.mutable |
4 | 6 |
|
5 | | -class Builder { |
6 | | - private var library: String = _ |
7 | | - private var pathToHeader: String = _ |
8 | | - private var packageName: String = _ |
9 | | - private var excludePrefix: String = _ |
10 | | - private var extraArg: mutable.Seq[String] = mutable.Seq() |
11 | | - private var extraArgBefore: mutable.Seq[String] = mutable.Seq() |
| 7 | +sealed trait Builder { |
12 | 8 |
|
13 | 9 | /** |
14 | 10 | * Set header file for which bindings will be generated |
15 | 11 | */ |
16 | | - def header(pathToHeader: String): Unit = { |
17 | | - this.pathToHeader = pathToHeader |
18 | | - } |
| 12 | + def header(header: File): Unit |
19 | 13 |
|
20 | 14 | /** |
21 | 15 | * Library to link with, e.g. -luv for libuv |
22 | 16 | */ |
23 | | - def link(library: String): Unit = { |
24 | | - this.library = library |
25 | | - } |
| 17 | + def link(library: String): Unit |
26 | 18 |
|
27 | 19 | /** |
28 | 20 | * Package name of generated Scala file |
29 | 21 | */ |
30 | | - def packageName(packageName: String): Unit = { |
31 | | - this.packageName = packageName |
32 | | - } |
| 22 | + def packageName(packageName: String): Unit |
33 | 23 |
|
34 | 24 | /** |
35 | 25 | * Declarations will be removed if their names |
36 | 26 | * contain given prefix |
37 | 27 | */ |
38 | | - def excludePrefix(prefix: String): Unit = { |
39 | | - if (!prefix.isEmpty) { |
40 | | - excludePrefix = prefix |
41 | | - } |
42 | | - } |
| 28 | + def excludePrefix(prefix: String): Unit |
43 | 29 |
|
44 | 30 | /** |
45 | 31 | * Additional argument to append to the compiler command line |
46 | 32 | */ |
47 | | - def extraArg(arg: String): Unit = { |
48 | | - if (!arg.isEmpty) { |
49 | | - extraArg += arg |
50 | | - } |
51 | | - } |
| 33 | + def extraArg(arg: String): Unit |
52 | 34 |
|
53 | 35 | /** |
54 | 36 | * Additional argument to append to the compiler command line |
55 | 37 | */ |
56 | | - def extraArgBefore(arg: String): Unit = { |
57 | | - if (!arg.isEmpty) { |
58 | | - extraArgBefore += arg |
59 | | - } |
60 | | - } |
| 38 | + def extraArgBefore(arg: String): Unit |
61 | 39 |
|
62 | 40 | /** |
63 | 41 | * Run binding generator |
64 | 42 | */ |
65 | | - def generate(): Bindings = { |
66 | | - // TODO: generate bindings |
67 | | - new Bindings("") |
68 | | - } |
| 43 | + def generate(): Bindings |
69 | 44 | } |
70 | 45 |
|
71 | 46 | object Builder { |
72 | | - def apply(): Builder = new Builder() |
| 47 | + def apply(): Builder = Impl() |
| 48 | + |
| 49 | + private final case class Impl() extends Builder { |
| 50 | + private var library: String = _ |
| 51 | + private var header: File = _ |
| 52 | + private var packageName: String = _ |
| 53 | + private var excludePrefix: String = _ |
| 54 | + private var extraArg: mutable.Seq[String] = mutable.Seq() |
| 55 | + private var extraArgBefore: mutable.Seq[String] = mutable.Seq() |
| 56 | + |
| 57 | + /** |
| 58 | + * Set header file for which bindings will be generated |
| 59 | + */ |
| 60 | + def header(header: File): Unit = { |
| 61 | + this.header = header |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Library to link with, e.g. -luv for libuv |
| 66 | + */ |
| 67 | + def link(library: String): Unit = { |
| 68 | + this.library = library |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Package name of generated Scala file |
| 73 | + */ |
| 74 | + def packageName(packageName: String): Unit = { |
| 75 | + this.packageName = packageName |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Declarations will be removed if their names |
| 80 | + * contain given prefix |
| 81 | + */ |
| 82 | + def excludePrefix(prefix: String): Unit = { |
| 83 | + require(!prefix.isEmpty) |
| 84 | + excludePrefix = prefix |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Additional argument to append to the compiler command line |
| 89 | + */ |
| 90 | + def extraArg(arg: String): Unit = { |
| 91 | + require(!arg.isEmpty) |
| 92 | + extraArg :+ arg |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Additional argument to append to the compiler command line |
| 97 | + */ |
| 98 | + def extraArgBefore(arg: String): Unit = { |
| 99 | + require(!arg.isEmpty) |
| 100 | + extraArgBefore :+ arg |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Run binding generator |
| 105 | + */ |
| 106 | + def generate(): Bindings = { |
| 107 | + // TODO: generate bindings |
| 108 | + new Bindings("") |
| 109 | + } |
| 110 | + } |
73 | 111 | } |
0 commit comments