Fixed bug in import insertion: it did not work with descriptors taken before modifications

This commit is contained in:
Valentin Kipyatkov
2015-02-09 18:57:40 +03:00
parent 7a4b291c85
commit 4fff1f44bb
5 changed files with 26 additions and 4 deletions
@@ -183,12 +183,14 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
val name = target.getName()
val topLevelScope = resolutionFacade.getFileTopLevelScope(file)
val targetFqName = target.importableFqName ?: return ImportDescriptorResult.FAIL
// check if import is not needed
when (target) {
is ClassDescriptor -> { if (topLevelScope.getClassifier(name) == target) return ImportDescriptorResult.ALREADY_IMPORTED }
is PackageViewDescriptor -> { if (topLevelScope.getPackage(name) == target) return ImportDescriptorResult.ALREADY_IMPORTED }
is FunctionDescriptor -> { if (topLevelScope.getFunctions(name).contains(target)) return ImportDescriptorResult.ALREADY_IMPORTED }
is PropertyDescriptor -> { if (topLevelScope.getProperties(name).contains(target)) return ImportDescriptorResult.ALREADY_IMPORTED }
is ClassDescriptor -> { if (topLevelScope.getClassifier(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED }
is PackageViewDescriptor -> { if (topLevelScope.getPackage(name)?.importableFqName == targetFqName) return ImportDescriptorResult.ALREADY_IMPORTED }
is FunctionDescriptor -> { if (topLevelScope.getFunctions(name).map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED }
is PropertyDescriptor -> { if (topLevelScope.getProperties(name).map { it.importableFqName }.contains(targetFqName)) return ImportDescriptorResult.ALREADY_IMPORTED }
else -> return ImportDescriptorResult.FAIL
}
@@ -0,0 +1,4 @@
package bar
class Class1
class Class2
@@ -0,0 +1,4 @@
// ALL_UNDER_IMPORTS: true
package foo
<selection>fun foo(p: bar.Class1): bar.Class2 { }</selection>
@@ -0,0 +1,6 @@
// ALL_UNDER_IMPORTS: true
package foo
import bar.*
fun foo(p: Class1): Class2 { }
@@ -49,6 +49,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
doTest(fileName);
}
@TestMetadata("descriptorsChangeAfterImportInsertion.kt")
public void testDescriptorsChangeAfterImportInsertion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/shortenRefs/descriptorsChangeAfterImportInsertion.kt");
doTest(fileName);
}
@TestMetadata("JavaStaticMethod.kt")
public void testJavaStaticMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/shortenRefs/JavaStaticMethod.kt");