Removed USELESS_HIDDEN_IMPORT error for it cannot happen anymore

This commit is contained in:
Valentin Kipyatkov
2015-01-16 00:40:51 +03:00
parent 929d6b885d
commit 7ce3925d71
8 changed files with 16 additions and 55 deletions
@@ -102,7 +102,6 @@ public interface Errors {
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_IMPORT_FROM_ELEMENT = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<JetSimpleNameExpression, DeclarationDescriptor> CANNOT_BE_IMPORTED = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetExpression> USELESS_HIDDEN_IMPORT = DiagnosticFactory0.create(WARNING);
DiagnosticFactory1<JetExpression, String> CONFLICTING_IMPORT = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetExpression> USELESS_SIMPLE_IMPORT = DiagnosticFactory0.create(WARNING);
@@ -168,7 +168,6 @@ public class DefaultErrorMessages {
MAP.put(CANNOT_IMPORT_FROM_ELEMENT, "Cannot import from ''{0}''", NAME);
MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME);
MAP.put(USELESS_HIDDEN_IMPORT, "Useless import, it is hidden further");
MAP.put(CONFLICTING_IMPORT, "Conflicting import, imported name ''{0}'' is ambiguous", STRING);
MAP.put(USELESS_SIMPLE_IMPORT, "Useless import, does nothing");
MAP.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn''t be used in Kotlin. Use {0} instead.", CLASSES_OR_SEPARATED);
@@ -133,7 +133,7 @@ public class ImportsResolver {
if (lookupMode == LookupMode.EVERYTHING) {
for (JetImportDirective importDirective : importDirectives) {
reportUselessImport(importDirective, fileScope, resolvedDirectives.get(importDirective), trace);
reportConflictingOrUselessImport(importDirective, fileScope, resolvedDirectives.get(importDirective), trace);
}
}
}
@@ -167,11 +167,11 @@ public class ImportsResolver {
}
}
public static void reportUselessImport(
@NotNull JetImportDirective importDirective,
@NotNull JetScope fileScope,
@Nullable Collection<? extends DeclarationDescriptor> resolvedTo,
@NotNull BindingTrace trace
public static void reportConflictingOrUselessImport(
@NotNull JetImportDirective importDirective,
@NotNull JetScope fileScope,
@Nullable Collection<? extends DeclarationDescriptor> resolvedTo,
@NotNull BindingTrace trace
) {
JetExpression importedReference = importDirective.getImportedReference();
@@ -180,39 +180,18 @@ public class ImportsResolver {
Name aliasName = JetPsiUtil.getAliasName(importDirective);
if (aliasName == null) return;
boolean uselessHiddenImport = true;
for (DeclarationDescriptor target : resolvedTo) {
DeclarationDescriptor isResolved = null;
if (resolvedTo.size() == 1) {
DeclarationDescriptor target = resolvedTo.iterator().next();
if (target instanceof ClassDescriptor) {
isResolved = fileScope.getClassifier(aliasName);
}
else if (target instanceof VariableDescriptor) {
isResolved = fileScope.getLocalVariable(aliasName);
if (fileScope.getClassifier(aliasName) == null) {
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
return;
}
}
else if (target instanceof PackageViewDescriptor) {
isResolved = fileScope.getPackage(aliasName);
}
if (isResolved == null || isResolved.equals(target)) {
uselessHiddenImport = false;
}
}
if (uselessHiddenImport) {
trace.report(USELESS_HIDDEN_IMPORT.on(importedReference));
}
else {
if (resolvedTo.size() == 1) {
DeclarationDescriptor target = resolvedTo.iterator().next();
if (target instanceof ClassDescriptor) {
if (fileScope.getClassifier(aliasName) == null) {
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
return;
}
}
else if (target instanceof PackageViewDescriptor) {
if (fileScope.getPackage(aliasName) == null) {
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
return;
}
if (fileScope.getPackage(aliasName) == null) {
trace.report(CONFLICTING_IMPORT.on(importedReference, aliasName.asString()));
return;
}
}
}
@@ -135,7 +135,7 @@ class LazyImportScope(
val status = importedScopesProvider(importDirective).importResolveStatus
if (status != null && !status.descriptors.isEmpty()) {
val fileScope = resolveSession.getScopeProvider().getFileScope(importDirective.getContainingJetFile())
ImportsResolver.reportUselessImport(importDirective, fileScope, status.descriptors, traceForImportResolve)
ImportsResolver.reportConflictingOrUselessImport(importDirective, fileScope, status.descriptors, traceForImportResolve)
}
}
@@ -128,7 +128,6 @@ public class QuickFixRegistrar {
JetSingleIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
QuickFixes.factories.put(USELESS_SIMPLE_IMPORT, removeImportFixFactory);
QuickFixes.factories.put(USELESS_HIDDEN_IMPORT, removeImportFixFactory);
QuickFixes.factories.put(CONFLICTING_IMPORT, removeImportFixFactory);
QuickFixes.factories.put(SUPERTYPE_NOT_INITIALIZED, ChangeToConstructorInvocationFix.createFactory());
@@ -1,4 +0,0 @@
// "Remove useless import for 'kotlin.List'" "true"
import kotlin.Double
class List {}
@@ -1,5 +0,0 @@
// "Remove useless import for 'kotlin.List'" "true"
import kotlin.Double
import kotlin.List<caret>
class List {}
@@ -4649,12 +4649,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/uselessImports"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeRemoveUselessHiddenImport.kt")
public void testRemoveUselessHiddenImport() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/uselessImports/beforeRemoveUselessHiddenImport.kt");
doTest(fileName);
}
@TestMetadata("beforeRemoveUselessImport.kt")
public void testRemoveUselessImport() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/uselessImports/beforeRemoveUselessImport.kt");