Optimize imports: references via aliases are treated correctly

This commit is contained in:
Valentin Kipyatkov
2015-02-17 15:35:03 +03:00
parent 8c034d4ac7
commit d60145d3e8
2 changed files with 8 additions and 4 deletions
@@ -181,8 +181,9 @@ public class KotlinImportOptimizer() : ImportOptimizer {
override fun visitJetElement(element: JetElement) {
val reference = element.getReference()
if (reference is JetReference) {
val referencedName = (element as? JetNameReferenceExpression)?.getReferencedNameAsName() //TODO: other types of references
val targets = reference.resolveToDescriptors()
//TODO: check if it's resolved through alias
for (target in targets) {
if (!target.canBeReferencedViaImport()) continue
if (target is PackageViewDescriptor && target.getFqName().parent() == FqName.ROOT) continue // no need to import top-level packages (TODO: is that always true?)
@@ -193,9 +194,12 @@ public class KotlinImportOptimizer() : ImportOptimizer {
if (element.getReceiverExpression() != null) continue
}
val importableDescriptor = target.getImportableDescriptor()
if (referencedName != null && importableDescriptor.getName() != referencedName) continue // resolved via alias
if (isAccessibleAsMember(target, element)) continue
usedDescriptors.add(target.getImportableDescriptor())
usedDescriptors.add(importableDescriptor)
}
}
@@ -3,10 +3,10 @@ Comment 1
*/
package sometest
import java.io as JavaIO
import java.text.Annotation as TextAnnotation
import java.util.ArrayList
import java.util.HashSet
import java.io as JavaIO
import java.text.Annotation as TextAnnotation
/**
Comment 2