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();
}
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();
}
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);
}
}
}
}
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();
}
}
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();
}
Aggregations