@@ -10,14 +10,13 @@ import java.lang.reflect.Constructor
10
10
import java.lang.reflect.Executable
11
11
import java.lang.reflect.Field
12
12
import java.lang.reflect.Method
13
- import java.net.URL
14
13
import java.net.URLClassLoader
15
14
import kotlin.reflect.KFunction
16
15
import kotlin.reflect.KVisibility
17
16
import kotlin.reflect.jvm.kotlinFunction
18
17
import kotlin.reflect.jvm.kotlinProperty
19
18
20
- class Processor (xmlFile : File , jarFiles : List <File >, outputFile : File ? ) {
19
+ class Processor (xmlFile : File , jarFiles : List <File >, outputFile : File ? , ignoreFile : File ? ) {
21
20
22
21
private fun expressionClasses () =
23
22
" /api/package/*[local-name()='class' or local-name()='interface']"
@@ -48,6 +47,8 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
48
47
private val outputFile: File ?
49
48
private val xtransformsdoc: Document
50
49
50
+ private val ignored: List <String >
51
+
51
52
init {
52
53
val urls = jarFiles.map { file -> file.toURI().toURL() }
53
54
loader = URLClassLoader (urls.toTypedArray())
@@ -57,6 +58,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
57
58
58
59
xtransformsdoc = Document (Element (" metadata" ))
59
60
this .outputFile = outputFile
61
+
62
+ if (ignoreFile != null ) {
63
+ ignored = ignoreFile.readLines()
64
+ } else {
65
+ ignored = emptyList()
66
+ }
60
67
}
61
68
62
69
fun process () {
@@ -196,13 +203,13 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
196
203
197
204
// remove the members that are not meant to be used
198
205
processMembers(xclass, " constructor" ) {
199
- shouldRemoveMember(it, jclass.declaredConstructors)
206
+ shouldRemoveMember(it, jclass.declaredConstructors + jclass.constructors )
200
207
}
201
208
processMembers(xclass, " method" ) {
202
- shouldRemoveMember(it, jclass.declaredMethods)
209
+ shouldRemoveMember(it, jclass.declaredMethods + jclass.methods )
203
210
}
204
211
processMembers(xclass, " field" ) {
205
- shouldRemoveField(it, jclass.declaredFields)
212
+ shouldRemoveField(it, jclass.declaredFields + jclass.fields )
206
213
}
207
214
}
208
215
@@ -253,6 +260,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
253
260
254
261
logVerbose(" Checking the class \" ${xpackage} .${xname} \" ..." )
255
262
263
+ // make sure we haven't been told to ignore this
264
+ if (ignored.contains(" ${xpackage} .${xname} " )) {
265
+ logVerbose(" Ignoring class \" ${xpackage} .${xname} \" because it was found in the ignore file..." )
266
+ return ProcessResult .Ignore
267
+ }
268
+
256
269
// before we check anything, make sure that the parent class is visible
257
270
var lastPeriod = xname.lastIndexOf(" ." )
258
271
while (lastPeriod != - 1 ) {
@@ -319,6 +332,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
319
332
val xtype = xmember.localName
320
333
val xfullname = " ${xpackage} .${xclassname} .${xname} "
321
334
335
+ // make sure we haven't been told to ignore this
336
+ if (ignored.contains(xfullname)) {
337
+ logVerbose(" Ignoring member \" ${xfullname} \" because it was found in the ignore file..." )
338
+ return ProcessResult .Ignore
339
+ }
340
+
322
341
// before doing any complex checks, make sure it is not an invalid member
323
342
if (invalidKeywords.any { check -> check(xname) })
324
343
return ProcessResult .RemoveGenerated
@@ -410,6 +429,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
410
429
val xtype = xmember.getAttributeValue(" type" )
411
430
val xfullname = " ${xpackage} .${xclassname} .${xname} "
412
431
432
+ // make sure we haven't been told to ignore this
433
+ if (ignored.contains(xfullname)) {
434
+ logVerbose(" Ignoring field \" ${xfullname} \" because it was found in the ignore file..." )
435
+ return ProcessResult .Ignore
436
+ }
437
+
413
438
// before doing any complex checks, make sure it is not an invalid member
414
439
if (invalidKeywords.any { check -> check(xname) }) {
415
440
return ProcessResult .RemoveGenerated
@@ -767,14 +792,14 @@ private val Element.parentElement: Element
767
792
768
793
private val KmPackage .functionOverloads: List <Pair <KmFunction , List <KmValueParameter >>>
769
794
get() = this .functions.map {
770
- it to it.valueParameters.getOverloads()
795
+ it to it.valueParameters.getOverloads(it.receiverParameterType )
771
796
}.flatMap { overload ->
772
797
overload.second.map { params -> overload.first to params }
773
798
}
774
799
775
800
private val KmClass .functionOverloads: List <Pair <KmFunction , List <KmValueParameter >>>
776
801
get() = this .functions.map {
777
- it to it.valueParameters.getOverloads()
802
+ it to it.valueParameters.getOverloads(it.receiverParameterType )
778
803
}.flatMap { overload ->
779
804
overload.second.map { params -> overload.first to params }
780
805
}
@@ -786,9 +811,15 @@ private val KmClass.constructorOverloads: List<Pair<KmConstructor, List<KmValueP
786
811
overload.second.map { params -> overload.first to params }
787
812
}
788
813
789
- private fun List<KmValueParameter>.getOverloads (): List <List <KmValueParameter >> {
814
+ private fun List<KmValueParameter>.getOverloads (receiverParameterType : KmType ? = null ): List <List <KmValueParameter >> {
790
815
val overloads = mutableListOf<List <KmValueParameter >>()
791
- overloads.add(this )
816
+ if (receiverParameterType == null ) {
817
+ overloads.add(this )
818
+ } else {
819
+ val t = KmValueParameter (0 , " this" )
820
+ t.type = receiverParameterType
821
+ overloads.add(listOf (t) + this )
822
+ }
792
823
while (Flag .ValueParameter .DECLARES_DEFAULT_VALUE (overloads.last().lastOrNull()?.flags ? : 0 )) {
793
824
val l = overloads.last()
794
825
overloads.add(l.take(l.size - 1 ))
0 commit comments