use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class SvnCheckinHandlerFactory method createVcsHandler.
@NotNull
@Override
protected CheckinHandler createVcsHandler(final CheckinProjectPanel panel) {
final Project project = panel.getProject();
final Collection<VirtualFile> commitRoots = panel.getRoots();
return new CheckinHandler() {
private Collection<Change> myChanges = panel.getSelectedChanges();
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
return null;
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
if (executor instanceof LocalCommitExecutor)
return ReturnResult.COMMIT;
final SvnVcs vcs = SvnVcs.getInstance(project);
final MultiMap<String, WorkingCopyFormat> copiesInfo = splitIntoCopies(vcs, myChanges);
final List<String> repoUrls = new ArrayList<>();
for (Map.Entry<String, Collection<WorkingCopyFormat>> entry : copiesInfo.entrySet()) {
if (entry.getValue().size() > 1) {
repoUrls.add(entry.getKey());
}
}
if (!repoUrls.isEmpty()) {
final String join = StringUtil.join(repoUrls, ",\n");
final int isOk = Messages.showOkCancelDialog(project, SvnBundle.message("checkin.different.formats.involved", repoUrls.size() > 1 ? 1 : 0, join), "Subversion: Commit Will Split", Messages.getWarningIcon());
return Messages.OK == isOk ? ReturnResult.COMMIT : ReturnResult.CANCEL;
}
return ReturnResult.COMMIT;
}
@Override
public void includedChangesChanged() {
myChanges = panel.getSelectedChanges();
}
@Override
public void checkinSuccessful() {
if (SvnConfiguration.getInstance(project).isAutoUpdateAfterCommit()) {
final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(SvnVcs.getInstance(project));
final List<FilePath> paths = new ArrayList<>();
for (VirtualFile root : roots) {
boolean take = false;
for (VirtualFile commitRoot : commitRoots) {
if (VfsUtilCore.isAncestor(root, commitRoot, false)) {
take = true;
break;
}
}
if (take) {
paths.add(VcsUtil.getFilePath(root));
}
}
if (paths.isEmpty())
return;
ApplicationManager.getApplication().invokeLater(() -> AutoSvnUpdater.run(new AutoSvnUpdater(project, paths.toArray(new FilePath[paths.size()])), ActionInfo.UPDATE.getActionName()), ModalityState.NON_MODAL);
}
}
};
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class GrChangeSignatureProcessor method preprocessUsages.
@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
collectConflictsFromExtensions(refUsages, conflictDescriptions, myChangeInfo);
final UsageInfo[] usagesIn = refUsages.get();
RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
Set<UsageInfo> usagesSet = new HashSet<>(Arrays.asList(usagesIn));
RenameUtil.removeConflictUsages(usagesSet);
if (!conflictDescriptions.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
throw new ConflictsInTestsException(conflictDescriptions.values());
}
ConflictsDialog dialog = prepareConflictsDialog(conflictDescriptions, usagesIn);
if (!dialog.showAndGet()) {
if (dialog.isShowConflicts())
prepareSuccessful();
return false;
}
}
refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()]));
prepareSuccessful();
return true;
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class SvnCommittedListsZipper method groupLocations.
public Pair<List<RepositoryLocationGroup>, List<RepositoryLocation>> groupLocations(final List<RepositoryLocation> in) {
final List<RepositoryLocationGroup> groups = new ArrayList<>();
final List<RepositoryLocation> singles = new ArrayList<>();
final MultiMap<SVNURL, RepositoryLocation> map = new MultiMap<>();
for (RepositoryLocation location : in) {
final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location;
final String url = svnLocation.getURL();
final SVNURL root = SvnUtil.getRepositoryRoot(myVcs, url);
if (root == null) {
// should not occur
LOG.info("repository root not found for location:" + location.toPresentableString());
singles.add(location);
} else {
map.putValue(root, svnLocation);
}
}
final Set<SVNURL> keys = map.keySet();
for (SVNURL key : keys) {
final Collection<RepositoryLocation> repositoryLocations = map.get(key);
if (repositoryLocations.size() == 1) {
singles.add(repositoryLocations.iterator().next());
} else {
final SvnRepositoryLocationGroup group = new SvnRepositoryLocationGroup(key, repositoryLocations);
groups.add(group);
}
}
return Pair.create(groups, singles);
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class ConvertClosureToMethodIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrField field;
if (element.getParent() instanceof GrField) {
field = (GrField) element.getParent();
} else {
final PsiReference ref = element.getReference();
LOG.assertTrue(ref != null);
PsiElement resolved = ref.resolve();
if (resolved instanceof GrAccessorMethod) {
resolved = ((GrAccessorMethod) resolved).getProperty();
}
LOG.assertTrue(resolved instanceof GrField);
field = (GrField) resolved;
}
final HashSet<PsiReference> usages = new HashSet<>();
usages.addAll(ReferencesSearch.search(field).findAll());
final GrAccessorMethod[] getters = field.getGetters();
for (GrAccessorMethod getter : getters) {
usages.addAll(MethodReferencesSearch.search(getter).findAll());
}
final GrAccessorMethod setter = field.getSetter();
if (setter != null) {
usages.addAll(MethodReferencesSearch.search(setter).findAll());
}
final String fieldName = field.getName();
LOG.assertTrue(fieldName != null);
final Collection<PsiElement> fieldUsages = new HashSet<>();
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
for (PsiReference usage : usages) {
final PsiElement psiElement = usage.getElement();
if (PsiUtil.isMethodUsage(psiElement))
continue;
if (!GroovyLanguage.INSTANCE.equals(psiElement.getLanguage())) {
conflicts.putValue(psiElement, GroovyIntentionsBundle.message("closure.is.accessed.outside.of.groovy", fieldName));
} else {
if (psiElement instanceof GrReferenceExpression) {
fieldUsages.add(psiElement);
if (PsiUtil.isAccessedForWriting((GrExpression) psiElement)) {
conflicts.putValue(psiElement, GroovyIntentionsBundle.message("write.access.to.closure.variable", fieldName));
}
} else if (psiElement instanceof GrArgumentLabel) {
conflicts.putValue(psiElement, GroovyIntentionsBundle.message("field.is.used.in.argument.label", fieldName));
}
}
}
final PsiClass containingClass = field.getContainingClass();
final GrExpression initializer = field.getInitializerGroovy();
LOG.assertTrue(initializer != null);
final PsiType type = initializer.getType();
LOG.assertTrue(type instanceof GrClosureType);
final GrSignature signature = ((GrClosureType) type).getSignature();
final List<MethodSignature> signatures = GrClosureSignatureUtil.generateAllMethodSignaturesBySignature(fieldName, signature);
for (MethodSignature s : signatures) {
final PsiMethod method = MethodSignatureUtil.findMethodBySignature(containingClass, s, true);
if (method != null) {
conflicts.putValue(method, GroovyIntentionsBundle.message("method.with.signature.already.exists", GroovyPresentationUtil.getSignaturePresentation(s)));
}
}
if (!conflicts.isEmpty()) {
final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts, () -> execute(field, fieldUsages));
conflictsDialog.show();
if (conflictsDialog.getExitCode() != DialogWrapper.OK_EXIT_CODE)
return;
}
execute(field, fieldUsages);
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class MembersBasedPresenterImpl method getConflicts.
/**
* Checks if one of destination classes already has members that should be moved, so conflict would take place.
*
* @return map of conflicts (if any)
* @see #getDestClassesToCheckConflicts()
*/
@NotNull
protected final MultiMap<PyClass, PyMemberInfo<?>> getConflicts() {
final MultiMap<PyClass, PyMemberInfo<?>> result = new MultiMap<>();
final Collection<PyMemberInfo<PyElement>> memberInfos = myView.getSelectedMemberInfos();
for (final PyClass destinationClass : getDestClassesToCheckConflicts()) {
for (final PyMemberInfo<PyElement> pyMemberInfo : memberInfos) {
if (pyMemberInfo.hasConflict(destinationClass)) {
result.putValue(destinationClass, pyMemberInfo);
}
}
}
return result;
}
Aggregations