Fix KT-13750, J2K const val serialVersionUID
This commit is contained in:
@@ -309,9 +309,9 @@ 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) + specialAnnotationPropertyCases(it) } ?: Annotations.Empty
|
val annotations = field?.let { convertAnnotations(it) } ?: Annotations.Empty
|
||||||
|
|
||||||
val modifiers = propertyInfo.modifiers
|
val modifiers = propertyInfo.modifiers + (field?.let{ specialModifiersCase(field) } ?: Modifiers.Empty)
|
||||||
|
|
||||||
val name = propertyInfo.identifier
|
val name = propertyInfo.identifier
|
||||||
if (field is PsiEnumConstant) {
|
if (field is PsiEnumConstant) {
|
||||||
@@ -432,21 +432,19 @@ class Converter private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun specialAnnotationPropertyCases(field: PsiField): Annotations {
|
private fun specialModifiersCase(field: PsiField): Modifiers {
|
||||||
val javaSerializableInterface = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_IO_SERIALIZABLE, field.resolveScope)
|
val javaSerializableInterface = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_IO_SERIALIZABLE, field.resolveScope)
|
||||||
val output = mutableListOf<Annotation>()
|
val output = mutableListOf<Modifier>()
|
||||||
if (javaSerializableInterface != null &&
|
if (javaSerializableInterface != null &&
|
||||||
field.name == "serialVersionUID" &&
|
field.name == "serialVersionUID" &&
|
||||||
field.hasModifierProperty(PsiModifier.FINAL) &&
|
field.hasModifierProperty(PsiModifier.FINAL) &&
|
||||||
field.hasModifierProperty(PsiModifier.STATIC) &&
|
field.hasModifierProperty(PsiModifier.STATIC) &&
|
||||||
field.containingClass?.isInheritor(javaSerializableInterface, false) ?: false
|
field.containingClass?.isInheritor(javaSerializableInterface, false) ?: false
|
||||||
) {
|
) {
|
||||||
output.add(Annotation(Identifier.withNoPrototype("JvmStatic"),
|
output.add(Modifier.CONST)
|
||||||
listOf(),
|
|
||||||
newLineAfter = false).assignNoPrototype())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Annotations(output)
|
return Modifiers(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun combinedNullability(vararg psiElements: PsiElement?): Nullability {
|
private fun combinedNullability(vararg psiElements: PsiElement?): Nullability {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ enum class Modifier(private val str: String) {
|
|||||||
OPEN("open"),
|
OPEN("open"),
|
||||||
OVERRIDE("override"),
|
OVERRIDE("override"),
|
||||||
EXTERNAL("external"),
|
EXTERNAL("external"),
|
||||||
|
CONST("const"),
|
||||||
INNER("inner");
|
INNER("inner");
|
||||||
|
|
||||||
fun toKotlin(): String = str
|
fun toKotlin(): String = str
|
||||||
@@ -66,6 +67,10 @@ class Modifiers(modifiers: Collection<Modifier>) : Element() {
|
|||||||
|
|
||||||
fun accessModifier(): Modifier? = modifiers.firstOrNull { it in ACCESS_MODIFIERS }
|
fun accessModifier(): Modifier? = modifiers.firstOrNull { it in ACCESS_MODIFIERS }
|
||||||
|
|
||||||
|
operator fun plus(other: Modifiers): Modifiers {
|
||||||
|
return Modifiers(this.modifiers + other.modifiers).assignNoPrototype()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val Empty = Modifiers(listOf())
|
val Empty = Modifiers(listOf())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class Bar : Serializable {
|
|||||||
internal var foobar = 0
|
internal var foobar = 0
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic private val serialVersionUID: Long = 0
|
private const val serialVersionUID: Long = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user