use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class NestingTreeStructureProvider method getNestingRules.
@NotNull
private Collection<NestingRule> getNestingRules() {
if (myNestingRules == null) {
myNestingRules = new THashSet<>();
final MultiMap<String, String> childToParentSuffix = new MultiMap<>();
final MultiMap<String, String> parentToChildSuffix = new MultiMap<>();
final ProjectViewNestingRulesProvider.Consumer consumer = new ProjectViewNestingRulesProvider.Consumer() {
@Override
public void addNestingRule(@NotNull final String parentFileSuffix, @NotNull final String childFileSuffix) {
LOG.assertTrue(!parentFileSuffix.isEmpty() && !childFileSuffix.isEmpty(), "file suffix must not be empty");
LOG.assertTrue(!parentFileSuffix.equals(childFileSuffix), "parent and child suffixes must be different: " + parentFileSuffix);
myNestingRules.add(new NestingRule(parentFileSuffix, childFileSuffix));
childToParentSuffix.putValue(childFileSuffix, parentFileSuffix);
parentToChildSuffix.putValue(parentFileSuffix, childFileSuffix);
// for all cases like A -> B -> C we also add a rule A -> C
for (String s : parentToChildSuffix.get(childFileSuffix)) {
myNestingRules.add(new NestingRule(parentFileSuffix, s));
parentToChildSuffix.putValue(parentFileSuffix, s);
childToParentSuffix.putValue(s, parentFileSuffix);
}
for (String s : childToParentSuffix.get(parentFileSuffix)) {
myNestingRules.add(new NestingRule(s, childFileSuffix));
parentToChildSuffix.putValue(s, childFileSuffix);
childToParentSuffix.putValue(childFileSuffix, s);
}
}
};
for (ProjectViewNestingRulesProvider provider : EP_NAME.getExtensions()) {
provider.addFileNestingRules(consumer);
}
}
return myNestingRules;
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class UsageFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
}
final Usage[] usages = UsageView.USAGES_KEY.getData(context);
if (usages != null) {
final List<AbstractTreeNode> result = new SmartList<>();
final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
final List<Usage> nonMapped = new ArrayList<>();
for (Usage usage : usages) {
if (usage instanceof UsageInFile) {
map.putValue(((UsageInFile) usage).getFile(), usage);
} else if (usage instanceof UsageInFiles) {
final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
for (VirtualFile file : files) {
map.putValue(file, usage);
}
} else {
nonMapped.add(usage);
}
}
final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
keys.addAll(map.keySet());
for (VirtualFile key : keys) {
final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
result.add(grouping);
final Collection<Usage> subUsages = map.get(key);
for (Usage usage : subUsages) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
grouping.addChild(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
}
for (Usage usage : nonMapped) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
result.add(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
return result;
}
return null;
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class ApplyPatchDifferentiatedDialog method runExecutor.
@CalledInAwt
private void runExecutor(ApplyPatchExecutor executor) {
final Collection<AbstractFilePatchInProgress> included = getIncluded();
if (included.isEmpty())
return;
final MultiMap<VirtualFile, AbstractFilePatchInProgress> patchGroups = new MultiMap<>();
for (AbstractFilePatchInProgress patchInProgress : included) {
patchGroups.putValue(patchInProgress.getBase(), patchInProgress);
}
final LocalChangeList selected = getSelectedChangeList();
FilePresentationModel presentation = myRecentPathFileChange.get();
VirtualFile vf = presentation != null ? presentation.getVf() : null;
executor.apply(getOriginalRemaining(), patchGroups, selected, vf == null ? null : vf.getName(), myReader == null ? null : myReader.getAdditionalInfo(ApplyPatchDefaultExecutor.pathsFromGroups(patchGroups)));
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class ImportToShelfExecutor method apply.
@Override
public void apply(@NotNull List<FilePatch> remaining, @NotNull final MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply, @Nullable LocalChangeList localList, @Nullable final String fileName, @Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
if (fileName == null) {
LOG.error("Patch file name shouldn't be null");
return;
}
final VcsCatchingRunnable vcsCatchingRunnable = new VcsCatchingRunnable() {
@Override
public void runImpl() throws VcsException {
final VirtualFile baseDir = myProject.getBaseDir();
final File ioBase = new File(baseDir.getPath());
final List<FilePatch> allPatches = new ArrayList<>();
for (VirtualFile virtualFile : patchGroupsToApply.keySet()) {
final File ioCurrentBase = new File(virtualFile.getPath());
allPatches.addAll(ContainerUtil.map(patchGroupsToApply.get(virtualFile), new Function<TextFilePatchInProgress, TextFilePatch>() {
public TextFilePatch fun(TextFilePatchInProgress patchInProgress) {
final TextFilePatch was = patchInProgress.getPatch();
was.setBeforeName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getBeforeName()))));
was.setAfterName(PathUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase, new File(ioCurrentBase, was.getAfterName()))));
return was;
}
}));
}
if (!allPatches.isEmpty()) {
PatchEP[] patchTransitExtensions = null;
if (additionalInfo != null) {
try {
final Map<String, PatchEP> extensions = new HashMap<>();
for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.compute().entrySet()) {
final String filePath = entry.getKey();
Map<String, CharSequence> extToValue = entry.getValue();
for (Map.Entry<String, CharSequence> innerEntry : extToValue.entrySet()) {
TransitExtension patchEP = (TransitExtension) extensions.get(innerEntry.getKey());
if (patchEP == null) {
patchEP = new TransitExtension(innerEntry.getKey());
extensions.put(innerEntry.getKey(), patchEP);
}
patchEP.put(filePath, innerEntry.getValue());
}
}
Collection<PatchEP> values = extensions.values();
patchTransitExtensions = values.toArray(new PatchEP[values.size()]);
} catch (PatchSyntaxException e) {
VcsBalloonProblemNotifier.showOverChangesView(myProject, "Can not import additional patch info: " + e.getMessage(), MessageType.ERROR);
}
}
try {
final ShelvedChangeList shelvedChangeList = ShelveChangesManager.getInstance(myProject).importFilePatches(fileName, allPatches, patchTransitExtensions);
ShelvedChangesViewManager.getInstance(myProject).activateView(shelvedChangeList);
} catch (IOException e) {
throw new VcsException(e);
}
}
}
};
ProgressManager.getInstance().runProcessWithProgressSynchronously(vcsCatchingRunnable, "Import Patch to Shelf", true, myProject);
if (!vcsCatchingRunnable.get().isEmpty()) {
AbstractVcsHelper.getInstance(myProject).showErrors(vcsCatchingRunnable.get(), IMPORT_TO_SHELF);
}
}
use of com.intellij.util.containers.MultiMap in project intellij-community by JetBrains.
the class ConvertInterfaceToClassIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
final PsiClass anInterface = (PsiClass) element.getParent();
final SearchScope searchScope = anInterface.getUseScope();
final Collection<PsiClass> inheritors = ClassInheritorsSearch.search(anInterface, searchScope, false).findAll();
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
inheritors.forEach(aClass -> {
final PsiReferenceList extendsList = aClass.getExtendsList();
if (extendsList == null) {
return;
}
final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements();
if (referenceElements.length > 0) {
final PsiElement target = referenceElements[0].resolve();
if (target instanceof PsiClass && !CommonClassNames.JAVA_LANG_OBJECT.equals(((PsiClass) target).getQualifiedName())) {
conflicts.putValue(aClass, IntentionPowerPackBundle.message("0.already.extends.1.and.will.not.compile.after.converting.2.to.a.class", RefactoringUIUtil.getDescription(aClass, true), RefactoringUIUtil.getDescription(target, true), RefactoringUIUtil.getDescription(anInterface, false)));
}
}
});
final PsiFunctionalExpression functionalExpression = FunctionalExpressionSearch.search(anInterface, searchScope).findFirst();
if (functionalExpression != null) {
final String conflictMessage = ClassPresentationUtil.getFunctionalExpressionPresentation(functionalExpression, true) + " will not compile after converting " + RefactoringUIUtil.getDescription(anInterface, false) + " to a class";
conflicts.putValue(functionalExpression, conflictMessage);
}
final boolean conflictsDialogOK;
if (conflicts.isEmpty()) {
conflictsDialogOK = true;
} else {
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode()) {
throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
}
final ConflictsDialog conflictsDialog = new ConflictsDialog(anInterface.getProject(), conflicts, () -> convertInterfaceToClass(anInterface, inheritors));
conflictsDialogOK = conflictsDialog.showAndGet();
}
if (conflictsDialogOK) {
convertInterfaceToClass(anInterface, inheritors);
}
}
Aggregations