Skip to content

Commit e0f8919

Browse files
authored
Merge pull request #1214 from NativeScript/vmutafov/java-8-interfaces-support
Add static and default interface methods support
2 parents 37c6ae6 + 3ffa4a2 commit e0f8919

27 files changed

+1093
-586
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ bin/
1919
.settings
2020

2121
.classpath
22+
android-runtime.iml

test-app/app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ android {
195195
}
196196
}
197197

198+
compileOptions {
199+
sourceCompatibility JavaVersion.VERSION_1_8
200+
targetCompatibility JavaVersion.VERSION_1_8
201+
}
202+
198203
sourceSets.main {
199204
jniLibs.srcDir "$projectDir/libs/jni"
200205
}

test-app/app/src/main/assets/app/mainpage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ shared.runRequireTests();
2020
shared.runWeakRefTests();
2121
shared.runRuntimeTests();
2222
shared.runWorkerTests();
23+
require("./tests/testInterfaceDefaultMethods");
24+
require("./tests/testInterfaceStaticMethods");
2325
require("./tests/testMetadata");
2426
require("./tests/testAsserts");
2527
require("./tests/testWeakRef");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
describe("Tests Java 8 default methods support", function () {
2+
3+
it("Test default method overrides in extending classes", function () {
4+
var firstGen = new com.tns.tests.interfaces.defaultmethods.impl.FirstGeneration();
5+
expect(firstGen.grow()).toBe("first generation grow");
6+
7+
var secondGeneration = new com.tns.tests.interfaces.defaultmethods.impl.SecondGeneration();
8+
expect(secondGeneration.grow()).toBe("second generation grow");
9+
})
10+
11+
it("Test default method overrides in interfaces chain", function () {
12+
var producer = new com.tns.tests.interfaces.defaultmethods.impl.CarProducerImpl();
13+
expect(producer.produce()).toBe("default produce in CarProducer");
14+
})
15+
16+
17+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe("Tests Java 8 static methods support", function () {
2+
3+
it("Test static method in interface", function () {
4+
var producer = com.tns.tests.interfaces.staticmethods.StaticProducer;
5+
expect(producer.staticProduce()).toBe("static produce");
6+
})
7+
8+
9+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.tns.tests.interfaces.defaultmethods.contract;
2+
3+
public interface CarProducer extends Producer{
4+
5+
@Override
6+
default String produce(){
7+
return "default produce in CarProducer";
8+
}
9+
}
10+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.tns.tests.interfaces.defaultmethods.contract;
2+
3+
public interface Generation{
4+
default String grow(){
5+
return "default grow";
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.tns.tests.interfaces.defaultmethods.contract;
2+
3+
public interface Producer{
4+
5+
default String produce(){
6+
return "default produce in Producer";
7+
}
8+
}
9+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.tns.tests.interfaces.defaultmethods.impl;
2+
3+
import com.tns.tests.interfaces.defaultmethods.contract.CarProducer;
4+
5+
public class CarProducerImpl implements CarProducer {
6+
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.tns.tests.interfaces.defaultmethods.impl;
2+
3+
import com.tns.tests.interfaces.defaultmethods.contract.Generation;
4+
5+
public class FirstGeneration implements Generation {
6+
7+
@Override
8+
public String grow(){
9+
return "first generation grow";
10+
}
11+
12+
}

0 commit comments

Comments
 (0)