J2K: supported synchronized, volatile, transient and strictfp
#KT-3678 Fixed
This commit is contained in:
@@ -503,7 +503,10 @@ public class Converter private(val project: Project, val settings: ConverterSett
|
||||
PsiModifier.PRIVATE to Modifier.PRIVATE
|
||||
)
|
||||
|
||||
fun convertAnnotations(owner: PsiModifierListOwner): Annotations {
|
||||
fun convertAnnotations(owner: PsiModifierListOwner): Annotations
|
||||
= (convertAnnotationsOnly(owner) + convertModifiersToAnnotations(owner)).assignNoPrototype()
|
||||
|
||||
private fun convertAnnotationsOnly(owner: PsiModifierListOwner): Annotations {
|
||||
val modifierList = owner.getModifierList()
|
||||
val annotations = modifierList?.getAnnotations()?.filter { it.getQualifiedName() !in ANNOTATIONS_TO_REMOVE }
|
||||
if (annotations == null || annotations.isEmpty()) return Annotations.Empty
|
||||
@@ -526,6 +529,20 @@ public class Converter private(val project: Project, val settings: ConverterSett
|
||||
return Annotations(list, newLines).assignNoPrototype()
|
||||
}
|
||||
|
||||
private fun convertModifiersToAnnotations(owner: PsiModifierListOwner): Annotations {
|
||||
val list = MODIFIER_TO_ANNOTATION
|
||||
.filter { owner.hasModifierProperty(it.first) }
|
||||
.map { Annotation(Identifier(it.second).assignNoPrototype(), listOf(), false).assignNoPrototype() }
|
||||
return Annotations(list, false).assignNoPrototype()
|
||||
}
|
||||
|
||||
private val MODIFIER_TO_ANNOTATION = listOf(
|
||||
PsiModifier.SYNCHRONIZED to "synchronized",
|
||||
PsiModifier.VOLATILE to "volatile",
|
||||
PsiModifier.STRICTFP to "strictfp",
|
||||
PsiModifier.TRANSIENT to "transient"
|
||||
)
|
||||
|
||||
private fun convertAnnotation(annotation: PsiAnnotation, brackets: Boolean): Annotation? {
|
||||
val qualifiedName = annotation.getQualifiedName()
|
||||
if (qualifiedName == CommonClassNames.JAVA_LANG_DEPRECATED && annotation.getParameterList().getAttributes().isEmpty()) {
|
||||
|
||||
@@ -1219,6 +1219,11 @@ public class JavaToKotlinConverterTestGenerated extends AbstractJavaToKotlinConv
|
||||
doTest("j2k/tests/testData/ast/field/varWithoutInit.java");
|
||||
}
|
||||
|
||||
@TestMetadata("volatileTransientAndStrictFp.java")
|
||||
public void testVolatileTransientAndStrictFp() throws Exception {
|
||||
doTest("j2k/tests/testData/ast/field/volatileTransientAndStrictFp.java");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("j2k/tests/testData/ast/for")
|
||||
@@ -1516,6 +1521,11 @@ public class JavaToKotlinConverterTestGenerated extends AbstractJavaToKotlinConv
|
||||
doTest("j2k/tests/testData/ast/function/public.java");
|
||||
}
|
||||
|
||||
@TestMetadata("synchronizedMethod.java")
|
||||
public void testSynchronizedMethod() throws Exception {
|
||||
doTest("j2k/tests/testData/ast/function/synchronizedMethod.java");
|
||||
}
|
||||
|
||||
@TestMetadata("throws.java")
|
||||
public void testThrows() throws Exception {
|
||||
doTest("j2k/tests/testData/ast/function/throws.java");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
@Deprecated
|
||||
volatile int field1 = 0;
|
||||
|
||||
transient int field2 = 1;
|
||||
|
||||
strictfp double field3 = 2;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
deprecated("")
|
||||
volatile
|
||||
var field1 = 0
|
||||
|
||||
transient var field2 = 1
|
||||
|
||||
strictfp var field3: Double = 2
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
synchronized void foo() {
|
||||
bar();
|
||||
}
|
||||
|
||||
void bar() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
synchronized fun foo() {
|
||||
bar()
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user