FE 1.0: introduce deprecation for Enum.declaringClass (KT-49653)

This commit is contained in:
Mikhail Glukhikh
2022-01-25 18:40:36 +03:00
committed by TeamCityServer
parent 983fa4c8c7
commit fd3d86eddf
7 changed files with 37 additions and 1 deletions
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.jvm.checkers
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
object EnumDeclaringClassDeprecationChecker : CallChecker {
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
val resultingDescriptor = resolvedCall.resultingDescriptor
if (resultingDescriptor !is PropertyDescriptor || resultingDescriptor.kind != CallableMemberDescriptor.Kind.SYNTHESIZED) return
val extensionReceiver = resultingDescriptor.extensionReceiverParameter?.value as? ExtensionReceiver ?: return
if (resultingDescriptor.name.asString() != "declaringClass") return
if (extensionReceiver.type.constructor.declarationDescriptor.classId != StandardClassIds.Enum) return
context.trace.report(ErrorsJvm.ENUM_DECLARING_CLASS_DEPRECATED.on(context.languageVersionSettings, reportOn))
}
}
@@ -228,6 +228,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
MAP.put(TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, "Non-reified type parameters with recursive bounds are not supported yet: {0}", STRING);
MAP.put(JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE, "Java SAM interface constructor references are prohibited");
MAP.put(ENUM_DECLARING_CLASS_DEPRECATED, "Enum.declaringClass is deprecated, use javaDeclaringClass instead");
}
@NotNull
@@ -206,6 +206,8 @@ public interface ErrorsJvm {
DiagnosticFactory1<PsiElement, String> TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<PsiElement> JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE = DiagnosticFactory0.create(ERROR);
DiagnosticFactoryForDeprecation0<PsiElement> ENUM_DECLARING_CLASS_DEPRECATED =
DiagnosticFactoryForDeprecation0.create(LanguageFeature.ProhibitEnumDeclaringClass);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
@@ -60,6 +60,7 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
InconsistentOperatorFromJavaCallChecker,
PolymorphicSignatureCallChecker,
SamInterfaceConstructorReferenceCallChecker,
EnumDeclaringClassDeprecationChecker,
),
additionalTypeCheckers = listOf(