#KT-13750 fix (#951)
This commit is contained in:
committed by
Dmitry Jemerov
parent
19ef29e96c
commit
115d63a2f3
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.j2k
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.CommonClassNames.*
|
import com.intellij.psi.CommonClassNames.*
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.util.InheritanceUtil
|
import com.intellij.psi.util.InheritanceUtil
|
||||||
import com.intellij.psi.util.PsiMethodUtil
|
import com.intellij.psi.util.PsiMethodUtil
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
@@ -141,7 +142,7 @@ class Converter private constructor(
|
|||||||
commonState.postUnfoldActions.forEach { it() }
|
commonState.postUnfoldActions.forEach { it() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun<TResult : Element> deferredElement(generator: (CodeConverter) -> TResult): DeferredElement<TResult> {
|
fun <TResult : Element> deferredElement(generator: (CodeConverter) -> TResult): DeferredElement<TResult> {
|
||||||
val element = DeferredElement(generator, personalState)
|
val element = DeferredElement(generator, personalState)
|
||||||
commonState.deferredElements.add(element)
|
commonState.deferredElements.add(element)
|
||||||
return element
|
return element
|
||||||
@@ -309,7 +310,7 @@ class Converter private constructor(
|
|||||||
val setMethod = propertyInfo.setMethod
|
val setMethod = propertyInfo.setMethod
|
||||||
|
|
||||||
//TODO: annotations from getter/setter?
|
//TODO: annotations from getter/setter?
|
||||||
val annotations = field?.let { convertAnnotations(it) } ?: Annotations.Empty
|
val annotations = field?.let { convertAnnotations(it) + specialAnnotationPropertyCases(it) } ?: Annotations.Empty
|
||||||
|
|
||||||
val modifiers = propertyInfo.modifiers
|
val modifiers = propertyInfo.modifiers
|
||||||
|
|
||||||
@@ -424,6 +425,24 @@ class Converter private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun specialAnnotationPropertyCases(field: PsiField): Annotations {
|
||||||
|
val javaSerializableInterface = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_IO_SERIALIZABLE, field.resolveScope)
|
||||||
|
val output = mutableListOf<Annotation>()
|
||||||
|
if (javaSerializableInterface != null &&
|
||||||
|
field.name == "serialVersionUID" &&
|
||||||
|
field.hasModifierProperty(PsiModifier.FINAL) &&
|
||||||
|
field.hasModifierProperty(PsiModifier.STATIC) &&
|
||||||
|
field.containingClass?.isInheritor(javaSerializableInterface, false) ?: false
|
||||||
|
) {
|
||||||
|
output.add(Annotation(Identifier.withNoPrototype("JvmStatic"),
|
||||||
|
listOf(),
|
||||||
|
newLineAfter = false).assignNoPrototype())
|
||||||
|
}
|
||||||
|
|
||||||
|
return Annotations(output)
|
||||||
|
}
|
||||||
|
|
||||||
private fun combinedNullability(vararg psiElements: PsiElement?): Nullability {
|
private fun combinedNullability(vararg psiElements: PsiElement?): Nullability {
|
||||||
val values = psiElements.filterNotNull().map {
|
val values = psiElements.filterNotNull().map {
|
||||||
when (it) {
|
when (it) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Bar implements Serializable {
|
||||||
|
private static final long serialVersionUID = 0;
|
||||||
|
int foobar = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Foo {
|
||||||
|
private static final long serialVersionUID = 0;
|
||||||
|
int foobar = 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
class Bar : Serializable {
|
||||||
|
internal var foobar = 0
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic private val serialVersionUID: Long = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
internal var foobar = 0
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val serialVersionUID: Long = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -11,6 +11,6 @@ class Language(protected var code: String) : Serializable {
|
|||||||
companion object {
|
companion object {
|
||||||
var ENGLISH = Language("en")
|
var ENGLISH = Language("en")
|
||||||
var SWEDISH = Language("sv")
|
var SWEDISH = Language("sv")
|
||||||
private val serialVersionUID = -2442762969929206780L
|
@JvmStatic private val serialVersionUID = -2442762969929206780L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,6 +120,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/primaryConstructorAnnotation.java");
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/primaryConstructorAnnotation.java");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("serialVersionUID.java")
|
||||||
|
public void testSerialVersionUID() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/serialVersionUID.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("j2k/testData/fileOrElement/anonymousBlock")
|
@TestMetadata("j2k/testData/fileOrElement/anonymousBlock")
|
||||||
|
|||||||
@@ -120,6 +120,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/primaryConstructorAnnotation.java");
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/primaryConstructorAnnotation.java");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("serialVersionUID.java")
|
||||||
|
public void testSerialVersionUID() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/annotations/serialVersionUID.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("j2k/testData/fileOrElement/anonymousBlock")
|
@TestMetadata("j2k/testData/fileOrElement/anonymousBlock")
|
||||||
|
|||||||
Reference in New Issue
Block a user