use of com.intellij.xdebugger.attach.XLocalAttachGroup in project intellij-community by JetBrains.
the class AttachToLocalProcessAction method collectAttachItems.
@NotNull
public static List<AttachItem> collectAttachItems(@NotNull final Project project, @NotNull ProcessInfo[] processList, @NotNull ProgressIndicator indicator, @NotNull XLocalAttachDebuggerProvider... providers) {
MultiMap<XLocalAttachGroup, Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> groupWithItems = new MultiMap<>();
UserDataHolderBase dataHolder = new UserDataHolderBase();
for (ProcessInfo eachInfo : processList) {
MultiMap<XLocalAttachGroup, XLocalAttachDebugger> groupsWithDebuggers = new MultiMap<>();
for (XLocalAttachDebuggerProvider eachProvider : providers) {
indicator.checkCanceled();
groupsWithDebuggers.putValues(eachProvider.getAttachGroup(), eachProvider.getAvailableDebuggers(project, eachInfo, dataHolder));
}
for (XLocalAttachGroup eachGroup : groupsWithDebuggers.keySet()) {
Collection<XLocalAttachDebugger> debuggers = groupsWithDebuggers.get(eachGroup);
if (!debuggers.isEmpty()) {
groupWithItems.putValue(eachGroup, Pair.create(eachInfo, new ArrayList<>(debuggers)));
}
}
}
ArrayList<XLocalAttachGroup> sortedGroups = new ArrayList<>(groupWithItems.keySet());
sortedGroups.sort(Comparator.comparingInt(XLocalAttachGroup::getOrder));
List<AttachItem> currentItems = new ArrayList<>();
for (final XLocalAttachGroup eachGroup : sortedGroups) {
List<Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> sortedItems = new ArrayList<>(groupWithItems.get(eachGroup));
sortedItems.sort((a, b) -> eachGroup.compare(project, a.first, b.first, dataHolder));
boolean first = true;
for (Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>> eachItem : sortedItems) {
currentItems.add(new AttachItem(eachGroup, first, eachItem.first, eachItem.second, dataHolder));
first = false;
}
}
List<AttachItem> currentHistoryItems = new ArrayList<>();
List<HistoryItem> history = getHistory(project);
for (int i = history.size() - 1; i >= 0; i--) {
HistoryItem eachHistoryItem = history.get(i);
for (AttachItem eachCurrentItem : currentItems) {
boolean isSuitableItem = eachHistoryItem.getGroup().equals(eachCurrentItem.getGroup()) && eachHistoryItem.getProcessInfo().getCommandLine().equals(eachCurrentItem.getProcessInfo().getCommandLine());
if (!isSuitableItem)
continue;
List<XLocalAttachDebugger> debuggers = eachCurrentItem.getDebuggers();
int selectedDebugger = -1;
for (int j = 0; j < debuggers.size(); j++) {
XLocalAttachDebugger eachDebugger = debuggers.get(j);
if (eachDebugger.getDebuggerDisplayName().equals(eachHistoryItem.getDebuggerName())) {
selectedDebugger = j;
break;
}
}
if (selectedDebugger == -1)
continue;
currentHistoryItems.add(new AttachItem(eachCurrentItem.getGroup(), currentHistoryItems.isEmpty(), XDebuggerBundle.message("xdebugger.attach.toLocal.popup.recent"), eachCurrentItem.getProcessInfo(), debuggers, selectedDebugger, dataHolder));
}
}
currentHistoryItems.addAll(currentItems);
return currentHistoryItems;
}
Aggregations