@@ -26,7 +26,7 @@ sealed trait Bindgen {
26
26
* Name of Scala object that contains bindings.
27
27
* Default is set to library name.
28
28
*/
29
- def scalaObjectName ( scalaObjectName : String ): Bindgen
29
+ def name ( name : String ): Bindgen
30
30
31
31
/**
32
32
* Package name of generated Scala file
@@ -59,44 +59,44 @@ object Bindgen {
59
59
def apply (): Bindgen = Impl ()
60
60
61
61
private final case class Impl (
62
- executable : File = null ,
63
- library : String = null ,
64
- header : File = null ,
65
- scalaObjectName : String = null ,
66
- packageName : String = null ,
67
- excludePrefix : String = null ,
62
+ executable : Option [ File ] = None ,
63
+ library : Option [ String ] = None ,
64
+ header : Option [ File ] = None ,
65
+ name : Option [ String ] = None ,
66
+ packageName : Option [ String ] = None ,
67
+ excludePrefix : Option [ String ] = None ,
68
68
extraArg : immutable.Seq [String ] = immutable.Seq [String ](),
69
69
extraArgBefore : immutable.Seq [String ] = immutable.Seq [String ]())
70
70
extends Bindgen {
71
71
72
72
def bindgenExecutable (executable : File ): Bindgen = {
73
73
require(executable.exists())
74
- copy(executable = executable)
74
+ copy(executable = Option ( executable) )
75
75
}
76
76
77
77
def header (header : File ): Bindgen = {
78
78
require(header.exists())
79
- copy(header = header)
79
+ copy(header = Option ( header) )
80
80
}
81
81
82
82
def link (library : String ): Bindgen = {
83
83
require(! library.isEmpty)
84
- copy(library = library)
84
+ copy(library = Option ( library) )
85
85
}
86
86
87
- def scalaObjectName ( scalaObjectName : String ): Bindgen = {
88
- require(! scalaObjectName .isEmpty)
89
- copy(scalaObjectName = scalaObjectName )
87
+ def name ( name : String ): Bindgen = {
88
+ require(! name .isEmpty)
89
+ copy(name = Option (name) )
90
90
}
91
91
92
92
def packageName (packageName : String ): Bindgen = {
93
93
require(! packageName.isEmpty)
94
- copy(packageName = packageName)
94
+ copy(packageName = Option ( packageName) )
95
95
}
96
96
97
97
def excludePrefix (prefix : String ): Bindgen = {
98
98
require(! prefix.isEmpty)
99
- copy(excludePrefix = prefix)
99
+ copy(excludePrefix = Option ( prefix) )
100
100
}
101
101
102
102
def extraArg (args : String * ): Bindgen = {
@@ -110,41 +110,31 @@ object Bindgen {
110
110
}
111
111
112
112
private def validateFields (): Unit = {
113
- if (executable == null ) {
114
- throw new AssertionError (" Specify bindgen executable" )
115
- }
116
- if (header == null ) {
117
- throw new AssertionError (" Specify header file" )
118
- }
119
- if (library == null ) {
120
- throw new AssertionError (" Specify library name" )
121
- }
113
+ require(executable.isDefined, " The executable must be specified" )
114
+ require(header.isDefined, " Header file must be specified" )
115
+ require(library.isDefined, " Library name must be specified" )
122
116
}
123
117
124
118
def generate (): Bindings = {
125
119
validateFields()
126
120
127
- val scalaObjectName =
128
- if (this .scalaObjectName != null )
129
- this .scalaObjectName
130
- else
131
- library
121
+ val name = this .name.getOrElse(library.get)
132
122
133
123
var cmd = Seq (
134
- executable.getAbsolutePath,
135
- header.getAbsolutePath,
124
+ executable.get. getAbsolutePath,
125
+ header.get. getAbsolutePath,
136
126
" --name" ,
137
- scalaObjectName ,
127
+ name ,
138
128
" --link" ,
139
- library
129
+ library.get
140
130
)
141
131
142
- if (packageName != null ) {
143
- cmd ++= Seq (" --package" , packageName)
132
+ if (packageName.isDefined ) {
133
+ cmd ++= Seq (" --package" , packageName.get )
144
134
}
145
135
146
- if (excludePrefix != null ) {
147
- cmd ++= Seq (" --exclude-prefix" , excludePrefix)
136
+ if (excludePrefix.isDefined ) {
137
+ cmd ++= Seq (" --exclude-prefix" , excludePrefix.get )
148
138
}
149
139
150
140
extraArg.foreach(arg => cmd ++= Seq (" --extra-arg" , arg))
0 commit comments