@Override public void execute(@NotNull Runnable command) { if (myExecutionTrampoline.get() != null) { myExecutionTrampoline.get().addLast(command); return; } try { final Queue<Runnable> queue = new Queue<Runnable>(2); myExecutionTrampoline.set(queue); queue.addLast(command); while(!queue.isEmpty()) { final Runnable runnable = queue.pullFirst(); runnable.run(); } } finally { myExecutionTrampoline.set(null); } }
private static Set<Module> buildDependents(Module module) { Set<Module> result = new THashSet<Module>(); result.add(module); Set<Module> processedExporting = new THashSet<Module>(); ModuleIndex index = getModuleIndex(module.getProject()); Queue<Module> walkingQueue = new Queue<Module>(10); walkingQueue.addLast(module); while (!walkingQueue.isEmpty()) { Module current = walkingQueue.pullFirst(); processedExporting.add(current); result.addAll(index.plainUsages.get(current)); for (Module dependent : index.exportingUsages.get(current)) { result.add(dependent); if (processedExporting.add(dependent)) { walkingQueue.addLast(dependent); } } } return result; }
private static void renameAll(PsiElement originalElement, UsageInfo[] infos, String newName, String originalName) throws IncorrectOperationException { if (newName.equals(originalName)) return; Queue<PsiReference> queue = new Queue<PsiReference>(infos.length); for (UsageInfo info : infos) { if (info.getElement() == null) continue; PsiReference ref = info.getReference(); if (ref == null) continue; queue.addLast(ref); } while(!queue.isEmpty()) { final PsiReference reference = queue.pullFirst(); final PsiElement oldElement = reference.getElement(); if (!oldElement.isValid() || oldElement == originalElement) continue; final PsiElement newElement = reference.handleElementRename(newName); if (!oldElement.isValid()) { for (PsiReference psiReference : ReferencesSearch.search(originalElement, new LocalSearchScope(newElement), false)) { queue.addLast(psiReference); } } } }
private void fillModules() { Queue<Module> walkingQueue = new Queue<Module>(10); walkingQueue.addLast(myModule); Module[] allModules = ModuleManager.getInstance(myModule.getProject()).getModules(); Set<Module> processed = new THashSet<Module>(); while (!walkingQueue.isEmpty()) { Module current = walkingQueue.pullFirst(); processed.add(current); for (Module dependent : allModules) { for (OrderEntry orderEntry : ModuleRootManager.getInstance(dependent).getOrderEntries()) { if (orderEntry instanceof ModuleOrderEntry && current.equals(((ModuleOrderEntry)orderEntry).getModule())) { myModules.add(dependent); if (!processed.contains(dependent) && ((ModuleOrderEntry)orderEntry).isExported()) { walkingQueue.addLast(dependent); } } } } } }
@Override public void execute(@Nonnull Runnable command) { if (myExecutionTrampoline.get() != null) { myExecutionTrampoline.get().addLast(command); return; } try { final Queue<Runnable> queue = new Queue<Runnable>(2); myExecutionTrampoline.set(queue); queue.addLast(command); while(!queue.isEmpty()) { final Runnable runnable = queue.pullFirst(); runnable.run(); } } finally { myExecutionTrampoline.set(null); } }
/** * @return true if completed, false if "too complex" */ private boolean runDfa(boolean forward, PairFunction<Instruction, BitSet, BitSet> handleState) { Set<Instruction> entryPoints = ContainerUtil.newHashSet(); if (forward) { entryPoints.add(myInstructions[0]); } else { entryPoints.addAll(ContainerUtil.findAll(myInstructions, FilteringIterator.instanceOf(ReturnInstruction.class))); } Queue<InstructionState> queue = new Queue<InstructionState>(10); for (Instruction i : entryPoints) { queue.addLast(new InstructionState(i, new BitSet())); } int limit = myForwardMap.size() * 20; Set<InstructionState> processed = ContainerUtil.newHashSet(); while (!queue.isEmpty()) { int steps = processed.size(); if (steps > limit) { return false; } if (steps % 1024 == 0) { ProgressManager.checkCanceled(); } InstructionState state = queue.pullFirst(); Instruction instruction = state.first; Collection<Instruction> nextInstructions = forward ? myForwardMap.get(instruction) : myBackwardMap.get(instruction); BitSet nextVars = handleState.fun(instruction, state.second); for (Instruction next : nextInstructions) { InstructionState nextState = new InstructionState(next, nextVars); if (processed.add(nextState)) { queue.addLast(nextState); } } } return true; }
private void buildGraph(PsiReference[] refs) { myMarkedNodes.clear(); myExpressionsQueue = new Queue<PsiExpression>(refs.length); myElementToNode.clear(); for (PsiReference ref : refs) { processUsage(ref.getElement()); } processQueue(); markNodes(); spreadMarks(); }
public static List<InspectionConfigTreeNode> getInspectionsNodes(final TreePath[] paths) { final Queue<InspectionConfigTreeNode> q = new Queue<InspectionConfigTreeNode>(paths.length); for (final TreePath path : paths) { if (path != null) { q.addLast((InspectionConfigTreeNode)path.getLastPathComponent()); } } return getInspectionsNodes(q); }
private static List<InspectionConfigTreeNode> getInspectionsNodes(final Queue<InspectionConfigTreeNode> queue) { final Set<InspectionConfigTreeNode> nodes = new THashSet<InspectionConfigTreeNode>(); while (!queue.isEmpty()) { final InspectionConfigTreeNode node = queue.pullFirst(); if (node.getDescriptors() == null) { for (int i = 0; i < node.getChildCount(); i++) { final InspectionConfigTreeNode childNode = (InspectionConfigTreeNode) node.getChildAt(i); queue.addLast(childNode); } } else { nodes.add(node); } } return new ArrayList<InspectionConfigTreeNode>(nodes); }
private static void processParents(@NotNull Processor<SchemaTypeDef> consumer, @NotNull SchemaTypeDef baseType, @NotNull SchemaTypeParentsSearch.SearchParameters parameters) { final Ref<SchemaTypeDef> currentBase = Ref.create(); final Queue<PsiAnchor> queue = new Queue<>(10); final Set<PsiAnchor> processed = ContainerUtil.newTroveSet(); final Processor<SchemaTypeDef> processor = new ReadActionProcessor<SchemaTypeDef>() { @Override public boolean processInReadAction(SchemaTypeDef inheritor) { if (!consumer.process(inheritor)) return false; if (inheritor == null) return false; queue.addLast(PsiAnchor.create(inheritor)); return true; } }; // seed ApplicationManager.getApplication().runReadAction(() -> { queue.addLast(PsiAnchor.create(baseType)); }); // BFS while (!queue.isEmpty()) { ProgressManager.checkCanceled(); final PsiAnchor anchor = queue.pullFirst(); if (!processed.add(anchor)) continue; SchemaTypeDef typeDef = ApplicationManager.getApplication().runReadAction( (Computable<SchemaTypeDef>) () -> (SchemaTypeDef) anchor.retrieve() ); if (typeDef == null) continue; currentBase.set(typeDef); if (!SchemaDirectTypeParentsSearch.search(typeDef).forEach(processor)) return; } }
public LookAheadLexer(final Lexer baseLexer, int capacity) { myBaseLexer = baseLexer; myTypeCache = new Queue<IElementType>(capacity); myEndOffsetCache = new Queue<Integer>(capacity); }
public static List<InspectionConfigTreeNode> getInspectionsNodes(final InspectionConfigTreeNode node) { final Queue<InspectionConfigTreeNode> q = new Queue<InspectionConfigTreeNode>(1); q.addLast(node); return getInspectionsNodes(q); }
/** * @return true if completed, false if "too complex" */ private boolean runDfa(boolean forward, PairFunction<Instruction, BitSet, BitSet> handleState) { Set<Instruction> entryPoints = ContainerUtil.newHashSet(); if(forward) { entryPoints.add(myInstructions[0]); } else { entryPoints.addAll(ContainerUtil.findAll(myInstructions, FilteringIterator.instanceOf(ReturnInstruction.class))); } Queue<InstructionState> queue = new Queue<>(10); for(Instruction i : entryPoints) { queue.addLast(new InstructionState(i, new BitSet())); } int limit = myForwardMap.size() * 20; Set<InstructionState> processed = ContainerUtil.newHashSet(); while(!queue.isEmpty()) { int steps = processed.size(); if(steps > limit) { return false; } if(steps % 1024 == 0) { ProgressManager.checkCanceled(); } InstructionState state = queue.pullFirst(); Instruction instruction = state.first; Collection<Instruction> nextInstructions = forward ? myForwardMap.get(instruction) : myBackwardMap.get(instruction); BitSet nextVars = handleState.fun(instruction, state.second); for(Instruction next : nextInstructions) { InstructionState nextState = new InstructionState(next, nextVars); if(processed.add(nextState)) { queue.addLast(nextState); } } } return true; }