Imports on copy/paste: Check whether import is needed before showing the user

Minor: rename ImportInsertHelper.doNeedImport -> needImport
This commit is contained in:
Pavel V. Talanov
2014-02-05 11:43:05 +04:00
parent 61153c87e0
commit ccaf87bc17
5 changed files with 18 additions and 11 deletions
@@ -225,8 +225,11 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Refere
return Collections.emptyList()
}
return referenceData.map {
val referenceExpression = findReference(it, file, bounds)
if (referenceExpression != null) createReferenceToRestoreData(referenceExpression, it.fqName) else null
if (ImportInsertHelper.needImport(it.fqName, file)) {
val referenceExpression = findReference(it, file, bounds)
if (referenceExpression != null) createReferenceToRestoreData(referenceExpression, it.fqName) else null
}
else null
}.filterNotNull()
}
@@ -67,7 +67,7 @@ public class JetDeclarationRemotenessWeigher extends LookupElementWeigher {
// Invalid name can be met for class object descriptor: Test.MyTest.A.<no name provided>.testOther
if (QualifiedNamesUtil.isValidJavaFqName(fqName.toString())) {
ImportPath importPath = new ImportPath(fqName.toString());
if (ImportInsertHelper.doNeedImport(importPath, file)) {
if (ImportInsertHelper.needImport(importPath, file)) {
return MyResult.notImported;
}
else {
@@ -39,7 +39,7 @@ import org.jetbrains.jet.util.QualifiedNamesUtil;
import java.util.*;
import static org.jetbrains.jet.plugin.quickfix.ImportInsertHelper.doNeedImport;
import static org.jetbrains.jet.plugin.quickfix.ImportInsertHelper.needImport;
public class JetImportOptimizer implements ImportOptimizer {
@Override
@@ -75,8 +75,8 @@ public class JetImportOptimizer implements ImportOptimizer {
}
if (isUseful(importPath, usedQualifiedNames) &&
doNeedImport(importPath, jetFile, directivesBeforeCurrent) &&
doNeedImport(importPath, jetFile, directivesAfterCurrent)) {
needImport(importPath, jetFile, directivesBeforeCurrent) &&
needImport(importPath, jetFile, directivesAfterCurrent)) {
directivesBeforeCurrent.add(anImport);
}
else {
@@ -107,7 +107,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
@Override
public boolean apply(@Nullable FqName fqName) {
assert fqName != null;
return ImportInsertHelper.doNeedImport(new ImportPath(fqName, false), (JetFile) file);
return ImportInsertHelper.needImport(new ImportPath(fqName, false), (JetFile) file);
}
});
}
@@ -88,7 +88,7 @@ public class ImportInsertHelper {
new OptimizeImportsProcessor(file.getProject(), file).runWithoutProgress();
}
if (!doNeedImport(importPath, file)) {
if (!needImport(importPath, file)) {
return;
}
@@ -142,11 +142,15 @@ public class ImportInsertHelper {
return QualifiedNamesUtil.isImported(defaultImports, importPath);
}
public static boolean doNeedImport(@NotNull ImportPath importPath, @NotNull JetFile file) {
return doNeedImport(importPath, file, file.getImportDirectives());
public static boolean needImport(@NotNull FqName fqName, @NotNull JetFile file) {
return needImport(new ImportPath(fqName, false), file);
}
public static boolean doNeedImport(@NotNull ImportPath importPath, @NotNull JetFile file, List<JetImportDirective> importDirectives) {
public static boolean needImport(@NotNull ImportPath importPath, @NotNull JetFile file) {
return needImport(importPath, file, file.getImportDirectives());
}
public static boolean needImport(@NotNull ImportPath importPath, @NotNull JetFile file, List<JetImportDirective> importDirectives) {
if (importPath.fqnPart().firstSegmentIs(JavaDescriptorResolver.JAVA_ROOT)) {
FqName withoutJavaRoot = QualifiedNamesUtil.withoutFirstSegment(importPath.fqnPart());
importPath = new ImportPath(withoutJavaRoot, importPath.isAllUnder(), importPath.getAlias());