Prohibit @JvmField for private properties
This commit is contained in:
committed by
Michael Bogdanov
parent
f7164c5bfd
commit
d8be99a378
+3
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
@@ -36,6 +37,7 @@ class JvmFieldApplicabilityChecker : DeclarationChecker {
|
||||
enum class Problem(val errorMessage: String) {
|
||||
NOT_A_PROPERTY("JvmField can only be applied to a property"),
|
||||
NOT_FINAL("JvmField can only be applied to final property"),
|
||||
PRIVATE("JvmField has no effect on a private property"),
|
||||
CUSTOM_ACCESSOR("JvmField cannot be applied to a property with a custom accessor"),
|
||||
NO_BACKING_FIELD("JvmField can only be applied to a property with backing field"),
|
||||
OVERRIDES("JvmField cannot be applied to a property that overrides some other property"),
|
||||
@@ -56,6 +58,7 @@ class JvmFieldApplicabilityChecker : DeclarationChecker {
|
||||
val problem = when {
|
||||
descriptor !is PropertyDescriptor -> NOT_A_PROPERTY
|
||||
descriptor.modality.isOverridable -> NOT_FINAL
|
||||
Visibilities.isPrivate(descriptor.visibility) -> PRIVATE
|
||||
!descriptor.hasBackingField(bindingContext) -> NO_BACKING_FIELD
|
||||
descriptor.hasCustomAccessor() -> CUSTOM_ACCESSOR
|
||||
descriptor.overriddenDescriptors.isNotEmpty() -> OVERRIDES
|
||||
|
||||
Vendored
+7
-1
@@ -35,6 +35,9 @@ abstract class C : I{
|
||||
|
||||
<!INAPPLICABLE_JVM_FIELD!>@JvmField<!>
|
||||
final override val ai = 3
|
||||
|
||||
<!INAPPLICABLE_JVM_FIELD!>@JvmField<!>
|
||||
private val private = 3
|
||||
}
|
||||
|
||||
interface I {
|
||||
@@ -71,4 +74,7 @@ interface K {
|
||||
object O {
|
||||
@JvmField
|
||||
val c = 3
|
||||
}
|
||||
}
|
||||
|
||||
<!INAPPLICABLE_JVM_FIELD!>@JvmField<!>
|
||||
private val private = 3
|
||||
Vendored
+2
@@ -2,6 +2,7 @@ package
|
||||
|
||||
@kotlin.jvm.JvmField() public const val Const: kotlin.Int = 4
|
||||
@kotlin.jvm.JvmField() public var i: kotlin.Int
|
||||
@kotlin.jvm.JvmField() private val private: kotlin.Int = 3
|
||||
@kotlin.jvm.JvmField() public fun foo(): kotlin.Unit
|
||||
|
||||
@kotlin.jvm.JvmField() public abstract class C : I {
|
||||
@@ -14,6 +15,7 @@ package
|
||||
@kotlin.jvm.JvmField() public final val customGetter: kotlin.String = ""
|
||||
@kotlin.jvm.JvmField() public final var customSetter: kotlin.String
|
||||
@kotlin.jvm.JvmField() public final val noBackingField: kotlin.String
|
||||
@kotlin.jvm.JvmField() private final val private: kotlin.Int = 3
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@kotlin.jvm.JvmField() private final fun foo(/*0*/ s: kotlin.String = ...): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
|
||||
Reference in New Issue
Block a user