Search in sources :

Example 1 with Stack

use of com.intellij.util.containers.Stack in project intellij-community by JetBrains.

the class MavenProjectsTree method delete.

private void delete(MavenProjectReader projectReader, List<VirtualFile> files, MavenExplicitProfiles explicitProfiles, MavenGeneralSettings generalSettings, MavenProgressIndicator process) {
    if (files.isEmpty())
        return;
    UpdateContext updateContext = new UpdateContext();
    Stack<MavenProject> updateStack = new Stack<>();
    Set<MavenProject> inheritorsToUpdate = new THashSet<>();
    for (VirtualFile each : files) {
        MavenProject mavenProject = findProject(each);
        if (mavenProject == null)
            return;
        inheritorsToUpdate.addAll(findInheritors(mavenProject));
        doDelete(findAggregator(mavenProject), mavenProject, updateContext);
    }
    inheritorsToUpdate.removeAll(updateContext.deletedProjects);
    for (MavenProject each : inheritorsToUpdate) {
        doUpdate(each, null, false, false, false, explicitProfiles, updateContext, updateStack, projectReader, generalSettings, process);
    }
    updateExplicitProfiles();
    updateContext.fireUpdatedIfNecessary();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) Stack(com.intellij.util.containers.Stack)

Example 2 with Stack

use of com.intellij.util.containers.Stack in project intellij-community by JetBrains.

the class ConvertVariadicParamIntention method findKeywordContainerUsages.

@NotNull
private static <T> List<T> findKeywordContainerUsages(@NotNull PyFunction function, @NotNull BiPredicate<PsiElement, String> usagePredicate) {
    final PyParameter keywordContainer = getKeywordContainer(function);
    final String keywordContainerName = keywordContainer == null ? null : keywordContainer.getName();
    if (keywordContainerName != null) {
        final List<T> result = new ArrayList<T>();
        final Stack<PsiElement> stack = new Stack<PsiElement>();
        for (PyStatement statement : function.getStatementList().getStatements()) {
            stack.push(statement);
            while (!stack.isEmpty()) {
                final PsiElement element = stack.pop();
                if (usagePredicate.test(element, keywordContainerName)) {
                    //noinspection unchecked
                    result.add((T) element);
                } else {
                    for (PsiElement child : element.getChildren()) {
                        stack.push(child);
                    }
                }
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : PsiElement(com.intellij.psi.PsiElement) Stack(com.intellij.util.containers.Stack) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Stack

use of com.intellij.util.containers.Stack in project intellij-community by JetBrains.

the class RemoveUnnecessaryBackslashQuickFix method removeBackSlash.

public static void removeBackSlash(PsiElement parent) {
    if (parent != null) {
        Stack<PsiElement> stack = new Stack<>();
        if (parent instanceof PyParenthesizedExpression)
            stack.push(((PyParenthesizedExpression) parent).getContainedExpression());
        else
            stack.push(parent);
        while (!stack.isEmpty()) {
            PsiElement el = stack.pop();
            PsiWhiteSpace[] children = PsiTreeUtil.getChildrenOfType(el, PsiWhiteSpace.class);
            if (children != null) {
                for (PsiWhiteSpace ws : children) {
                    if (ws.getText().contains("\\")) {
                        ws.delete();
                    }
                }
            }
            for (PsiElement psiElement : el.getChildren()) {
                stack.push(psiElement);
            }
        }
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) Stack(com.intellij.util.containers.Stack) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 4 with Stack

use of com.intellij.util.containers.Stack in project intellij-community by JetBrains.

the class DfsUtil method walk.

/*
   * Depth-first walk for a graph. For each node, walks both into upward and downward siblings.
   * Tries to preserve direction of travel: when a node is entered from up-sibling, goes to the down-siblings first.
   * Then goes to the other up-siblings.
   * And when a node is entered from down-sibling, goes to the up-siblings first.
   * Then goes to the other down-siblings.
   * When a node is entered the first time, enterNode is called.
   * When a node is passes in the same direction, exitNode is called.
   * Nothing is called when a all the siblings of the node are visited.
   */
public static void walk(@NotNull LiteLinearGraph graph, int start, @NotNull NodeVisitor visitor) {
    BitSetFlags visited = new BitSetFlags(graph.nodesCount(), false);
    BitSetFlags visitedInSameDirection = new BitSetFlags(graph.nodesCount(), false);
    Stack<Pair<Integer, Boolean>> stack = new Stack<>();
    // commit + direction of travel
    stack.push(new Pair<>(start, true));
    outer: while (!stack.empty()) {
        int currentNode = stack.peek().first;
        boolean down = stack.peek().second;
        if (!visited.get(currentNode)) {
            visited.set(currentNode, true);
            visitor.enterNode(currentNode);
        }
        for (int nextNode : graph.getNodes(currentNode, down ? LiteLinearGraph.NodeFilter.DOWN : LiteLinearGraph.NodeFilter.UP)) {
            if (!visited.get(nextNode)) {
                stack.push(new Pair<>(nextNode, down));
                continue outer;
            }
        }
        if (!visitedInSameDirection.get(currentNode)) {
            visitedInSameDirection.set(currentNode, true);
            visitor.exitNode(currentNode);
        }
        for (int nextNode : graph.getNodes(currentNode, down ? LiteLinearGraph.NodeFilter.UP : LiteLinearGraph.NodeFilter.DOWN)) {
            if (!visited.get(nextNode)) {
                stack.push(new Pair<>(nextNode, !down));
                continue outer;
            }
        }
        stack.pop();
    }
}
Also used : BitSetFlags(com.intellij.vcs.log.graph.utils.impl.BitSetFlags) Stack(com.intellij.util.containers.Stack) IntStack(com.intellij.util.containers.IntStack) Pair(com.intellij.openapi.util.Pair)

Example 5 with Stack

use of com.intellij.util.containers.Stack in project intellij-community by JetBrains.

the class Divider method divideInsideAndOutsideInOneRoot.

private static void divideInsideAndOutsideInOneRoot(@NotNull PsiFile root, @NotNull TextRange restrictRange, @NotNull TextRange priorityRange, @NotNull List<PsiElement> inside, @NotNull List<ProperTextRange> insideRanges, @NotNull List<PsiElement> outside, @NotNull List<ProperTextRange> outsideRanges, @NotNull List<PsiElement> outParents, @NotNull List<ProperTextRange> outParentRanges, boolean includeParents) {
    int startOffset = restrictRange.getStartOffset();
    int endOffset = restrictRange.getEndOffset();
    final Condition<PsiElement>[] filters = Extensions.getExtensions(CollectHighlightsUtil.EP_NAME);
    final TIntStack starts = new TIntStack(STARTING_TREE_HEIGHT);
    starts.push(startOffset);
    final Stack<PsiElement> elements = new Stack<>(STARTING_TREE_HEIGHT);
    final Stack<PsiElement> children = new Stack<>(STARTING_TREE_HEIGHT);
    PsiElement element = root;
    PsiElement child = HAVE_TO_GET_CHILDREN;
    int offset = 0;
    while (true) {
        ProgressManager.checkCanceled();
        for (Condition<PsiElement> filter : filters) {
            if (!filter.value(element)) {
                assert child == HAVE_TO_GET_CHILDREN;
                // do not want to process children
                child = null;
                break;
            }
        }
        boolean startChildrenVisiting;
        if (child == HAVE_TO_GET_CHILDREN) {
            startChildrenVisiting = true;
            child = element.getFirstChild();
        } else {
            startChildrenVisiting = false;
        }
        if (child == null) {
            if (startChildrenVisiting) {
                // leaf element
                offset += element.getTextLength();
            }
            int start = starts.pop();
            if (startOffset <= start && offset <= endOffset) {
                if (priorityRange.containsRange(start, offset)) {
                    inside.add(element);
                    insideRanges.add(new ProperTextRange(start, offset));
                } else {
                    outside.add(element);
                    outsideRanges.add(new ProperTextRange(start, offset));
                }
            }
            if (elements.isEmpty())
                break;
            element = elements.pop();
            child = children.pop();
        } else {
            // composite element
            if (offset > endOffset)
                break;
            children.push(child.getNextSibling());
            starts.push(offset);
            elements.push(element);
            element = child;
            child = HAVE_TO_GET_CHILDREN;
        }
    }
    if (includeParents) {
        PsiElement parent = !outside.isEmpty() ? outside.get(outside.size() - 1) : !inside.isEmpty() ? inside.get(inside.size() - 1) : CollectHighlightsUtil.findCommonParent(root, startOffset, endOffset);
        while (parent != null && !(parent instanceof PsiFile)) {
            parent = parent.getParent();
            if (parent != null) {
                outParents.add(parent);
                TextRange textRange = parent.getTextRange();
                assert textRange != null : "Text range for " + parent + " is null. " + parent.getClass() + "; root: " + root + ": " + root.getVirtualFile();
                outParentRanges.add(ProperTextRange.create(textRange));
            }
        }
    }
    assert inside.size() == insideRanges.size();
    assert outside.size() == outsideRanges.size();
    assert outParents.size() == outParentRanges.size();
}
Also used : Condition(com.intellij.openapi.util.Condition) ProperTextRange(com.intellij.openapi.util.ProperTextRange) PsiFile(com.intellij.psi.PsiFile) ProperTextRange(com.intellij.openapi.util.ProperTextRange) TextRange(com.intellij.openapi.util.TextRange) TIntStack(gnu.trove.TIntStack) PsiElement(com.intellij.psi.PsiElement) TIntStack(gnu.trove.TIntStack) Stack(com.intellij.util.containers.Stack)

Aggregations

Stack (com.intellij.util.containers.Stack)20 IElementType (com.intellij.psi.tree.IElementType)5 FileTypeExtensionPoint (com.intellij.openapi.fileTypes.FileTypeExtensionPoint)4 PsiElement (com.intellij.psi.PsiElement)4 TIntStack (gnu.trove.TIntStack)3 NotNull (org.jetbrains.annotations.NotNull)3 Condition (com.intellij.openapi.util.Condition)2 Pair (com.intellij.openapi.util.Pair)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiMethod (com.intellij.psi.PsiMethod)2 THashSet (gnu.trove.THashSet)2 ArrayList (java.util.ArrayList)2 Node (com.android.tools.idea.ui.FileTreeModel.Node)1 CustomHighlightInfoHolder (com.intellij.codeInsight.daemon.impl.analysis.CustomHighlightInfoHolder)1 HighlightInfoHolder (com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder)1 DebuggerManagerThreadImpl (com.intellij.debugger.engine.DebuggerManagerThreadImpl)1 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)1 PairedBraceMatcher (com.intellij.lang.PairedBraceMatcher)1 PsiBuilder (com.intellij.lang.PsiBuilder)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1