Add annotation for default parameter value
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
class A {
|
||||
public int first(
|
||||
@ParameterName("first") @DefaultValue("42") int a,
|
||||
@ParameterName("second") @DefaultValue("1") int b
|
||||
) {
|
||||
return 100 * a + b;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
if (a.first() != 100 * 42 + 1) {
|
||||
return "FAIL 1"
|
||||
}
|
||||
|
||||
if (a.first(second = 2) != 100 * 42 + 2) {
|
||||
return "FAIL 2"
|
||||
}
|
||||
|
||||
if (a.first(first = 2) != 100 * 2 + 1) {
|
||||
return "FAIL 3"
|
||||
}
|
||||
|
||||
if (a.first(second = 2, first = 5) != 100 * 5 + 2) {
|
||||
return "FAIL 4"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
|
||||
public Integer a(@DefaultValue("42") Integer arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Float b(@DefaultValue("42.5") Float arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Boolean c(@DefaultValue("true") Boolean arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Byte d(@DefaultValue("42") Byte arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Character e(@DefaultValue("o") Character arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Double f(@DefaultValue("1e12") Double arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Long g(@DefaultValue("42424242424242") Long arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Short h(@DefaultValue("123") Short arg) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
if (a.a() != 42) {
|
||||
return "FAIL Int: ${a.a()}"
|
||||
}
|
||||
|
||||
if (a.b() != 42.5f) {
|
||||
return "FAIL Float: ${a.b()}"
|
||||
}
|
||||
|
||||
if (!a.c()) {
|
||||
return "FAIL Boolean: ${a.c()}"
|
||||
}
|
||||
|
||||
if (a.d() != 42.toByte()) {
|
||||
return "FAIL Byte: ${a.d()}"
|
||||
}
|
||||
|
||||
if (a.e() != 'o') {
|
||||
return "FAIL Char: ${a.e()}"
|
||||
}
|
||||
|
||||
if (a.f() != 1e12) {
|
||||
return "FAIl Double: ${a.f()}"
|
||||
}
|
||||
|
||||
if (a.g() != 42424242424242) {
|
||||
return "FAIL Long: ${a.g()}"
|
||||
}
|
||||
|
||||
if (a.h() != 123.toShort()) {
|
||||
return "FAIL Short: ${a.h()}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: Signs.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
public enum Signs {
|
||||
HELLO,
|
||||
WORLD;
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
enum class B {
|
||||
X,
|
||||
Y;
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
class A {
|
||||
public Signs a(@DefaultValue("HELLO") Signs arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public B b(@DefaultValue("Y") B arg) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
if (a.a() != Signs.HELLO) {
|
||||
return "FAIL: enums Java"
|
||||
}
|
||||
|
||||
if (a.b() != B.Y) {
|
||||
return "FAIL: enums Kotlin"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
public Long first(@DefaultValue("0x1F") Long value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Long second(@DefaultValue("0X1F") Long value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Long third(@DefaultValue("0b1010") Long value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Long fourth(@DefaultValue("0B1010") Long value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
if (a.first() != 0x1F.toLong()) {
|
||||
return "FAIL 1"
|
||||
}
|
||||
|
||||
if (a.second() != 0x1F.toLong()) {
|
||||
return "FAIL 2"
|
||||
}
|
||||
|
||||
if (a.third() != 0b1010.toLong()) {
|
||||
return "FAIL 3"
|
||||
}
|
||||
|
||||
if (a.fourth() != 0b1010.toLong()) {
|
||||
return "FAIL 4"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
class A {
|
||||
public int first(@DefaultValue("1") int a, @DefaultValue("2") int b) {
|
||||
return 100 * a + b;
|
||||
}
|
||||
|
||||
public int second(int a, @DefaultValue("42") int b) {
|
||||
return 100 * a + b;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
if (a.first() != 102) {
|
||||
return "FAIL 1"
|
||||
}
|
||||
|
||||
if (a.first(2) != 202) {
|
||||
return "FAIL 2"
|
||||
}
|
||||
|
||||
if (a.first(3, 4) != 304) {
|
||||
return "FAIL 3"
|
||||
}
|
||||
|
||||
if (a.second(7, 8) != 708) {
|
||||
return "FAIL 4"
|
||||
}
|
||||
|
||||
if (a.second(1) != 142) {
|
||||
return "FAIL 5"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
public Integer foo(@DefaultNull Integer x) { return x; }
|
||||
public Integer bar(@DefaultNull Integer x) { return x; }
|
||||
|
||||
public Integer baz(@DefaultValue("42") Integer x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: AInt.java
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public interface AInt {
|
||||
public Integer foo(@DefaultValue("42") Integer x);
|
||||
public Integer bar(@DefaultNull Integer x);
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
|
||||
public class B extends A {
|
||||
public Integer foo(Integer x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class C extends A {
|
||||
public Integer foo(@DefaultValue("42") Integer x) { return x; }
|
||||
|
||||
public Integer baz(@DefaultNull Integer x) { return x; }
|
||||
}
|
||||
|
||||
// FILE: D.java
|
||||
|
||||
public class D extends A implements AInt {
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
if (A().foo() != null) return "FAIL 0"
|
||||
|
||||
if (B().foo() != null) return "FAIL 1"
|
||||
if (B().bar() != null) return "FAIL 2"
|
||||
|
||||
if (C().foo() != null) return "FAIL 3"
|
||||
if (C().baz() != 42) return "FAIL 4"
|
||||
|
||||
if (D().baz() != 42) return "FAIL 5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class A {
|
||||
|
||||
public Integer a(@Nullable @DefaultValue("42") Integer arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Float b(@Nullable @DefaultValue("42.5") Float arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Boolean c(@Nullable @DefaultValue("true") Boolean arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Byte d(@Nullable @DefaultValue("42") Byte arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Character e(@Nullable @DefaultValue("o") Character arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Double f(@Nullable @DefaultValue("1e12") Double arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Long g(@Nullable @DefaultValue("42424242424242") Long arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public Short h(@Nullable @DefaultValue("123") Short arg) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
if (a.a() != 42) {
|
||||
return "FAIL Int: ${a.a()}"
|
||||
}
|
||||
|
||||
if (a.b() != 42.5f) {
|
||||
return "FAIL Float: ${a.b()}"
|
||||
}
|
||||
|
||||
if (!a.c()) {
|
||||
return "FAIL Boolean: ${a.c()}"
|
||||
}
|
||||
|
||||
if (a.d() != 42.toByte()) {
|
||||
return "FAIL Byte: ${a.d()}"
|
||||
}
|
||||
|
||||
if (a.e() != 'o') {
|
||||
return "FAIL Char: ${a.e()}"
|
||||
}
|
||||
|
||||
if (a.f() != 1e12) {
|
||||
return "FAIl Double: ${a.f()}"
|
||||
}
|
||||
|
||||
if (a.g() != 42424242424242) {
|
||||
return "FAIL Long: ${a.g()}"
|
||||
}
|
||||
|
||||
if (a.h() != 123.toShort()) {
|
||||
return "FAIL Short: ${a.h()}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
class A {
|
||||
public int first(@DefaultValue("42") int a) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
class B extends A {
|
||||
public int first(int a) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val b = B()
|
||||
val ab: A = B()
|
||||
|
||||
if (a.first() != 42) {
|
||||
return "FAIL 1"
|
||||
}
|
||||
if (b.first() != 42) {
|
||||
return "FAIL 2"
|
||||
}
|
||||
if (ab.first() != 42) {
|
||||
return "FAIL 4"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
|
||||
public int a(@DefaultValue("42") int arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public float b(@DefaultValue("42.5") float arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public boolean c(@DefaultValue("true") boolean arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public byte d(@DefaultValue("42") byte arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public char e(@DefaultValue("o") char arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public double f(@DefaultValue("1e12") double arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public String g(@DefaultValue("hello") String arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public long h(@DefaultValue("42424242424242") long arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public short i(@DefaultValue("123") short arg) {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
if (a.a() != 42) {
|
||||
return "FAIL Int: ${a.a()}"
|
||||
}
|
||||
|
||||
if (a.b() != 42.5f) {
|
||||
return "FAIL Float: ${a.b()}"
|
||||
}
|
||||
|
||||
if (!a.c()) {
|
||||
return "FAIL Boolean: ${a.c()}"
|
||||
}
|
||||
|
||||
if (a.d() != 42.toByte()) {
|
||||
return "FAIL Byte: ${a.d()}"
|
||||
}
|
||||
|
||||
if (a.e() != 'o') {
|
||||
return "FAIL Char: ${a.e()}"
|
||||
}
|
||||
|
||||
if (a.f() != 1e12) {
|
||||
return "FAIl Double: ${a.f()}"
|
||||
}
|
||||
|
||||
if (a.g() != "hello") {
|
||||
return "FAIL String: ${a.g()}"
|
||||
}
|
||||
|
||||
if (a.h() != 42424242424242) {
|
||||
return "FAIL Long: ${a.h()}"
|
||||
}
|
||||
|
||||
if (a.i() != 123.toShort()) {
|
||||
return "FAIL Short: ${a.i()}"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
public String x;
|
||||
public A(@DefaultValue("OK") String hello) {
|
||||
x = hello;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
val b = object : A() {
|
||||
}
|
||||
|
||||
val c = object : A() {
|
||||
fun hello() = x
|
||||
}
|
||||
|
||||
if (a.x != "OK") {
|
||||
return "FAIL 1"
|
||||
}
|
||||
|
||||
if (b.x != "OK") {
|
||||
return "FAIL 2"
|
||||
}
|
||||
|
||||
if (c.hello() != "OK") {
|
||||
return "FAIL 3"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
public int x(@DefaultValue("42") int x) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
class B : A() {
|
||||
override fun x(x: Int): Int = x + 1
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
if (B().x() != 43) {
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.kt
|
||||
open class A {
|
||||
open fun x(x: Int = foo()) = x
|
||||
private fun foo() = 42
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
public class B extends A {
|
||||
public int x(int i) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
fun box(): String {
|
||||
if (B().x() != 43) {
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user