EA-351178 - SOE: MarkedDescriptorTree.addChild

GitOrigin-RevId: fec12db1d2f850a1f00eeff0923620b747153610
This commit is contained in:
Egor Ushakov
2022-07-22 15:34:40 +02:00
committed by intellij-monorepo-bot
parent 3f0ac8e5c7
commit 6a90e6b4d3

View File

@@ -1,26 +1,15 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.debugger.ui.impl.watch;
import com.intellij.debugger.ui.tree.NodeDescriptor;
import com.intellij.openapi.util.Pair;
import one.util.streamex.StreamEx;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import static com.intellij.util.ObjectUtils.consumeIfNotNull;
import static com.intellij.util.containers.ContainerUtil.iterateBackward;
import static com.intellij.util.containers.ContainerUtil.map;
public class DescriptorTree {
private final HashMap<NodeDescriptor, List<NodeDescriptor>> myChildrenMap = new HashMap<>();
@@ -76,15 +65,14 @@ public class DescriptorTree {
}
public void dfst(DFSTWalker walker) {
dfstImpl(null, myRootChildren, walker);
}
private void dfstImpl(NodeDescriptor descriptor, List<NodeDescriptor> children, DFSTWalker walker) {
if(children != null) {
for (NodeDescriptor child : children) {
walker.visit(descriptor, child);
dfstImpl(child, myChildrenMap.get(child), walker);
}
ArrayDeque<Pair<NodeDescriptor, NodeDescriptor>> stack =
StreamEx.of(myRootChildren).map(e -> new Pair<NodeDescriptor, NodeDescriptor>(null, e)).toCollection(ArrayDeque::new);
while (!stack.isEmpty()) {
Pair<NodeDescriptor, NodeDescriptor> nodeInfo = stack.pop();
NodeDescriptor child = nodeInfo.second;
walker.visit(nodeInfo.first, child);
consumeIfNotNull(myChildrenMap.get(child),
children -> iterateBackward(map(children, e -> new Pair<>(child, e))).forEach(stack::push));
}
}