@Deprecated(..., level = HIDDEN) supported
isAnnotatedAsHidden() moved to front-end
This commit is contained in:
@@ -40,10 +40,10 @@ import org.jetbrains.kotlin.load.java.JavaVisibilities;
|
|||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
|
import org.jetbrains.kotlin.resolve.DeprecationUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
|
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.inline.InlineUtil;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPackage;
|
import org.jetbrains.kotlin.resolve.jvm.JvmPackage;
|
||||||
@@ -226,9 +226,9 @@ public class AsmUtil {
|
|||||||
int flags = getVisibilityAccessFlag(functionDescriptor);
|
int flags = getVisibilityAccessFlag(functionDescriptor);
|
||||||
flags |= getVarargsFlag(functionDescriptor);
|
flags |= getVarargsFlag(functionDescriptor);
|
||||||
flags |= getDeprecatedAccessFlag(functionDescriptor);
|
flags |= getDeprecatedAccessFlag(functionDescriptor);
|
||||||
if (DescriptorUtilPackage.isAnnotatedAsHidden(functionDescriptor)
|
if (DeprecationUtilKt.isAnnotatedAsHidden(functionDescriptor)
|
||||||
|| functionDescriptor instanceof PropertyAccessorDescriptor
|
|| functionDescriptor instanceof PropertyAccessorDescriptor
|
||||||
&& DescriptorUtilPackage.isAnnotatedAsHidden(((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty())) {
|
&& DeprecationUtilKt.isAnnotatedAsHidden(((PropertyAccessorDescriptor) functionDescriptor).getCorrespondingProperty())) {
|
||||||
flags |= ACC_SYNTHETIC;
|
flags |= ACC_SYNTHETIC;
|
||||||
}
|
}
|
||||||
return flags;
|
return flags;
|
||||||
|
|||||||
@@ -648,7 +648,7 @@ public class CallResolver {
|
|||||||
) {
|
) {
|
||||||
final List<CallCandidateResolutionContext<D>> candidateResolutionContexts = ContainerUtil.newArrayList();
|
final List<CallCandidateResolutionContext<D>> candidateResolutionContexts = ContainerUtil.newArrayList();
|
||||||
for (final ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
|
for (final ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
|
||||||
if (DescriptorUtilPackage.isAnnotatedAsHidden(resolutionCandidate.getDescriptor())) continue;
|
if (DeprecationUtilKt.isAnnotatedAsHidden(resolutionCandidate.getDescriptor())) continue;
|
||||||
|
|
||||||
candidatePerfCounter.time(new Function0<Unit>() {
|
candidatePerfCounter.time(new Function0<Unit>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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<AnnotationDescriptor, DeclarationDescriptor>? {
|
||||||
|
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
|
||||||
|
}
|
||||||
+8
-58
@@ -19,24 +19,23 @@ package org.jetbrains.kotlin.resolve.validation
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.tree.TokenSet
|
import com.intellij.psi.tree.TokenSet
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
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.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.Diagnostic
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
|
import org.jetbrains.kotlin.resolve.DeprecationLevelValue
|
||||||
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
|
import org.jetbrains.kotlin.resolve.getDeprecatedAnnotation
|
||||||
|
import org.jetbrains.kotlin.resolve.getDeprecatedAnnotationLevel
|
||||||
|
|
||||||
public class DeprecatedSymbolValidator : SymbolUsageValidator {
|
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) {
|
override fun validateCall(resolvedCall: ResolvedCall<*>?, targetDescriptor: CallableDescriptor, trace: BindingTrace, element: PsiElement) {
|
||||||
val deprecated = targetDescriptor.getDeprecatedAnnotation()
|
val deprecated = targetDescriptor.getDeprecatedAnnotation()
|
||||||
@@ -67,59 +66,10 @@ public class DeprecatedSymbolValidator : SymbolUsageValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun DeclarationDescriptor.getDeprecatedAnnotation(): Pair<AnnotationDescriptor, DeclarationDescriptor>? {
|
|
||||||
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 {
|
private fun createDeprecationDiagnostic(element: PsiElement, descriptor: DeclarationDescriptor, deprecated: AnnotationDescriptor): Diagnostic {
|
||||||
val message = deprecated.argumentValue("message") as? String ?: ""
|
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)
|
return Errors.DEPRECATION_ERROR.on(element, descriptor.original, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,4 +139,4 @@ internal annotation class NoInfer
|
|||||||
*/
|
*/
|
||||||
@Target(TYPE)
|
@Target(TYPE)
|
||||||
@Retention(SOURCE)
|
@Retention(SOURCE)
|
||||||
internal annotation class Exact
|
internal annotation class Exact
|
||||||
|
|||||||
@@ -16,14 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.descriptorUtil
|
package org.jetbrains.kotlin.resolve.descriptorUtil
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||||
import org.jetbrains.kotlin.name.FqName
|
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")
|
private val NO_INFER_ANNOTATION_FQ_NAME = FqName("kotlin.NoInfer")
|
||||||
|
|
||||||
public fun Annotated.hasNoInferAnnotation(): Boolean = annotations.findAnnotation(NO_INFER_ANNOTATION_FQ_NAME) != null
|
public fun Annotated.hasNoInferAnnotation(): Boolean = annotations.findAnnotation(NO_INFER_ANNOTATION_FQ_NAME) != null
|
||||||
|
|||||||
+1
-1
@@ -31,8 +31,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
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.descriptorUtil.isExtension
|
||||||
|
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.JetExpression
|
|||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
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.resolve.lazy.ResolveSessionUtils
|
||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
|||||||
import org.jetbrains.kotlin.renderer.render
|
import org.jetbrains.kotlin.renderer.render
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
|
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.resolve.scopes.FileScope
|
||||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
|
|||||||
Reference in New Issue
Block a user