optimize imports: leave on demand imports untouched when no corresponding dirs can be found in the resolve scope (IDEA-82944) [peter]

(cherry picked from commit 61c42a9b1cb1fa712db584b8df5bc707cf4fb7ea)
This commit is contained in:
anna
2012-03-21 18:02:11 +01:00
parent 6f805c06b5
commit 8cea94f9c3
2 changed files with 10 additions and 1 deletions
@@ -104,10 +104,17 @@ public class OptimizeImportsRefactoringHelper implements RefactoringHelper<Set<P
if (importStatement != null && importStatement.isValid()) {
final PsiJavaCodeReferenceElement ref = importStatement.getImportReference();
//Do not remove non-resolving refs
if (ref == null || ref.resolve() == null) {
if (ref == null) {
continue;
}
final PsiElement resolve = ref.resolve();
if (resolve == null) {
continue;
}
if (resolve instanceof PsiPackage && ((PsiPackage)resolve).getDirectories(ref.getResolveScope()).length == 0) {
continue;
}
importStatement.delete();
}
}