Allow to use @JvmStatic in interface companion object
This commit is contained in:
+40
-10
@@ -17,6 +17,9 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
@@ -51,7 +54,12 @@ class LocalFunInlineChecker : SimpleDeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class PlatformStaticAnnotationChecker : SimpleDeclarationChecker {
|
||||
class JvmStaticChecker(jvmTarget: JvmTarget, languageVersionSettings: LanguageVersionSettings) : SimpleDeclarationChecker {
|
||||
|
||||
private val isLessJVM18 = jvmTarget.bytecodeVersion < JvmTarget.JVM_1_8.bytecodeVersion
|
||||
|
||||
private val supportJvmStaticInInterface = languageVersionSettings.supportsFeature(LanguageFeature.JvmStaticInInterface)
|
||||
|
||||
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
@@ -75,13 +83,24 @@ class PlatformStaticAnnotationChecker : SimpleDeclarationChecker {
|
||||
diagnosticHolder: DiagnosticSink
|
||||
) {
|
||||
val container = descriptor.containingDeclaration
|
||||
val insideObject = container != null && DescriptorUtils.isNonCompanionObject(container)
|
||||
val insideCompanionObjectInClass =
|
||||
container != null && DescriptorUtils.isCompanionObject(container) &&
|
||||
DescriptorUtils.isClassOrEnumClass(container.containingDeclaration)
|
||||
val insideObject = DescriptorUtils.isObject(container)
|
||||
val insideCompanionObjectInInterface = DescriptorUtils.isCompanionObject(container) &&
|
||||
DescriptorUtils.isInterface(container!!.containingDeclaration)
|
||||
|
||||
if (!insideObject && !insideCompanionObjectInClass) {
|
||||
diagnosticHolder.report(ErrorsJvm.JVM_STATIC_NOT_IN_OBJECT.on(declaration))
|
||||
if (!insideObject || insideCompanionObjectInInterface) {
|
||||
if (insideCompanionObjectInInterface &&
|
||||
supportJvmStaticInInterface &&
|
||||
descriptor is DeclarationDescriptorWithVisibility) {
|
||||
checkVisibility(descriptor, diagnosticHolder, declaration)
|
||||
if (isLessJVM18) {
|
||||
diagnosticHolder.report(ErrorsJvm.JVM_STATIC_IN_INTERFACE_1_6.on(declaration))
|
||||
}
|
||||
} else {
|
||||
diagnosticHolder.report(
|
||||
(if (supportJvmStaticInInterface) ErrorsJvm.JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION
|
||||
else ErrorsJvm.JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION).on(declaration)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val checkDeclaration = when (declaration) {
|
||||
@@ -89,7 +108,7 @@ class PlatformStaticAnnotationChecker : SimpleDeclarationChecker {
|
||||
else -> declaration
|
||||
}
|
||||
|
||||
if (insideObject && checkDeclaration.modifierList?.hasModifier(KtTokens.OVERRIDE_KEYWORD) == true) {
|
||||
if (DescriptorUtils.isNonCompanionObject(container) && checkDeclaration.modifierList?.hasModifier(KtTokens.OVERRIDE_KEYWORD) == true) {
|
||||
diagnosticHolder.report(ErrorsJvm.OVERRIDE_CANNOT_BE_STATIC.on(declaration))
|
||||
}
|
||||
|
||||
@@ -97,6 +116,18 @@ class PlatformStaticAnnotationChecker : SimpleDeclarationChecker {
|
||||
diagnosticHolder.report(ErrorsJvm.JVM_STATIC_ON_CONST_OR_JVM_FIELD.on(declaration))
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkVisibility(
|
||||
descriptor: DeclarationDescriptorWithVisibility,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
declaration: KtDeclaration
|
||||
) {
|
||||
if (descriptor.visibility != Visibilities.PUBLIC) {
|
||||
diagnosticHolder.report(ErrorsJvm.JVM_STATIC_ON_NON_PUBLIC_MEMBER.on(declaration))
|
||||
} else if (descriptor is PropertyDescriptor) {
|
||||
descriptor.setter?.let { checkVisibility(it, diagnosticHolder, declaration) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JvmNameAnnotationChecker : SimpleDeclarationChecker {
|
||||
@@ -129,8 +160,7 @@ class JvmNameAnnotationChecker : SimpleDeclarationChecker {
|
||||
}
|
||||
|
||||
if (descriptor is CallableMemberDescriptor) {
|
||||
val callableMemberDescriptor = descriptor
|
||||
if (DescriptorUtils.isOverride(callableMemberDescriptor) || callableMemberDescriptor.isOverridable) {
|
||||
if (DescriptorUtils.isOverride(descriptor) || descriptor.isOverridable) {
|
||||
diagnosticHolder.report(ErrorsJvm.INAPPLICABLE_JVM_NAME.on(annotationEntry))
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -50,7 +50,10 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
MAP.put(ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
|
||||
MAP.put(CONFLICTING_INHERITED_JVM_DECLARATIONS, "Inherited platform declarations clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA);
|
||||
|
||||
MAP.put(JVM_STATIC_NOT_IN_OBJECT, "Only functions in named objects and companion objects of classes can be annotated with '@JvmStatic'");
|
||||
MAP.put(JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION, "Only members in named objects and companion objects of classes can be annotated with '@JvmStatic'");
|
||||
MAP.put(JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION, "Only members in named objects and companion objects can be annotated with '@JvmStatic'");
|
||||
MAP.put(JVM_STATIC_ON_NON_PUBLIC_MEMBER, "Only public members in interface companion objects can be annotated with '@JvmStatic'");
|
||||
MAP.put(JVM_STATIC_IN_INTERFACE_1_6, "'@JvmStatic' annotation in interface supported only with JVM target 1.8 and above. Recompile with '-jvm-target 1.8'\"");
|
||||
MAP.put(JVM_STATIC_ON_CONST_OR_JVM_FIELD, "'@JvmStatic' annotation is useless for const or '@JvmField' properties");
|
||||
MAP.put(OVERRIDE_CANNOT_BE_STATIC, "Override member cannot be '@JvmStatic' in object");
|
||||
MAP.put(OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS, "'@JvmOverloads' annotation has no effect for methods without default arguments");
|
||||
|
||||
+4
-1
@@ -41,7 +41,10 @@ public interface ErrorsJvm {
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
|
||||
DiagnosticFactory0<KtDeclaration> OVERRIDE_CANNOT_BE_STATIC = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_STATIC_NOT_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_STATIC_ON_NON_PUBLIC_MEMBER = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_STATIC_IN_INTERFACE_1_6 = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtDeclaration> JVM_STATIC_ON_CONST_OR_JVM_FIELD = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_JVM_NAME = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
+1
-1
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.types.DynamicTypesSettings
|
||||
object JvmPlatformConfigurator : PlatformConfigurator(
|
||||
DynamicTypesSettings(),
|
||||
additionalDeclarationCheckers = listOf(
|
||||
PlatformStaticAnnotationChecker(),
|
||||
JvmNameAnnotationChecker(),
|
||||
VolatileAnnotationChecker(),
|
||||
SynchronizedAnnotationChecker(),
|
||||
@@ -87,6 +86,7 @@ object JvmPlatformConfigurator : PlatformConfigurator(
|
||||
declarationReturnTypeSanitizer = JvmDeclarationReturnTypeSanitizer
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useImpl<JvmStaticChecker>()
|
||||
container.useImpl<JvmReflectionAPICallChecker>()
|
||||
container.useImpl<JavaSyntheticScopes>()
|
||||
container.useImpl<SamConversionResolverImpl>()
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
class A(<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic val z: Int<!>) {
|
||||
class A(<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic val z: Int<!>) {
|
||||
|
||||
}
|
||||
+5
-5
@@ -14,20 +14,20 @@ class A {
|
||||
|
||||
fun test() {
|
||||
val s = object {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic fun a3()<!> {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a3()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic fun a4()<!> {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a4()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface B {
|
||||
companion object {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic fun a1()<!> {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a1()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -40,13 +40,13 @@ interface B {
|
||||
|
||||
fun test() {
|
||||
val s = object {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic fun a3()<!> {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a3()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic fun a4()<!> {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a4()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !LANGUAGE: +JvmStaticInInterface
|
||||
class A {
|
||||
companion object {
|
||||
@JvmStatic fun a1() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
object A {
|
||||
@JvmStatic fun a2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val s = object {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION!>@JvmStatic fun a3()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION!>@JvmStatic fun a4()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface B {
|
||||
companion object {
|
||||
<!JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic fun a1()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
object A {
|
||||
@JvmStatic fun a2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val s = object {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION!>@JvmStatic fun a3()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_COMPANION!>@JvmStatic fun a4()<!> {
|
||||
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
@kotlin.jvm.JvmStatic public final fun a4(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public object A {
|
||||
private constructor A()
|
||||
@kotlin.jvm.JvmStatic public final fun a2(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
@kotlin.jvm.JvmStatic public final fun a1(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
|
||||
public interface B {
|
||||
@kotlin.jvm.JvmStatic public open fun a4(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public object A {
|
||||
private constructor A()
|
||||
@kotlin.jvm.JvmStatic public final fun a2(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
@kotlin.jvm.JvmStatic public final fun a1(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
package
|
||||
|
||||
public interface B {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
@kotlin.jvm.JvmStatic public final var foo: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo1: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo2: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic private final var foo3: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo4: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo5: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final fun a1(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic internal final fun a4(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic private final fun a4(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic protected final fun a4(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
interface B {
|
||||
companion object {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a1()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic private fun a2()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic protected fun a3()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic internal fun a4()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
var foo<!> = 1
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
var foo1<!> = 1
|
||||
protected set
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
var foo2<!> = 1
|
||||
private set
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
private var foo3<!> = 1
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
protected var foo4<!> = 1
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
protected var foo5<!> = 1
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic
|
||||
val foo6<!> = 1
|
||||
|
||||
val foo7 = 1
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic get<!>
|
||||
|
||||
private var foo8 = 1
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic <!SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY!>public<!> set<!>
|
||||
|
||||
public var foo9 = 1
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic private set<!>
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public interface B {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
@kotlin.jvm.JvmStatic public final var foo: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo1: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo2: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic private final var foo3: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo4: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo5: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final val foo6: kotlin.Int = 1
|
||||
public final val foo7: kotlin.Int = 1
|
||||
private final var foo8: kotlin.Int
|
||||
public final var foo9: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final fun a1(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic private final fun a2(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic protected final fun a3(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic internal final fun a4(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !LANGUAGE: +JvmStaticInInterface
|
||||
interface B {
|
||||
companion object {
|
||||
<!JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic fun a1()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic private fun a2()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic protected fun a3()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic internal fun a4()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
var foo<!> = 1
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
var foo1<!> = 1
|
||||
protected set
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
var foo2<!> = 1
|
||||
private set
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
private var foo3<!> = 1
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
protected var foo4<!> = 1
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
protected var foo5<!> = 1
|
||||
|
||||
<!JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic
|
||||
val foo6<!> = 1
|
||||
|
||||
val foo7 = 1
|
||||
<!JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic get<!>
|
||||
|
||||
private var foo8 = 1
|
||||
<!JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic <!SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY!>public<!> set<!>
|
||||
|
||||
public var foo9 = 1
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER, JVM_STATIC_IN_INTERFACE_1_6!>@JvmStatic private set<!>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public interface B {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
@kotlin.jvm.JvmStatic public final var foo: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo1: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo2: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic private final var foo3: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo4: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo5: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final val foo6: kotlin.Int = 1
|
||||
public final val foo7: kotlin.Int = 1
|
||||
private final var foo8: kotlin.Int
|
||||
public final var foo9: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final fun a1(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic private final fun a2(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic protected final fun a3(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic internal final fun a4(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// !LANGUAGE: +JvmStaticInInterface
|
||||
// !JVM_TARGET: 1.8
|
||||
interface B {
|
||||
companion object {
|
||||
@JvmStatic fun a1() {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic private fun a2()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic protected fun a3()<!> {
|
||||
|
||||
}
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic internal fun a4()<!> {
|
||||
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
var foo = 1
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic
|
||||
var foo1<!> = 1
|
||||
protected set
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic
|
||||
var foo2<!> = 1
|
||||
private set
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic
|
||||
private var foo3<!> = 1
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic
|
||||
protected var foo4<!> = 1
|
||||
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic
|
||||
protected var foo5<!> = 1
|
||||
|
||||
@JvmStatic
|
||||
val foo6 = 1
|
||||
|
||||
val foo7 = 1
|
||||
@JvmStatic get
|
||||
|
||||
private var foo8 = 1
|
||||
@JvmStatic <!SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY!>public<!> set
|
||||
|
||||
public var foo9 = 1
|
||||
<!JVM_STATIC_ON_NON_PUBLIC_MEMBER!>@JvmStatic private set<!>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public interface B {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
@kotlin.jvm.JvmStatic public final var foo: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo1: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final var foo2: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic private final var foo3: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo4: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic protected final var foo5: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final val foo6: kotlin.Int = 1
|
||||
public final val foo7: kotlin.Int = 1
|
||||
private final var foo8: kotlin.Int
|
||||
public final var foo9: kotlin.Int
|
||||
@kotlin.jvm.JvmStatic public final fun a1(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic private final fun a2(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic protected final fun a3(): kotlin.Unit
|
||||
@kotlin.jvm.JvmStatic internal final fun a4(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
fun main(args: Array<String>) {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic fun a()<!>{
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic fun a()<!>{
|
||||
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -36,9 +36,9 @@ class A {
|
||||
}
|
||||
|
||||
var p:Int = 1
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic set(p1: Int)<!> {
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic set(p1: Int)<!> {
|
||||
p = 1
|
||||
}
|
||||
|
||||
<!JVM_STATIC_NOT_IN_OBJECT!>@JvmStatic val z2<!> = 1;
|
||||
<!JVM_STATIC_NOT_IN_OBJECT_OR_CLASS_COMPANION!>@JvmStatic val z2<!> = 1;
|
||||
}
|
||||
+24
@@ -596,6 +596,30 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functions_LL13.kt")
|
||||
public void testFunctions_LL13() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions_LL13.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceCompanion_LL12.kt")
|
||||
public void testInterfaceCompanion_LL12() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceCompanion_LL13_16.kt")
|
||||
public void testInterfaceCompanion_LL13_16() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceCompanion_LL13_18.kt")
|
||||
public void testInterfaceCompanion_LL13_18() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localFun.kt")
|
||||
public void testLocalFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun.kt");
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+24
@@ -596,6 +596,30 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functions_LL13.kt")
|
||||
public void testFunctions_LL13() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/functions_LL13.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceCompanion_LL12.kt")
|
||||
public void testInterfaceCompanion_LL12() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL12.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceCompanion_LL13_16.kt")
|
||||
public void testInterfaceCompanion_LL13_16() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_16.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("interfaceCompanion_LL13_18.kt")
|
||||
public void testInterfaceCompanion_LL13_18() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/interfaceCompanion_LL13_18.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localFun.kt")
|
||||
public void testLocalFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic/localFun.kt");
|
||||
|
||||
@@ -75,6 +75,7 @@ enum class LanguageFeature(
|
||||
ProperVisibilityForCompanionObjectInstanceField(KOTLIN_1_3),
|
||||
ProperForInArrayLoopRangeVariableAssignmentSemantic(KOTLIN_1_3),
|
||||
NestedClassesInAnnotations(KOTLIN_1_3),
|
||||
JvmStaticInInterface(KOTLIN_1_3),
|
||||
|
||||
StrictJavaNullabilityAssertions(sinceVersion = null, defaultState = State.DISABLED),
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ public class DescriptorUtils {
|
||||
descriptor.getName().equals(SpecialNames.ANONYMOUS_FUNCTION);
|
||||
}
|
||||
|
||||
public static boolean isNonCompanionObject(@NotNull DeclarationDescriptor descriptor) {
|
||||
public static boolean isNonCompanionObject(@Nullable DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.OBJECT) && !((ClassDescriptor) descriptor).isCompanionObject();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user