KT-18232: Kotlin code converter misses annotations
#KT-18232 Fixed
This commit is contained in:
committed by
Simon Ogorodnik
parent
4092d754c6
commit
be664e26f7
@@ -111,8 +111,9 @@ class AnnotationConverter(private val converter: Converter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun effectiveAnnotationUseTarget(name: String, target: AnnotationUseTarget?): AnnotationUseTarget? =
|
private fun effectiveAnnotationUseTarget(name: String, target: AnnotationUseTarget?): AnnotationUseTarget? =
|
||||||
when (name) {
|
when {
|
||||||
"Deprecated" -> if (target == AnnotationUseTarget.Param) null else target
|
name == "Deprecated" &&
|
||||||
|
(target == AnnotationUseTarget.Param || target == AnnotationUseTarget.Field) -> null
|
||||||
else -> target
|
else -> target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -196,16 +196,26 @@ class ConstructorConverter(
|
|||||||
else {
|
else {
|
||||||
val (field, type) = parameterToField[parameter]!!
|
val (field, type) = parameterToField[parameter]!!
|
||||||
val propertyInfo = fieldToPropertyInfo(field)
|
val propertyInfo = fieldToPropertyInfo(field)
|
||||||
FunctionParameter(propertyInfo.identifier,
|
|
||||||
type,
|
var paramAnnotations = converter.convertAnnotations(parameter, AnnotationUseTarget.Param) +
|
||||||
if (propertyInfo.isVar) FunctionParameter.VarValModifier.Var else FunctionParameter.VarValModifier.Val,
|
converter.convertAnnotations(field, AnnotationUseTarget.Field)
|
||||||
converter.convertAnnotations(parameter, AnnotationUseTarget.Param) + converter.convertAnnotations(field),
|
if (propertyInfo.getMethod != null) {
|
||||||
propertyInfo.modifiers,
|
paramAnnotations += converter.convertAnnotations(propertyInfo.getMethod, AnnotationUseTarget.Get)
|
||||||
default)
|
}
|
||||||
.assignPrototypes(
|
if (propertyInfo.setMethod != null) {
|
||||||
PrototypeInfo(parameter, CommentsAndSpacesInheritance.LINE_BREAKS),
|
paramAnnotations += converter.convertAnnotations(propertyInfo.setMethod, AnnotationUseTarget.Set)
|
||||||
PrototypeInfo(field, CommentsAndSpacesInheritance.NO_SPACES)
|
}
|
||||||
)
|
FunctionParameter(
|
||||||
|
propertyInfo.identifier,
|
||||||
|
type,
|
||||||
|
if (propertyInfo.isVar) FunctionParameter.VarValModifier.Var else FunctionParameter.VarValModifier.Val,
|
||||||
|
paramAnnotations,
|
||||||
|
propertyInfo.modifiers,
|
||||||
|
default
|
||||||
|
).assignPrototypes(
|
||||||
|
PrototypeInfo(parameter, CommentsAndSpacesInheritance.LINE_BREAKS),
|
||||||
|
PrototypeInfo(field, CommentsAndSpacesInheritance.NO_SPACES)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
correctCodeConverter = { correct() })
|
correctCodeConverter = { correct() })
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.j2k.append
|
|||||||
import org.jetbrains.kotlin.j2k.buildList
|
import org.jetbrains.kotlin.j2k.buildList
|
||||||
|
|
||||||
enum class AnnotationUseTarget(val id: String) {
|
enum class AnnotationUseTarget(val id: String) {
|
||||||
File("file"), Param("param"), Get("get"), Set("set")
|
File("file"), Param("param"), Get("get"), Set("set"), Field("field")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Annotation(val name: Identifier,
|
class Annotation(val name: Identifier,
|
||||||
|
|||||||
+1
-1
@@ -2,5 +2,5 @@ internal annotation class A
|
|||||||
|
|
||||||
internal annotation class B
|
internal annotation class B
|
||||||
|
|
||||||
class U(@param:A @B
|
class U(@param:A @field:B
|
||||||
var i: Int)
|
var i: Int)
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
@interface TestAnnotation {
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
@TestAnnotation
|
||||||
|
private String arg;
|
||||||
|
|
||||||
|
public Test(@TestAnnotation String arg) {
|
||||||
|
this.arg = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestAnnotation
|
||||||
|
public String getArg() {
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestAnnotation
|
||||||
|
public void setArg(String arg) {
|
||||||
|
this.arg = arg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
internal annotation class TestAnnotation
|
||||||
|
|
||||||
|
class Test(@param:TestAnnotation @field:TestAnnotation
|
||||||
|
@get:TestAnnotation
|
||||||
|
@set:TestAnnotation
|
||||||
|
var arg: String?)
|
||||||
@@ -1508,6 +1508,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DataClassWithAnnotations.java")
|
||||||
|
public void testDataClassWithAnnotations() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithAnnotations.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("DataClassWithMutableField.java")
|
@TestMetadata("DataClassWithMutableField.java")
|
||||||
public void testDataClassWithMutableField() throws Exception {
|
public void testDataClassWithMutableField() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithMutableField.java");
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithMutableField.java");
|
||||||
|
|||||||
@@ -1508,6 +1508,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DataClassWithAnnotations.java")
|
||||||
|
public void testDataClassWithAnnotations() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithAnnotations.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("DataClassWithMutableField.java")
|
@TestMetadata("DataClassWithMutableField.java")
|
||||||
public void testDataClassWithMutableField() throws Exception {
|
public void testDataClassWithMutableField() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithMutableField.java");
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithMutableField.java");
|
||||||
|
|||||||
Reference in New Issue
Block a user