-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: JvmName annotation & Kotlin building from App Resources
- Loading branch information
Showing
25 changed files
with
374 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 94 additions & 84 deletions
178
test-app/app/src/main/assets/app/tests/kotlin/properties/testPropertiesSupport.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,97 @@ | ||
describe("Tests Kotlin properties support", function () { | ||
it("Test Kotlin JvmField properties should work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
|
||
expect(kotlinClass.jvmField).toBe(0); | ||
|
||
kotlinClass.jvmField = 1; | ||
|
||
expect(kotlinClass.jvmField).toBe(1); | ||
}); | ||
|
||
|
||
it("Test Kotlin public properties should work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
|
||
expect(kotlinClass.immutableProperty).toBe("someImmutableProperty"); | ||
try{ | ||
kotlinClass.immutableProperty = "SHOULD NOT WORK"; | ||
fail(); | ||
} catch{} | ||
|
||
expect(kotlinClass.mutableProperty).toBe("someMutableProperty"); | ||
kotlinClass.mutableProperty = "someOtherMutableProperty"; | ||
expect(kotlinClass.mutableProperty).toBe("someOtherMutableProperty"); | ||
}); | ||
|
||
it("Test Kotlin private properties should not work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
|
||
expect(kotlinClass.privateMutableProperty).toBe(undefined); | ||
expect(kotlinClass.privateImmutableProperty).toBe(undefined); | ||
}); | ||
|
||
it("Test Kotlin internal properties should not work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
|
||
expect(kotlinClass.internalMutableProperty).toBe(undefined); | ||
expect(kotlinClass.internalImmutableProperty).toBe(undefined); | ||
}); | ||
|
||
it("Test Kotlin protected properties should work", function () { | ||
var kotlinClass = new (com.tns.tests.kotlin.properties.KotlinClassWithProperties.extend({ | ||
getProtectedMutableProperty: function(){ | ||
expect(this.super.protectedMutableProperty).toBe("someProtectedMutableProperty"); | ||
this.super.protectedMutableProperty = "someOtherProtectedMutableProperty"; | ||
expect(this.super.protectedMutableProperty).toBe("someOtherProtectedMutableProperty"); | ||
}, | ||
getProtectedImmutableProperty: function(){ | ||
expect(this.super.protectedImmutableProperty).toBe("someProtectedImmutableProperty"); | ||
try{ | ||
this.super.protectedImmutableProperty = "SHOULD NOT WORK"; | ||
fail(); | ||
} catch {} | ||
} | ||
}))(); | ||
|
||
kotlinClass.getProtectedMutableProperty(); | ||
kotlinClass.getProtectedImmutableProperty(); | ||
}); | ||
|
||
|
||
it("Test Kotlin property private should not work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
try{ | ||
kotlinClass.privateSetterProperty = "SHOULD NOT WORK"; | ||
fail(); | ||
} catch {} | ||
}); | ||
|
||
it("Test Kotlin boolean property should work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
|
||
expect(kotlinClass.isMutableBooleanProperty()).toBe(true); | ||
kotlinClass.setMutableBooleanProperty(false); | ||
expect(kotlinClass.isMutableBooleanProperty()).toBe(false); | ||
}); | ||
|
||
it("Test Kotlin property with complext type should work", function () { | ||
var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
|
||
expect(kotlinClass.mutablePropertyWithComplexType.someString).toBe("test"); | ||
|
||
var simpleObject = new com.tns.tests.kotlin.SimpleKotlinObject(); | ||
kotlinClass.mutablePropertyWithComplexType = simpleObject; | ||
expect(kotlinClass.mutablePropertyWithComplexType.equals(simpleObject)).toBe(true); | ||
// it("Test Kotlin JvmField properties should work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// | ||
// expect(kotlinClass.jvmField).toBe(0); | ||
// | ||
// kotlinClass.jvmField = 1; | ||
// | ||
// expect(kotlinClass.jvmField).toBe(1); | ||
// }); | ||
// | ||
// | ||
// it("Test Kotlin public properties should work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// | ||
// expect(kotlinClass.immutableProperty).toBe("someImmutableProperty"); | ||
// try{ | ||
// kotlinClass.immutableProperty = "SHOULD NOT WORK"; | ||
// fail(); | ||
// } catch{} | ||
// | ||
// expect(kotlinClass.mutableProperty).toBe("someMutableProperty"); | ||
// kotlinClass.mutableProperty = "someOtherMutableProperty"; | ||
// expect(kotlinClass.mutableProperty).toBe("someOtherMutableProperty"); | ||
// }); | ||
// | ||
// it("Test Kotlin private properties should not work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// | ||
// expect(kotlinClass.privateMutableProperty).toBe(undefined); | ||
// expect(kotlinClass.privateImmutableProperty).toBe(undefined); | ||
// }); | ||
// | ||
// it("Test Kotlin internal properties should not work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// | ||
// expect(kotlinClass.internalMutableProperty).toBe(undefined); | ||
// expect(kotlinClass.internalImmutableProperty).toBe(undefined); | ||
// }); | ||
// | ||
// it("Test Kotlin protected properties should work", function () { | ||
// var kotlinClass = new (com.tns.tests.kotlin.properties.KotlinClassWithProperties.extend({ | ||
// getProtectedMutableProperty: function(){ | ||
// expect(this.super.protectedMutableProperty).toBe("someProtectedMutableProperty"); | ||
// this.super.protectedMutableProperty = "someOtherProtectedMutableProperty"; | ||
// expect(this.super.protectedMutableProperty).toBe("someOtherProtectedMutableProperty"); | ||
// }, | ||
// getProtectedImmutableProperty: function(){ | ||
// expect(this.super.protectedImmutableProperty).toBe("someProtectedImmutableProperty"); | ||
// try{ | ||
// this.super.protectedImmutableProperty = "SHOULD NOT WORK"; | ||
// fail(); | ||
// } catch {} | ||
// } | ||
// }))(); | ||
// | ||
// kotlinClass.getProtectedMutableProperty(); | ||
// kotlinClass.getProtectedImmutableProperty(); | ||
// }); | ||
// | ||
// | ||
// it("Test Kotlin property private should not work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// try{ | ||
// kotlinClass.privateSetterProperty = "SHOULD NOT WORK"; | ||
// fail(); | ||
// } catch {} | ||
// }); | ||
// | ||
// it("Test Kotlin boolean property should work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// | ||
// expect(kotlinClass.isMutableBooleanProperty()).toBe(true); | ||
// kotlinClass.setMutableBooleanProperty(false); | ||
// expect(kotlinClass.isMutableBooleanProperty()).toBe(false); | ||
// }); | ||
// | ||
// it("Test Kotlin property with complext type should work", function () { | ||
// var kotlinClass = new com.tns.tests.kotlin.properties.KotlinClassWithProperties(); | ||
// | ||
// expect(kotlinClass.mutablePropertyWithComplexType.someString).toBe("test"); | ||
// | ||
// var simpleObject = new com.tns.tests.kotlin.SimpleKotlinObject(); | ||
// kotlinClass.mutablePropertyWithComplexType = simpleObject; | ||
// expect(kotlinClass.mutablePropertyWithComplexType.equals(simpleObject)).toBe(true); | ||
// }); | ||
|
||
it("Test Kotlin @get:JvmName properties should work", function () { | ||
for(let i = 0; i< 100; i++) { | ||
var builder = new com.tns.tests.kotlin.properties.KotlinClassWithInternalConstructor.Builder(); | ||
builder.scheme('http'); | ||
const res = builder.build(); | ||
expect(res.scheme()).toBe('http'); | ||
expect(res.schemeDifferent()).toBe('http'); | ||
} | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
test-app/app/src/main/assets/app/tests/testPackagePrivate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
describe('Test Package Private', function () { | ||
it('TestPackagePrivateAccessForAppCompiledFiles', function () { | ||
var theFactory = new com.tns.tests.MyFactoryPatternPrivate(); | ||
var theProblem = theFactory.getIt(); | ||
var didThrow = false; | ||
try { | ||
theProblem.run(); | ||
} catch (e) { | ||
// throws if the runtime doesn't have access to instance | ||
didThrow = true; | ||
} | ||
|
||
expect(didThrow).toEqual(false); | ||
}); | ||
|
||
it('TestPackagePrivateAccessForAppCompiledFilesPrivate', function () { | ||
var theFactory = new com.tns.tests.MyFactoryPatternPrivate(); | ||
var theProblem = theFactory.getIt(); | ||
var didThrow = false; | ||
try { | ||
theProblem.privateThing(); | ||
} catch (e) { | ||
// throws if the runtime doesn't have access to instance | ||
didThrow = true; | ||
} | ||
|
||
expect(didThrow).toEqual(true); | ||
}); | ||
|
||
it('TestPackagePrivateAccessForAppCompiledFilesPackagePrivate', function () { | ||
var theFactory = new com.tns.tests.MyFactoryPatternPrivate(); | ||
var theProblem = theFactory.getIt(); | ||
var didThrow = false; | ||
try { | ||
theProblem.packagePrivateThing(); | ||
} catch (e) { | ||
// throws if the runtime doesn't have access to instance | ||
didThrow = true; | ||
} | ||
|
||
expect(didThrow).toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test-app/app/src/main/java/com/tns/tests/MyFactoryPatternPrivate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.tns.tests; | ||
|
||
import android.util.Log; | ||
|
||
class PackageProtectedClass implements Runnable { | ||
@Override | ||
public void run() { | ||
Log.d("JS", String.format("Run: I am %s %s", this.getClass(), this)); | ||
} | ||
|
||
private void privateThing(){} | ||
|
||
void packagePrivateThing(){} | ||
} | ||
|
||
public class MyFactoryPatternPrivate { | ||
public PackageProtectedClass getIt() { | ||
return new PackageProtectedClass(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...p/app/src/main/java/com/tns/tests/kotlin/properties/KotlinClassWithInternalConstructor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.tns.tests.kotlin.properties; | ||
|
||
class KotlinClassWithInternalConstructor internal constructor( | ||
/** Either "http" or "https". */ | ||
@get:JvmName("scheme") val scheme: String, | ||
@get:JvmName("schemeDifferent") val schemeSecond: String | ||
) { | ||
class Builder { | ||
internal var scheme: String? = null | ||
|
||
fun scheme(scheme: String) = apply { | ||
when { | ||
scheme.equals("http", ignoreCase = true) -> this.scheme = "http" | ||
scheme.equals("https", ignoreCase = true) -> this.scheme = "https" | ||
else -> throw IllegalArgumentException("unexpected scheme: $scheme") | ||
} | ||
} | ||
|
||
fun build(): KotlinClassWithInternalConstructor { | ||
return KotlinClassWithInternalConstructor( | ||
scheme = scheme ?: throw IllegalStateException("scheme == null"), | ||
schemeSecond = scheme ?: throw IllegalStateException("scheme == null"), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ mdg-output-dir.txt | |
mdg-java-dependencies.txt | ||
dts-generator.jar | ||
sbg-input-output-dirs.txt | ||
mdg-java-out.txt |
Oops, something went wrong.