Run classifier usage checkers on constructor calls
In some cases, REFERENCE_TARGET for annotation entries is the annotation class descriptor, and in others -- the constructor of that class
This commit is contained in:
+3
@@ -46,6 +46,9 @@ class JvmModuleAccessibilityChecker(project: Project) : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val descriptor = resolvedCall.resultingDescriptor
|
||||
|
||||
// Do not check constructors, because the containing class will be checked in [ClassifierUsage]
|
||||
if (descriptor is ClassConstructorDescriptor) return
|
||||
|
||||
// javac seems to check only the containing class of the member being called. Note that it's fine to call, for example,
|
||||
// members with parameter types or return type from an unexported package
|
||||
val targetDescriptor = DescriptorUtils.getParentOfType(descriptor, ClassOrPackageFragmentDescriptor::class.java) ?: return
|
||||
|
||||
+4
-6
@@ -18,10 +18,7 @@ package org.jetbrains.kotlin.resolve.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
@@ -77,8 +74,9 @@ fun checkClassifierUsages(
|
||||
}
|
||||
|
||||
private fun getReferencedClassifier(expression: KtReferenceExpression): ClassifierDescriptor? {
|
||||
val target = context.trace.get(BindingContext.REFERENCE_TARGET, expression) as? ClassifierDescriptor
|
||||
if (target != null) return target
|
||||
val target = context.trace.get(BindingContext.REFERENCE_TARGET, expression)
|
||||
if (target is ClassifierDescriptor) return target
|
||||
if (target is ClassConstructorDescriptor) return target.constructedClass
|
||||
|
||||
// "Comparable" in "import java.lang.Comparable" references both a class and a SAM constructor and prevents
|
||||
// REFERENCE_TARGET from being recorded in favor of AMBIGUOUS_REFERENCE_TARGET. But we must still run checkers
|
||||
|
||||
@@ -334,9 +334,6 @@ class DeprecationResolver(
|
||||
is DescriptorDerivedFromTypeAlias -> {
|
||||
result.addAll(typeAliasDescriptor.getOwnDeprecations())
|
||||
}
|
||||
is ConstructorDescriptor -> {
|
||||
addDeprecationIfPresent(containingDeclaration)
|
||||
}
|
||||
is PropertyAccessorDescriptor -> {
|
||||
addDeprecationIfPresent(correspondingProperty)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ open class Foo
|
||||
|
||||
fun test(f: <!DEPRECATION_ERROR!>Foo<!>) {
|
||||
f.toString()
|
||||
val g: <!DEPRECATION_ERROR!>Foo<!>? = <!UNRESOLVED_REFERENCE!>Foo<!>()
|
||||
val g: <!DEPRECATION_ERROR!>Foo<!>? = <!DEPRECATION_ERROR!>Foo<!>()
|
||||
}
|
||||
|
||||
class Bar : <!UNRESOLVED_REFERENCE, DEPRECATION_ERROR, DEBUG_INFO_UNRESOLVED_WITH_TARGET!>Foo<!>()
|
||||
class Bar : <!DEPRECATION_ERROR!>Foo<!>()
|
||||
|
||||
Reference in New Issue
Block a user