KT-18232: Kotlin code converter misses annotations

#KT-18232 Fixed
This commit is contained in:
Toshiaki Kameyama
2017-08-11 22:36:11 +09:00
committed by Simon Ogorodnik
parent 4092d754c6
commit be664e26f7
8 changed files with 64 additions and 14 deletions
@@ -111,8 +111,9 @@ class AnnotationConverter(private val converter: Converter) {
}
private fun effectiveAnnotationUseTarget(name: String, target: AnnotationUseTarget?): AnnotationUseTarget? =
when (name) {
"Deprecated" -> if (target == AnnotationUseTarget.Param) null else target
when {
name == "Deprecated" &&
(target == AnnotationUseTarget.Param || target == AnnotationUseTarget.Field) -> null
else -> target
}
@@ -196,16 +196,26 @@ class ConstructorConverter(
else {
val (field, type) = parameterToField[parameter]!!
val propertyInfo = fieldToPropertyInfo(field)
FunctionParameter(propertyInfo.identifier,
type,
if (propertyInfo.isVar) FunctionParameter.VarValModifier.Var else FunctionParameter.VarValModifier.Val,
converter.convertAnnotations(parameter, AnnotationUseTarget.Param) + converter.convertAnnotations(field),
propertyInfo.modifiers,
default)
.assignPrototypes(
PrototypeInfo(parameter, CommentsAndSpacesInheritance.LINE_BREAKS),
PrototypeInfo(field, CommentsAndSpacesInheritance.NO_SPACES)
)
var paramAnnotations = converter.convertAnnotations(parameter, AnnotationUseTarget.Param) +
converter.convertAnnotations(field, AnnotationUseTarget.Field)
if (propertyInfo.getMethod != null) {
paramAnnotations += converter.convertAnnotations(propertyInfo.getMethod, AnnotationUseTarget.Get)
}
if (propertyInfo.setMethod != null) {
paramAnnotations += converter.convertAnnotations(propertyInfo.setMethod, AnnotationUseTarget.Set)
}
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() })
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.j2k.append
import org.jetbrains.kotlin.j2k.buildList
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,
@@ -2,5 +2,5 @@ internal annotation class A
internal annotation class B
class U(@param:A @B
class U(@param:A @field:B
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);
}
@TestMetadata("DataClassWithAnnotations.java")
public void testDataClassWithAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithAnnotations.java");
doTest(fileName);
}
@TestMetadata("DataClassWithMutableField.java")
public void testDataClassWithMutableField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithMutableField.java");
@@ -1508,6 +1508,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
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")
public void testDataClassWithMutableField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/detectProperties/DataClassWithMutableField.java");