Skip to content

Commit e5bc012

Browse files
committed
Resolved all references before che
cking unused imports in tests
1 parent 1d5f91e commit e5bc012

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/com/goide/codeInsight/imports/GoImportOptimizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private static boolean hasImportUsers(@NotNull GoImportSpec spec) {
202202
}
203203

204204
@NotNull
205-
private static Set<GoImportSpec> findDuplicatedEntries(@NotNull MultiMap<String, GoImportSpec> importMap) {
205+
public static Set<GoImportSpec> findDuplicatedEntries(@NotNull MultiMap<String, GoImportSpec> importMap) {
206206
Set<GoImportSpec> duplicatedEntries = ContainerUtil.newLinkedHashSet();
207207
for (Map.Entry<String, Collection<GoImportSpec>> imports : importMap.entrySet()) {
208208
Collection<GoImportSpec> importsWithSameName = imports.getValue();

src/com/goide/inspections/GoUnusedImportInspection.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.goide.quickfix.GoRenameQuickFix;
2525
import com.intellij.codeInspection.*;
2626
import com.intellij.find.FindManager;
27+
import com.intellij.openapi.application.ApplicationManager;
2728
import com.intellij.openapi.command.WriteCommandAction;
2829
import com.intellij.openapi.project.Project;
2930
import com.intellij.psi.PsiElement;
@@ -104,18 +105,14 @@ protected void checkFile(@NotNull GoFile file, @NotNull ProblemsHolder problemsH
104105
}
105106
}
106107

107-
if (!problemsHolder.isOnTheFly()) {
108-
resolveAllReferences(file);
109-
}
108+
if (!problemsHolder.isOnTheFly() || ApplicationManager.getApplication().isUnitTestMode()) resolveAllReferences(file);
110109
MultiMap<String, GoImportSpec> unusedImportsMap = GoImportOptimizer.filterUnusedImports(file, importMap);
111110
Set<GoImportSpec> unusedImportSpecs = ContainerUtil.newHashSet(unusedImportsMap.values());
112111
for (PsiElement importEntry : unusedImportSpecs) {
113112
GoImportSpec spec = GoImportOptimizer.getImportSpec(importEntry);
114-
if (spec != null) {
115-
if (spec.getImportString().resolve() != null) {
116-
problemsHolder.registerProblem(spec, "Unused import", ProblemHighlightType.GENERIC_ERROR, OPTIMIZE_QUICK_FIX,
117-
IMPORT_FOR_SIDE_EFFECTS_QUICK_FIX);
118-
}
113+
if (spec != null && spec.getImportString().resolve() != null) {
114+
problemsHolder.registerProblem(spec, "Unused import", ProblemHighlightType.GENERIC_ERROR, OPTIMIZE_QUICK_FIX,
115+
IMPORT_FOR_SIDE_EFFECTS_QUICK_FIX);
119116
}
120117
}
121118
}

0 commit comments

Comments
 (0)