FE 1.0: introduce deprecation for Enum.declaringClass (KT-49653)
This commit is contained in:
committed by
TeamCityServer
parent
983fa4c8c7
commit
fd3d86eddf
+29
@@ -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))
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -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(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(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
|
@NotNull
|
||||||
|
|||||||
@@ -206,6 +206,8 @@ public interface ErrorsJvm {
|
|||||||
DiagnosticFactory1<PsiElement, String> TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<PsiElement, String> TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<PsiElement> JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<PsiElement> JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE = DiagnosticFactory0.create(ERROR);
|
||||||
|
DiagnosticFactoryForDeprecation0<PsiElement> ENUM_DECLARING_CLASS_DEPRECATED =
|
||||||
|
DiagnosticFactoryForDeprecation0.create(LanguageFeature.ProhibitEnumDeclaringClass);
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
Object _initializer = new Object() {
|
Object _initializer = new Object() {
|
||||||
|
|||||||
+1
@@ -60,6 +60,7 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
|||||||
InconsistentOperatorFromJavaCallChecker,
|
InconsistentOperatorFromJavaCallChecker,
|
||||||
PolymorphicSignatureCallChecker,
|
PolymorphicSignatureCallChecker,
|
||||||
SamInterfaceConstructorReferenceCallChecker,
|
SamInterfaceConstructorReferenceCallChecker,
|
||||||
|
EnumDeclaringClassDeprecationChecker,
|
||||||
),
|
),
|
||||||
|
|
||||||
additionalTypeCheckers = listOf(
|
additionalTypeCheckers = listOf(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
// !LANGUAGE: -ProhibitEnumDeclaringClass
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
// !LANGUAGE: -ProhibitEnumDeclaringClass
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun <E : Enum<E>> foo(values: Array<E>) {
|
fun <E : Enum<E>> foo(values: Array<E>) {
|
||||||
EnumSet.noneOf(values.first().declaringClass)
|
EnumSet.noneOf(values.first().<!ENUM_DECLARING_CLASS_DEPRECATED_WARNING!>declaringClass<!>)
|
||||||
EnumSet.noneOf(values.first().<!UNRESOLVED_REFERENCE!>getDeclaringClass<!>())
|
EnumSet.noneOf(values.first().<!UNRESOLVED_REFERENCE!>getDeclaringClass<!>())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,6 +267,7 @@ enum class LanguageFeature(
|
|||||||
ProhibitArrayLiteralsInCompanionOfAnnotation(KOTLIN_1_9, kind = BUG_FIX), // KT-39041
|
ProhibitArrayLiteralsInCompanionOfAnnotation(KOTLIN_1_9, kind = BUG_FIX), // KT-39041
|
||||||
ProhibitCyclesInAnnotations(KOTLIN_1_9, kind = BUG_FIX), // KT-47932
|
ProhibitCyclesInAnnotations(KOTLIN_1_9, kind = BUG_FIX), // KT-47932
|
||||||
ForbidExtensionFunctionTypeOnNonFunctionTypes(KOTLIN_1_9), // related to KT-43527
|
ForbidExtensionFunctionTypeOnNonFunctionTypes(KOTLIN_1_9), // related to KT-43527
|
||||||
|
ProhibitEnumDeclaringClass(KOTLIN_1_9, kind = BUG_FIX), // KT-49653
|
||||||
|
|
||||||
// Temporarily disabled, see KT-27084/KT-22379
|
// Temporarily disabled, see KT-27084/KT-22379
|
||||||
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
|
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
|
||||||
|
|||||||
Reference in New Issue
Block a user