diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 87a3bc418ee..069d0463804 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -40,10 +40,10 @@ import org.jetbrains.kotlin.load.java.JavaVisibilities; import org.jetbrains.kotlin.load.java.JvmAnnotationNames; import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor; import org.jetbrains.kotlin.name.FqName; +import org.jetbrains.kotlin.resolve.DeprecationUtilKt; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt; import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage; -import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage; import org.jetbrains.kotlin.resolve.inline.InlineUtil; import org.jetbrains.kotlin.resolve.jvm.JvmClassName; import org.jetbrains.kotlin.resolve.jvm.JvmPackage; @@ -226,9 +226,9 @@ public class AsmUtil { int flags = getVisibilityAccessFlag(functionDescriptor); flags |= getVarargsFlag(functionDescriptor); flags |= getDeprecatedAccessFlag(functionDescriptor); - if (DescriptorUtilPackage.isAnnotatedAsHidden(functionDescriptor) + if (DeprecationUtilKt.isAnnotatedAsHidden(functionDescriptor) || functionDescriptor instanceof PropertyAccessorDescriptor - && DescriptorUtilPackage.isAnnotatedAsHidden(((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty())) { + && DeprecationUtilKt.isAnnotatedAsHidden(((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty())) { flags |= ACC_SYNTHETIC; } return flags; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java index 6af7b2445af..c7ed4ccf592 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -648,7 +648,7 @@ public class CallResolver { ) { final List> candidateResolutionContexts = ContainerUtil.newArrayList(); for (final ResolutionCandidate resolutionCandidate : task.getCandidates()) { - if (DescriptorUtilPackage.isAnnotatedAsHidden(resolutionCandidate.getDescriptor())) continue; + if (DeprecationUtilKt.isAnnotatedAsHidden(resolutionCandidate.getDescriptor())) continue; candidatePerfCounter.time(new Function0() { @Override diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt new file mode 100644 index 00000000000..0eb0fb3d95e --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecationUtil.kt @@ -0,0 +1,103 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve + +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget +import org.jetbrains.kotlin.descriptors.annotations.Annotations +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.resolve.annotations.argumentValue + +private val JAVA_DEPRECATED = FqName("java.lang.Deprecated") + +fun DeclarationDescriptor.getDeprecatedAnnotation(): Pair? { + val ownAnnotation = getDeclaredDeprecatedAnnotation(AnnotationUseSiteTarget.getAssociatedUseSiteTarget(this)) + if (ownAnnotation != null) + return ownAnnotation to this + + when (this) { + is ConstructorDescriptor -> { + val classDescriptor = getContainingDeclaration() + val classAnnotation = classDescriptor.getDeclaredDeprecatedAnnotation() + if (classAnnotation != null) + return classAnnotation to classDescriptor + } + is PropertyAccessorDescriptor -> { + val propertyDescriptor = correspondingProperty + + val target = if (this is PropertyGetterDescriptor) AnnotationUseSiteTarget.PROPERTY_GETTER else AnnotationUseSiteTarget.PROPERTY_SETTER + val accessorAnnotation = propertyDescriptor.getDeclaredDeprecatedAnnotation(target, false) + if (accessorAnnotation != null) + return accessorAnnotation to this + + val classDescriptor = containingDeclaration as? ClassDescriptor + if (classDescriptor != null && classDescriptor.isCompanionObject) { + val classAnnotation = classDescriptor.getDeclaredDeprecatedAnnotation() + if (classAnnotation != null) + return classAnnotation to classDescriptor + } + } + } + return null +} + +private fun DeclarationDescriptor.getDeclaredDeprecatedAnnotation( + target: AnnotationUseSiteTarget? = null, + findAnnotationsWithoutTarget: Boolean = true +): AnnotationDescriptor? { + if (findAnnotationsWithoutTarget) { + val annotations = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.deprecated) ?: annotations.findAnnotation(JAVA_DEPRECATED) + if (annotations != null) return annotations + } + + if (target != null) { + return Annotations.findUseSiteTargetedAnnotation(annotations, target, KotlinBuiltIns.FQ_NAMES.deprecated) + ?: Annotations.findUseSiteTargetedAnnotation(annotations, target, JAVA_DEPRECATED) + } + + return null +} + +// Reflects values from kotlin.DeprecationLevel +enum class DeprecationLevelValue { + WARNING, ERROR, HIDDEN +} + +fun AnnotationDescriptor.getDeprecatedAnnotationLevel(): DeprecationLevelValue? { + val level = this.argumentValue("level") as? ClassDescriptor + + return when(level?.name?.asString()) { + "WARNING" -> DeprecationLevelValue.WARNING + "ERROR" -> DeprecationLevelValue.ERROR + "HIDDEN" -> DeprecationLevelValue.HIDDEN + else -> null + } +} + +fun DeclarationDescriptor.getDeprecatedAnnotationLevel(): DeprecationLevelValue? { + return getDeprecatedAnnotation()?.first?.getDeprecatedAnnotationLevel() +} + +@Deprecated("Should be removed together with kotlin.HiddenDeclaration") +private val HIDDEN_ANNOTATION_FQ_NAME = FqName("kotlin.HiddenDeclaration") + +fun DeclarationDescriptor.isAnnotatedAsHidden(): Boolean { + return annotations.findAnnotation(HIDDEN_ANNOTATION_FQ_NAME) != null + || getDeprecatedAnnotationLevel() == DeprecationLevelValue.HIDDEN +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt index ca8589ac238..83a58e6b149 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/validation/DeprecatedSymbolValidator.kt @@ -19,24 +19,23 @@ package org.jetbrains.kotlin.resolve.validation import com.intellij.psi.PsiElement import com.intellij.psi.tree.TokenSet import com.intellij.psi.util.PsiTreeUtil -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassifierDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor -import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget -import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.PROPERTY_GETTER -import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.PROPERTY_SETTER -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingTrace +import org.jetbrains.kotlin.resolve.DeprecationLevelValue import org.jetbrains.kotlin.resolve.annotations.argumentValue import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.getDeprecatedAnnotation +import org.jetbrains.kotlin.resolve.getDeprecatedAnnotationLevel public class DeprecatedSymbolValidator : SymbolUsageValidator { - private val JAVA_DEPRECATED = FqName(java.lang.Deprecated::class.java.name) override fun validateCall(resolvedCall: ResolvedCall<*>?, targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) { val deprecated = targetDescriptor.getDeprecatedAnnotation() @@ -67,59 +66,10 @@ public class DeprecatedSymbolValidator : SymbolUsageValidator { } } - private fun DeclarationDescriptor.getDeprecatedAnnotation(): Pair? { - val ownAnnotation = getDeclaredDeprecatedAnnotation(AnnotationUseSiteTarget.getAssociatedUseSiteTarget(this)) - if (ownAnnotation != null) - return ownAnnotation to this - - when (this) { - is ConstructorDescriptor -> { - val classDescriptor = getContainingDeclaration() - val classAnnotation = classDescriptor.getDeclaredDeprecatedAnnotation() - if (classAnnotation != null) - return classAnnotation to classDescriptor - } - is PropertyAccessorDescriptor -> { - val propertyDescriptor = correspondingProperty - - val target = if (this is PropertyGetterDescriptor) PROPERTY_GETTER else PROPERTY_SETTER - val accessorAnnotation = propertyDescriptor.getDeclaredDeprecatedAnnotation(target, false) - if (accessorAnnotation != null) - return accessorAnnotation to this - - val classDescriptor = containingDeclaration as? ClassDescriptor - if (classDescriptor != null && classDescriptor.isCompanionObject) { - val classAnnotation = classDescriptor.getDeclaredDeprecatedAnnotation() - if (classAnnotation != null) - return classAnnotation to classDescriptor - } - } - } - return null - } - - private fun DeclarationDescriptor.getDeclaredDeprecatedAnnotation( - target: AnnotationUseSiteTarget? = null, - findAnnotationsWithoutTarget: Boolean = true - ): AnnotationDescriptor? { - if (findAnnotationsWithoutTarget) { - val annotations = annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.deprecated) ?: annotations.findAnnotation(JAVA_DEPRECATED) - if (annotations != null) return annotations - } - - if (target != null) { - return Annotations.Companion.findUseSiteTargetedAnnotation(annotations, target, KotlinBuiltIns.FQ_NAMES.deprecated) - ?: Annotations.Companion.findUseSiteTargetedAnnotation(annotations, target, JAVA_DEPRECATED) - } - - return null - } - private fun createDeprecationDiagnostic(element: PsiElement, descriptor: DeclarationDescriptor, deprecated: AnnotationDescriptor): Diagnostic { val message = deprecated.argumentValue("message") as? String ?: "" - val level = deprecated.argumentValue("level") as? ClassDescriptor - if (level?.name?.asString() == "ERROR") { + if (deprecated.getDeprecatedAnnotationLevel() == DeprecationLevelValue.ERROR) { return Errors.DEPRECATION_ERROR.on(element, descriptor.original, message) } diff --git a/core/builtins/src/kotlin/Annotations.kt b/core/builtins/src/kotlin/Annotations.kt index b0ce1e7021b..941d69b402d 100644 --- a/core/builtins/src/kotlin/Annotations.kt +++ b/core/builtins/src/kotlin/Annotations.kt @@ -139,4 +139,4 @@ internal annotation class NoInfer */ @Target(TYPE) @Retention(SOURCE) -internal annotation class Exact \ No newline at end of file +internal annotation class Exact diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt index b27edd07a31..61822b98360 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/annotationsForResolve.kt @@ -16,14 +16,9 @@ package org.jetbrains.kotlin.resolve.descriptorUtil -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotated import org.jetbrains.kotlin.name.FqName -private val HIDDEN_ANNOTATION_FQ_NAME = FqName("kotlin.HiddenDeclaration") - -public fun DeclarationDescriptor.isAnnotatedAsHidden(): Boolean = annotations.findAnnotation(HIDDEN_ANNOTATION_FQ_NAME) != null - private val NO_INFER_ANNOTATION_FQ_NAME = FqName("kotlin.NoInfer") public fun Annotated.hasNoInferAnnotation(): Boolean = annotations.findAnnotation(NO_INFER_ANNOTATION_FQ_NAME) != null diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt index 7db2b98e9fe..5813d3714d1 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/codeInsight/ReferenceVariantsHelper.kt @@ -31,8 +31,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager -import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotatedAsHidden import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension +import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.JetScope diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt index 2376b277ff4..d3f080059a3 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt @@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetNamedDeclaration import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotatedAsHidden +import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils import org.jetbrains.kotlin.types.JetType import org.jetbrains.kotlin.utils.addIfNotNull diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt index 804933571c1..15a1ecd400e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ConflictingExtensionPropertyInspection.kt @@ -48,7 +48,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.renderer.render import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess -import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotatedAsHidden +import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden import org.jetbrains.kotlin.resolve.scopes.FileScope import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull