J2K - no '@' required for primary constructor annnotations
This commit is contained in:
@@ -431,7 +431,7 @@ class Converter private constructor(
|
||||
function.annotations += Annotations(
|
||||
listOf(Annotation(Identifier("jvmOverloads").assignNoPrototype(),
|
||||
listOf(),
|
||||
withAt = function is PrimaryConstructor,
|
||||
withAt = false,
|
||||
newLineAfter = false).assignNoPrototype())).assignNoPrototype()
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,3 @@ class Annotations(val annotations: List<Annotation>) : Element() {
|
||||
val Empty = Annotations(listOf())
|
||||
}
|
||||
}
|
||||
|
||||
fun Annotations.withAt(): Annotations
|
||||
= Annotations(annotations.map { Annotation(it.name, it.arguments, withAt = true, newLineAfter = it.newLineAfter).assignPrototypesFrom(it) }).assignPrototypesFrom(this)
|
||||
|
||||
@@ -61,7 +61,7 @@ class PrimaryConstructorSignature(val annotations: Annotations, private val modi
|
||||
var needConstructorKeyword = false
|
||||
|
||||
if (!annotations.isEmpty) {
|
||||
builder append " " append annotations.withAt()
|
||||
builder append " " append annotations
|
||||
needConstructorKeyword = true
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class C {
|
||||
@Deprecated
|
||||
public C() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
class C deprecated("")
|
||||
constructor()
|
||||
@@ -1,5 +1,5 @@
|
||||
class A// this is a primary constructor
|
||||
@jvmOverloads constructor(p: Int = 1) {
|
||||
jvmOverloads constructor(p: Int = 1) {
|
||||
private val v: Int
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package pack
|
||||
|
||||
class C @jvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0)
|
||||
class C jvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0)
|
||||
|
||||
public object User {
|
||||
public fun main() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import javaApi.Anon5
|
||||
|
||||
class A
|
||||
@Anon5(10)
|
||||
Anon5(10)
|
||||
constructor(private val a: Int, private val b: Int) {
|
||||
|
||||
deprecated("") // this constructor will not be replaced by default parameter value in primary because of this annotation
|
||||
@@ -9,8 +9,8 @@ constructor(private val a: Int, private val b: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
class B @Anon5(11)
|
||||
class B Anon5(11)
|
||||
constructor()
|
||||
|
||||
class C @Anon5(12)
|
||||
class C Anon5(12)
|
||||
private constructor()
|
||||
@@ -1 +1 @@
|
||||
class C @jvmOverloads constructor(private val string: String, a: Int = string.length())
|
||||
class C jvmOverloads constructor(private val string: String, a: Int = string.length())
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class A @jvmOverloads constructor(nested: A.Nested = A.Nested(A.Nested.FIELD)) {
|
||||
class A jvmOverloads constructor(nested: A.Nested = A.Nested(A.Nested.FIELD)) {
|
||||
|
||||
class Nested(p: Int) {
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// ERROR: Property must be initialized or be abstract
|
||||
import A.Nested
|
||||
|
||||
class A @jvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
|
||||
class A jvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
|
||||
|
||||
class Nested(p: Int) {
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package pack
|
||||
|
||||
import pack.A.Nested
|
||||
|
||||
class A @jvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
|
||||
class A jvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
|
||||
|
||||
class Nested(p: Int) {
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package pack
|
||||
|
||||
import pack.A.*
|
||||
|
||||
class A @jvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
|
||||
class A jvmOverloads constructor(nested: Nested = Nested(Nested.FIELD)) {
|
||||
|
||||
class Nested(p: Int) {
|
||||
companion object {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package pack
|
||||
|
||||
class C @jvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||
class C jvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||
|
||||
constructor(a: Int) : this(a, 0, 0, 0, 1) {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package pack
|
||||
|
||||
class C @jvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||
class C jvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||
|
||||
constructor(a1: Int, b1: Int, c1: Int) : this(a1, b1, c1, 0, 0) {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package pack
|
||||
|
||||
class C @jvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||
class C jvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||
|
||||
constructor(a: Int, b: Int, c: Int) : this(b, a, c, 0, 0) {
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package pack
|
||||
|
||||
class C @jvmOverloads constructor(a: Int = 1, b: Int = 2, c: Int = 3, d: Int = 4, e: Int = 5)
|
||||
class C jvmOverloads constructor(a: Int = 1, b: Int = 2, c: Int = 3, d: Int = 4, e: Int = 5)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package pack
|
||||
|
||||
class C @jvmOverloads constructor(a: Int = 1, b: Int = 2, c: Int = 3, d: Int = 4, e: Int = 5)
|
||||
class C jvmOverloads constructor(a: Int = 1, b: Int = 2, c: Int = 3, d: Int = 4, e: Int = 5)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ERROR: Overload resolution ambiguity: public constructor C(arg1: kotlin.Int, arg2: kotlin.Int) defined in C kotlin.jvm.jvmOverloads public constructor C(arg1: kotlin.Int, arg2: kotlin.Int = ..., arg3: kotlin.Int = ...) defined in C
|
||||
class C @jvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0) {
|
||||
class C jvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0) {
|
||||
private val field: Int
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class C @jvmOverloads private constructor(arg1: Int, arg2: Int, arg3: Int = 0) {
|
||||
class C jvmOverloads private constructor(arg1: Int, arg2: Int, arg3: Int = 0) {
|
||||
|
||||
public constructor(arg1: Int) : this(arg1, 0, 0) {
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
public class C @jvmOverloads constructor(c: C, public val x: Int = c.x)
|
||||
public class C jvmOverloads constructor(c: C, public val x: Int = c.x)
|
||||
|
||||
@@ -102,6 +102,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/jetbrainsNullable.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primaryConstructorAnnotation.java")
|
||||
public void testPrimaryConstructorAnnotation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/primaryConstructorAnnotation.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("j2k/testData/fileOrElement/anonymousBlock")
|
||||
|
||||
@@ -102,6 +102,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/jetbrainsNullable.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primaryConstructorAnnotation.java")
|
||||
public void testPrimaryConstructorAnnotation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/primaryConstructorAnnotation.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("j2k/testData/fileOrElement/anonymousBlock")
|
||||
|
||||
Reference in New Issue
Block a user