Fixed bug in reference shortening related on on the fly import optimization

This commit is contained in:
Valentin Kipyatkov
2015-03-02 21:04:39 +03:00
parent 862d391da6
commit 5b4afa140b
4 changed files with 20 additions and 1 deletions
@@ -159,6 +159,10 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
for (descriptor in descriptorsToImport) {
assert(descriptor !in failedToImportDescriptors)
if (importInserter.optimizeImports()) {
anyChange = true
}
val result = importInserter.addImport(descriptor)
if (result != ImportInsertHelper.ImportDescriptorResult.ALREADY_IMPORTED) {
anyChange = true
@@ -456,7 +460,6 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options.
private val helper = ImportInsertHelper.getInstance(file.getProject())
fun addImport(target: DeclarationDescriptor): ImportInsertHelper.ImportDescriptorResult {
optimizeImports()
return helper.importDescriptor(file, target)
}
@@ -0,0 +1,5 @@
// OPTIMIZE_IMPORTS: true
// NAME_COUNT_TO_USE_STAR_IMPORT: 1
import java.util.HashMap
val v: HashMap<String, <selection>java.util.Date</selection>>
@@ -0,0 +1,5 @@
// OPTIMIZE_IMPORTS: true
// NAME_COUNT_TO_USE_STAR_IMPORT: 1
import java.util.*
val v: HashMap<String, Date>
@@ -186,6 +186,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
doTest(fileName);
}
@TestMetadata("ImportsOnTheFlyBug.kt")
public void testImportsOnTheFlyBug() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/shortenRefs/imports/ImportsOnTheFlyBug.kt");
doTest(fileName);
}
@TestMetadata("leaveQualifiedConstructor.kt")
public void testLeaveQualifiedConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/shortenRefs/imports/leaveQualifiedConstructor.kt");