List<ShelvedChangeList> (@NotNull Collection<? extends Change> changes, boolean rollbackChanges) { List<String> failedChangeLists = new ArrayList<>(); List<ShelvedChangeList> result = new ArrayList<>(); List<Change> shelvedChanges = new ArrayList<>(); try { ChangeListManager changeListManager = ChangeListManager.getInstance(myProject); if (!changeListManager.areChangeListsEnabled()) { LOG.warn("Changelists are disabled", new Throwable()); } SHELVED_FILES_LOCK.writeLock().lock(); rememberShelvingFiles(changes); List<LocalChangeList> changeLists = changeListManager.getChangeLists(); for (LocalChangeList list : changeLists) { Set<Change> changeSet = new HashSet<>(list.getChanges()); List<Change> changesForChangelist = new ArrayList<>(); for (Change change : changes) { boolean inChangelist; if (change instanceof ChangeListChange) { inChangelist = ((ChangeListChange)change).getChangeListId().equals(list.getId()); } else { inChangelist = changeSet.contains(change); } if (inChangelist) { changesForChangelist.add(change); } } if (!changesForChangelist.isEmpty()) { try { result.add(createShelfFromChanges(changesForChangelist, list.getName(), false, false)); shelvedChanges.addAll(changesForChangelist); } catch (Exception e) { ProgressManager.checkCanceled(); LOG.warn(e); failedChangeLists.add(list.getName()); } } } } finally { cleanShelvingFiles(); SHELVED_FILES_LOCK.writeLock().unlock(); notifyStateChanged(); } if (rollbackChanges) { rollbackChangesAfterShelve(shelvedChanges, false); } if (!failedChangeLists.isEmpty()) { VcsNotifier.getInstance(myProject).notifyError( SHELVE_FAILED, VcsBundle.message("shelve.failed.title"), VcsBundle.message("shelve.failed.message", failedChangeLists.size(), StringUtil.join(failedChangeLists, ","))); } return result; }