Fixed bug with importing some of SAM-constructors and factory functions

#KT-3449 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-02-09 21:24:49 +03:00
parent 2c5953dbe6
commit 546836d5dd
11 changed files with 94 additions and 3 deletions
@@ -58,9 +58,23 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
= DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this)
private fun JetReferenceExpression.targets(context: BindingContext): Collection<DeclarationDescriptor> {
return context[BindingContext.REFERENCE_TARGET, this]?.let { listOf(it.getImportableDescriptor()) }
?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this]?.map { it.getImportableDescriptor() }?.toSet()
?: listOf()
val targets = context[BindingContext.REFERENCE_TARGET, this]?.let { listOf(it) }
?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this]
?: listOf()
return targets.map { descriptorToImport(it) }.toSet()
}
private fun descriptorToImport(target: DeclarationDescriptor): DeclarationDescriptor {
val descriptor = target.getImportableDescriptor()
// if there is a class with the same fq-name then prefer to consider it as target (otherwise we won't insert import)
if (descriptor is CallableDescriptor) {
val container = descriptor.getContainingDeclaration()
if (container is PackageFragmentDescriptor) {
val classifier = container.getMemberScope().getClassifier(descriptor.getName())
if (classifier != null) return classifier
}
}
return descriptor
}
private fun mayImport(descriptor: DeclarationDescriptor, file: JetFile): Boolean {