Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 62eb4bf

Browse files
committed
Revert "Revert "Improve Kotlin Binding Support (#685)""
This reverts commit e3c55a9.
1 parent 4615343 commit 62eb4bf

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

Util/Xamarin.Kotlin.BindingSupport/build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
var TARGET = Argument("t", Argument("target", "Default"));
33

4-
var PACKAGE_VERSION = "0.2.0-preview";
4+
var PACKAGE_VERSION = "0.3.0-preview";
55

66
Task("externals")
77
.Does(() =>

Util/Xamarin.Kotlin.BindingSupport/native/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id 'java'
3-
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
3+
id 'org.jetbrains.kotlin.jvm' version '1.3.0'
44
}
55

66
group 'xamarin.binding.kotlin'
@@ -17,8 +17,8 @@ dependencies {
1717
compile 'com.github.ajalt:clikt:2.1.0'
1818
compile 'xom:xom:1.3.2'
1919
compile 'org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.1.0'
20-
compile "org.jetbrains.kotlin:kotlin-stdlib:1.3.41"
21-
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.41"
20+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.3.0"
21+
compile "org.jetbrains.kotlin:kotlin-reflect:1.3.0"
2222
}
2323

2424
compileKotlin {

Util/Xamarin.Kotlin.BindingSupport/native/src/main/kotlin/xamarin/binding/kotlin/bindingsupport/ProcessXmlCommand.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class ProcessXmlCommand : CliktCommand(name = "KotlinBindingSupport") {
2020
val outputFile: File? by option("-o", "--output", help = "path to the output transform file")
2121
.file(fileOkay = true, folderOkay = false)
2222

23+
val ignoreFile: File? by option("-i", "--ignore", help = "path to the ignore file")
24+
.file(fileOkay = true, folderOkay = false)
25+
2326
val companions: Processor.CompanionProcessing by option("--companions", help = "indicate how to handle companions")
2427
.choice(
2528
"default" to Processor.CompanionProcessing.Default,
@@ -32,7 +35,7 @@ class ProcessXmlCommand : CliktCommand(name = "KotlinBindingSupport") {
3235
.flag(default = false)
3336

3437
override fun run() {
35-
val proc = Processor(xmlFile, jarFiles, outputFile)
38+
val proc = Processor(xmlFile, jarFiles, outputFile, ignoreFile)
3639
proc.verbose = verbose
3740
proc.companions = companions
3841
proc.process()

Util/Xamarin.Kotlin.BindingSupport/native/src/main/kotlin/xamarin/binding/kotlin/bindingsupport/Processor.kt

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import java.lang.reflect.Constructor
1010
import java.lang.reflect.Executable
1111
import java.lang.reflect.Field
1212
import java.lang.reflect.Method
13-
import java.net.URL
1413
import java.net.URLClassLoader
1514
import kotlin.reflect.KFunction
1615
import kotlin.reflect.KVisibility
1716
import kotlin.reflect.jvm.kotlinFunction
1817
import kotlin.reflect.jvm.kotlinProperty
1918

20-
class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
19+
class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?, ignoreFile: File?) {
2120

2221
private fun expressionClasses() =
2322
"/api/package/*[local-name()='class' or local-name()='interface']"
@@ -48,6 +47,8 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
4847
private val outputFile: File?
4948
private val xtransformsdoc: Document
5049

50+
private val ignored: List<String>
51+
5152
init {
5253
val urls = jarFiles.map { file -> file.toURI().toURL() }
5354
loader = URLClassLoader(urls.toTypedArray())
@@ -57,6 +58,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
5758

5859
xtransformsdoc = Document(Element("metadata"))
5960
this.outputFile = outputFile
61+
62+
if (ignoreFile != null) {
63+
ignored = ignoreFile.readLines()
64+
} else {
65+
ignored = emptyList()
66+
}
6067
}
6168

6269
fun process() {
@@ -196,13 +203,13 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
196203

197204
// remove the members that are not meant to be used
198205
processMembers(xclass, "constructor") {
199-
shouldRemoveMember(it, jclass.declaredConstructors)
206+
shouldRemoveMember(it, jclass.declaredConstructors + jclass.constructors)
200207
}
201208
processMembers(xclass, "method") {
202-
shouldRemoveMember(it, jclass.declaredMethods)
209+
shouldRemoveMember(it, jclass.declaredMethods + jclass.methods)
203210
}
204211
processMembers(xclass, "field") {
205-
shouldRemoveField(it, jclass.declaredFields)
212+
shouldRemoveField(it, jclass.declaredFields + jclass.fields)
206213
}
207214
}
208215

@@ -253,6 +260,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
253260

254261
logVerbose("Checking the class \"${xpackage}.${xname}\"...")
255262

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+
256269
// before we check anything, make sure that the parent class is visible
257270
var lastPeriod = xname.lastIndexOf(".")
258271
while (lastPeriod != -1) {
@@ -319,6 +332,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
319332
val xtype = xmember.localName
320333
val xfullname = "${xpackage}.${xclassname}.${xname}"
321334

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+
322341
// before doing any complex checks, make sure it is not an invalid member
323342
if (invalidKeywords.any { check -> check(xname) })
324343
return ProcessResult.RemoveGenerated
@@ -410,6 +429,12 @@ class Processor(xmlFile: File, jarFiles: List<File>, outputFile: File?) {
410429
val xtype = xmember.getAttributeValue("type")
411430
val xfullname = "${xpackage}.${xclassname}.${xname}"
412431

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+
413438
// before doing any complex checks, make sure it is not an invalid member
414439
if (invalidKeywords.any { check -> check(xname) }) {
415440
return ProcessResult.RemoveGenerated
@@ -767,14 +792,14 @@ private val Element.parentElement: Element
767792

768793
private val KmPackage.functionOverloads: List<Pair<KmFunction, List<KmValueParameter>>>
769794
get() = this.functions.map {
770-
it to it.valueParameters.getOverloads()
795+
it to it.valueParameters.getOverloads(it.receiverParameterType)
771796
}.flatMap { overload ->
772797
overload.second.map { params -> overload.first to params }
773798
}
774799

775800
private val KmClass.functionOverloads: List<Pair<KmFunction, List<KmValueParameter>>>
776801
get() = this.functions.map {
777-
it to it.valueParameters.getOverloads()
802+
it to it.valueParameters.getOverloads(it.receiverParameterType)
778803
}.flatMap { overload ->
779804
overload.second.map { params -> overload.first to params }
780805
}
@@ -786,9 +811,15 @@ private val KmClass.constructorOverloads: List<Pair<KmConstructor, List<KmValueP
786811
overload.second.map { params -> overload.first to params }
787812
}
788813

789-
private fun List<KmValueParameter>.getOverloads(): List<List<KmValueParameter>> {
814+
private fun List<KmValueParameter>.getOverloads(receiverParameterType: KmType? = null): List<List<KmValueParameter>> {
790815
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+
}
792823
while (Flag.ValueParameter.DECLARES_DEFAULT_VALUE(overloads.last().lastOrNull()?.flags ?: 0)) {
793824
val l = overloads.last()
794825
overloads.add(l.take(l.size - 1))

Util/Xamarin.Kotlin.BindingSupport/source/Xamarin.Kotlin.BindingSupport.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@
99
<PropertyGroup>
1010
<KotlinBindingSupportJar Condition="'$(KotlinBindingSupportJar)' == ''">$(MSBuildThisFileDirectory)binding-support-1.0.jar</KotlinBindingSupportJar>
1111
<KotlinBindingSupportExtraArgs Condition="'$(KotlinBindingSupportExtraArgs)' == ''"></KotlinBindingSupportExtraArgs>
12+
<KotlinBindingSupportIgnorePath Condition="'$(KotlinBindingSupportIgnorePath)' == ''"></KotlinBindingSupportIgnorePath>
1213
<KotlinBindingSupportOutputPath Condition="'$(KotlinBindingSupportOutputPath)' == ''">$(IntermediateOutputPath)\KotlinBindingSupport.generated.xml</KotlinBindingSupportOutputPath>
1314
</PropertyGroup>
1415

1516
<!-- private properties -->
1617
<PropertyGroup>
1718
<_KotlinBindingJavaPath Condition="'$(_KotlinBindingJavaPath)' == '' and '$(OS)' == 'Unix'">$(JavaSdkDirectory)\bin\java</_KotlinBindingJavaPath>
1819
<_KotlinBindingJavaPath Condition="'$(_KotlinBindingJavaPath)' == '' and '$(OS)' != 'Unix'">$(JavaSdkDirectory)\bin\java.exe</_KotlinBindingJavaPath>
20+
<_KotlinBindingSupportIgnore Condition="'$(KotlinBindingSupportIgnorePath)' != ''">--ignore &quot;$(KotlinBindingSupportIgnorePath)&quot;</_KotlinBindingSupportIgnore>
1921
</PropertyGroup>
2022

2123
<ItemGroup>
2224
<_KotlinBindingReferenceJar Include="@(EmbeddedJar);@(InputJar)" />
2325
<_KotlinBindingReferenceJar Include="@(EmbeddedReferenceJar);@(ReferenceJar);@(_AdditionalJavaLibraryReferences)" />
2426
</ItemGroup>
2527

26-
<Exec Command="&quot;$(_KotlinBindingJavaPath)&quot; -jar &quot;$(KotlinBindingSupportJar)&quot; --xml &quot;$(ApiOutputFile)&quot; --jar &quot;@(_KotlinBindingReferenceJar, '&quot; --jar &quot;')&quot; --output &quot;$(KotlinBindingSupportOutputPath)&quot; $(KotlinBindingSupportExtraArgs)" />
28+
<Exec Command="&quot;$(_KotlinBindingJavaPath)&quot; -jar &quot;$(KotlinBindingSupportJar)&quot; --xml &quot;$(ApiOutputFile)&quot; --jar &quot;@(_KotlinBindingReferenceJar, '&quot; --jar &quot;')&quot; --output &quot;$(KotlinBindingSupportOutputPath)&quot; $(_KotlinBindingSupportIgnore) $(KotlinBindingSupportExtraArgs)" />
2729

2830
<ItemGroup>
2931
<!-- insert the generated transform at the beginning -->

0 commit comments

Comments
 (0)