Overcome ambiguity between kotlin.Throws and kotlin.jvm.Throws
^KT-35468 In Progress
This commit is contained in:
committed by
Ilya Gorbunov
parent
534ff58d9c
commit
d3f541a715
@@ -47,3 +47,5 @@ val JVM_FIELD_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmField")
|
||||
// If you wish to add another JVM-related annotation and has/find utility methods, please proceed to jvmAnnotationUtil.kt
|
||||
@JvmField
|
||||
val JVM_THROWS_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.Throws")
|
||||
|
||||
val KOTLIN_THROWS_ANNOTATION_FQ_NAME = FqName("kotlin.Throws")
|
||||
|
||||
@@ -32,7 +32,10 @@ import org.jetbrains.kotlin.psi.KtImportDirective
|
||||
import org.jetbrains.kotlin.psi.KtImportInfo
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.annotations.JVM_THROWS_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.annotations.KOTLIN_THROWS_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.ImportingScope
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
@@ -242,13 +245,28 @@ class LazyImportScope(
|
||||
val descriptor = getImportScope(directive).getContributedClassifier(name, location)
|
||||
if (descriptor !is ClassDescriptor && descriptor !is TypeAliasDescriptor || !isClassifierVisible(descriptor))
|
||||
continue /* type parameters can't be imported */
|
||||
if (target != null && target != descriptor) return@compute null // ambiguity
|
||||
target = descriptor
|
||||
if (target != null && target != descriptor) {
|
||||
if (target.isKotlinOrJvmThrows() && descriptor.isKotlinOrJvmThrows()) {
|
||||
if (descriptor.isKotlinThrows()) {
|
||||
target = descriptor
|
||||
}
|
||||
} else {
|
||||
return@compute null // ambiguity
|
||||
}
|
||||
} else {
|
||||
target = descriptor
|
||||
}
|
||||
}
|
||||
|
||||
target
|
||||
}
|
||||
|
||||
private fun ClassifierDescriptor.isKotlinThrows() = fqNameOrNull() == KOTLIN_THROWS_ANNOTATION_FQ_NAME
|
||||
private fun ClassifierDescriptor.isKotlinOrJvmThrows(): Boolean {
|
||||
if (name != JVM_THROWS_ANNOTATION_FQ_NAME.shortName()) return false
|
||||
return isKotlinThrows() || fqNameOrNull() == JVM_THROWS_ANNOTATION_FQ_NAME
|
||||
}
|
||||
|
||||
override fun getContributedPackage(name: Name): PackageViewDescriptor? = null
|
||||
|
||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
|
||||
Reference in New Issue
Block a user