boolean () { final ProgressIndicator indicator = myTask.getIndicator(); if (indicator != null) { indicator.setFraction(((double)myCount ++) / myTotal); } final SmartPsiElementPointer<PsiImportStatementBase> pointer = myPointers.next(); final PsiImportStatementBase importStatement = pointer.getElement(); if (importStatement != null && importStatement.isValid()) { final PsiJavaCodeReferenceElement ref = importStatement.getImportReference(); //Do not remove non-resolving refs if (ref != null) { final PsiElement resolve = ref.resolve(); try { if (resolve != null) { if (!(resolve instanceof PsiPackage) || ((PsiPackage)resolve).getDirectories(ref.getResolveScope()).length != 0) { importStatement.delete(); } } //preserve comments and don't need to distinguish static/normal imports and on-demand variations else { Collection<String> imports = myDuplicates.computeIfAbsent(pointer.getContainingFile(), file -> new HashSet<>()); if (!imports.add(importStatement.getText())) { importStatement.delete(); } } } catch (IncorrectOperationException e) { LOG.error(e); } } } return isDone(); }