use of com.intellij.util.containers.Queue in project intellij-community by JetBrains.
the class CompilerReferenceReader method getWholeHierarchy.
@Nullable("return null if the class hierarchy contains ambiguous qualified names")
private LightRef.NamedLightRef[] getWholeHierarchy(LightRef.LightClassHierarchyElementDef hierarchyElement, boolean checkBaseClassAmbiguity) throws StorageException {
Set<LightRef.NamedLightRef> result = new THashSet<>();
Queue<LightRef.NamedLightRef> q = new Queue<>(10);
q.addLast(hierarchyElement);
while (!q.isEmpty()) {
LightRef.NamedLightRef curClass = q.pullFirst();
if (result.add(curClass)) {
if (checkBaseClassAmbiguity || curClass != hierarchyElement) {
DefCount count = getDefinitionCount(curClass);
if (count == DefCount.NONE) {
//diagnostic
String baseHierarchyElement = getNameEnumerator().getName(hierarchyElement.getName());
String curHierarchyElement = getNameEnumerator().getName(curClass.getName());
LOG.error("Can't get definition files for: " + curHierarchyElement + " base class: " + baseHierarchyElement);
}
if (count != DefCount.ONE) {
return null;
}
}
myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(curClass).forEach((id, children) -> {
for (LightRef child : children) {
if (child instanceof LightRef.LightClassHierarchyElementDef) {
q.addLast((LightRef.LightClassHierarchyElementDef) child);
}
}
return true;
});
}
}
return result.toArray(new LightRef.NamedLightRef[result.size()]);
}
use of com.intellij.util.containers.Queue in project intellij-community by JetBrains.
the class ModuleWithDependentsScope method buildDependents.
private static Set<Module> buildDependents(Module module) {
Set<Module> result = new THashSet<>();
result.add(module);
Set<Module> processedExporting = new THashSet<>();
ModuleIndex index = getModuleIndex(module.getProject());
Queue<Module> walkingQueue = new Queue<>(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;
}
use of com.intellij.util.containers.Queue in project intellij-community by JetBrains.
the class SuppressActionSequentialTask method suppress.
private void suppress(@NotNull final PsiElement element, @Nullable final CommonProblemDescriptor descriptor, @NotNull final SuppressIntentionAction action, @NotNull final RefEntity refEntity, InspectionToolWrapper wrapper, @NotNull final SuppressableInspectionTreeNode node) {
if (action instanceof SuppressIntentionActionFromFix && !(descriptor instanceof ProblemDescriptor)) {
LOG.info("local suppression fix for specific problem descriptor: " + wrapper.getTool().getClass().getName());
}
final Project project = element.getProject();
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(project).commitAllDocuments();
try {
PsiElement container = null;
if (action instanceof SuppressIntentionActionFromFix) {
container = ((SuppressIntentionActionFromFix) action).getContainer(element);
}
if (container == null) {
container = element;
}
if (action.isAvailable(project, null, element)) {
action.invoke(project, null, element);
}
final Set<GlobalInspectionContextImpl> globalInspectionContexts = ((InspectionManagerEx) InspectionManager.getInstance(element.getProject())).getRunningContexts();
for (GlobalInspectionContextImpl context : globalInspectionContexts) {
context.ignoreElement(wrapper.getTool(), container);
if (descriptor != null) {
context.getPresentation(wrapper).ignoreCurrentElementProblem(refEntity, descriptor);
}
}
final RefElement containerRef = refEntity.getRefManager().getReference(container);
final Set<Object> suppressedNodes = myContext.getView().getSuppressedNodes(wrapper.getShortName());
if (containerRef != null) {
Queue<RefEntity> toIgnoreInView = new Queue<>(1);
toIgnoreInView.addLast(containerRef);
while (!toIgnoreInView.isEmpty()) {
final RefEntity entity = toIgnoreInView.pullFirst();
if (node instanceof ProblemDescriptionNode) {
final CommonProblemDescriptor[] descriptors = myContext.getPresentation(wrapper).getIgnoredElements().get(entity);
if (descriptors != null) {
Collections.addAll(suppressedNodes, descriptors);
}
} else {
suppressedNodes.add(entity);
}
final List<RefEntity> children = entity.getChildren();
for (RefEntity child : children) {
toIgnoreInView.addLast(child);
}
}
}
if (node instanceof ProblemDescriptionNode) {
suppressedNodes.add(descriptor);
}
} catch (IncorrectOperationException e1) {
LOG.error(e1);
}
});
node.removeSuppressActionFromAvailable(mySuppressAction);
}
use of com.intellij.util.containers.Queue in project intellij-community by JetBrains.
the class SingleInspectionProfilePanel method updateOptionsAndDescriptionPanel.
private void updateOptionsAndDescriptionPanel(final TreePath... paths) {
if (myProfile == null || paths == null || paths.length == 0) {
return;
}
final TreePath path = paths[0];
if (path == null)
return;
final List<InspectionConfigTreeNode> nodes = InspectionsAggregationUtil.getInspectionsNodes(paths);
if (!nodes.isEmpty()) {
final InspectionConfigTreeNode singleNode = paths.length == 1 && ((InspectionConfigTreeNode) paths[0].getLastPathComponent()).getDefaultDescriptor() != null ? ContainerUtil.getFirstItem(nodes) : null;
if (singleNode != null) {
final Descriptor descriptor = singleNode.getDefaultDescriptor();
LOG.assertTrue(descriptor != null);
if (descriptor.loadDescription() != null) {
// need this in order to correctly load plugin-supplied descriptions
final Descriptor defaultDescriptor = singleNode.getDefaultDescriptor();
final String description = defaultDescriptor.loadDescription();
try {
if (!readHTML(myBrowser, SearchUtil.markup(toHTML(myBrowser, description, false), myProfileFilter.getFilter()))) {
readHTML(myBrowser, toHTML(myBrowser, "<b>" + UNDER_CONSTRUCTION + "</b>", false));
}
} catch (Throwable t) {
LOG.error("Failed to load description for: " + defaultDescriptor.getToolWrapper().getTool().getClass() + "; description: " + description, t);
}
} else {
readHTML(myBrowser, toHTML(myBrowser, "Can't find inspection description.", false));
}
} else {
readHTML(myBrowser, toHTML(myBrowser, "Multiple inspections are selected. You can edit them as a single inspection.", false));
}
myOptionsPanel.removeAll();
final Project project = myProjectProfileManager.getProject();
final JPanel severityPanel = new JPanel(new GridBagLayout());
final JPanel configPanelAnchor = new JPanel(new GridLayout());
final Set<String> scopesNames = new THashSet<>();
for (final InspectionConfigTreeNode node : nodes) {
final List<ScopeToolState> nonDefaultTools = myProfile.getNonDefaultTools(node.getDefaultDescriptor().getKey().toString(), project);
for (final ScopeToolState tool : nonDefaultTools) {
scopesNames.add(tool.getScopeName());
}
}
final double severityPanelWeightY;
if (scopesNames.isEmpty()) {
final LevelChooserAction severityLevelChooser = new LevelChooserAction(myProfile.getProfileManager().getOwnSeverityRegistrar(), includeDoNotShow(nodes)) {
@Override
protected void onChosen(final HighlightSeverity severity) {
final HighlightDisplayLevel level = HighlightDisplayLevel.find(severity);
for (final InspectionConfigTreeNode node : nodes) {
final HighlightDisplayKey key = node.getDefaultDescriptor().getKey();
final NamedScope scope = node.getDefaultDescriptor().getScope();
final boolean toUpdate = myProfile.getErrorLevel(key, scope, project) != level;
myProfile.setErrorLevel(key, level, null, project);
if (toUpdate)
node.dropCache();
}
myTreeTable.updateUI();
}
};
final HighlightSeverity severity = ScopesAndSeveritiesTable.getSeverity(ContainerUtil.map(nodes, node -> node.getDefaultDescriptor().getState()));
severityLevelChooser.setChosen(severity);
final ScopesChooser scopesChooser = new ScopesChooser(ContainerUtil.map(nodes, node -> node.getDefaultDescriptor()), myProfile, project, null) {
@Override
protected void onScopesOrderChanged() {
myTreeTable.updateUI();
updateOptionsAndDescriptionPanel();
}
@Override
protected void onScopeAdded() {
myTreeTable.updateUI();
updateOptionsAndDescriptionPanel();
}
};
severityPanel.add(new JLabel(InspectionsBundle.message("inspection.severity")), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, JBUI.insets(10, 0), 0, 0));
final JComponent severityLevelChooserComponent = severityLevelChooser.createCustomComponent(severityLevelChooser.getTemplatePresentation());
severityPanel.add(severityLevelChooserComponent, new GridBagConstraints(1, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(10, 0), 0, 0));
final JComponent scopesChooserComponent = scopesChooser.createCustomComponent(scopesChooser.getTemplatePresentation());
severityPanel.add(scopesChooserComponent, new GridBagConstraints(2, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(10, 0), 0, 0));
final JLabel label = new JLabel("", SwingConstants.RIGHT);
severityPanel.add(label, new GridBagConstraints(3, 0, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.BOTH, JBUI.insets(2, 0), 0, 0));
severityPanelWeightY = 0.0;
if (singleNode != null) {
setConfigPanel(configPanelAnchor, myProfile.getToolDefaultState(singleNode.getDefaultDescriptor().getKey().toString(), project));
}
} else {
if (singleNode != null) {
for (final Descriptor descriptor : singleNode.getDescriptors().getNonDefaultDescriptors()) {
descriptor.loadConfig();
}
}
final JTable scopesAndScopesAndSeveritiesTable = new ScopesAndSeveritiesTable(new ScopesAndSeveritiesTable.TableSettings(nodes, myProfile, project) {
@Override
protected void onScopeChosen(@NotNull final ScopeToolState state) {
setConfigPanel(configPanelAnchor, state);
configPanelAnchor.revalidate();
configPanelAnchor.repaint();
}
@Override
protected void onSettingsChanged() {
update(false);
}
@Override
protected void onScopeAdded() {
update(true);
}
@Override
protected void onScopesOrderChanged() {
update(true);
}
@Override
protected void onScopeRemoved(final int scopesCount) {
update(scopesCount == 1);
}
private void update(final boolean updateOptionsAndDescriptionPanel) {
Queue<InspectionConfigTreeNode> q = new Queue<>(nodes.size());
for (InspectionConfigTreeNode node : nodes) {
q.addLast(node);
}
while (!q.isEmpty()) {
final InspectionConfigTreeNode inspectionConfigTreeNode = q.pullFirst();
inspectionConfigTreeNode.dropCache();
final TreeNode parent = inspectionConfigTreeNode.getParent();
if (parent != null && parent.getParent() != null) {
q.addLast((InspectionConfigTreeNode) parent);
}
}
myTreeTable.updateUI();
if (updateOptionsAndDescriptionPanel) {
updateOptionsAndDescriptionPanel();
}
}
});
final ToolbarDecorator wrappedTable = ToolbarDecorator.createDecorator(scopesAndScopesAndSeveritiesTable).disableUpDownActions().setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
final int selectedRow = scopesAndScopesAndSeveritiesTable.getSelectedRow();
final int rowCount = scopesAndScopesAndSeveritiesTable.getRowCount();
return rowCount - 1 != selectedRow;
}
});
final JPanel panel = wrappedTable.createPanel();
panel.setMinimumSize(new Dimension(getMinimumSize().width, 3 * scopesAndScopesAndSeveritiesTable.getRowHeight()));
severityPanel.add(new JBLabel("Severity by Scope"), new GridBagConstraints(0, 0, 1, 1, 1.0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(5, 0, 2, 10), 0, 0));
severityPanel.add(panel, new GridBagConstraints(0, 1, 1, 1, 0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(0, 0, 0, 0), 0, 0));
severityPanelWeightY = 0.3;
}
myOptionsPanel.add(severityPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, severityPanelWeightY, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(0, 2, 0, 0), 0, 0));
if (configPanelAnchor.getComponentCount() != 0) {
configPanelAnchor.setBorder(IdeBorderFactory.createTitledBorder("Options", false, new JBInsets(7, 0, 0, 0)));
}
GuiUtils.enableChildren(myOptionsPanel, isThoughOneNodeEnabled(nodes));
if (configPanelAnchor.getComponentCount() != 0 || scopesNames.isEmpty()) {
myOptionsPanel.add(configPanelAnchor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.insets(0, 2, 0, 0), 0, 0));
}
myOptionsPanel.revalidate();
} else {
initOptionsAndDescriptionPanel();
}
myOptionsPanel.repaint();
}
use of com.intellij.util.containers.Queue in project intellij-community by JetBrains.
the class DebugReflectionUtil method walkObjects.
public static boolean walkObjects(int maxDepth, @NotNull Collection<Object> startRoots, @NotNull final Class<?> lookFor, @NotNull Condition<Object> shouldExamineValue, @NotNull final PairProcessor<Object, BackLink> leakProcessor) {
TIntHashSet visited = new TIntHashSet((int) (10000000 * 0.8));
final Queue<BackLink> toVisit = new Queue<BackLink>(1000000);
for (Object startRoot : startRoots) {
toVisit.addLast(new BackLink(startRoot, null, null));
}
while (true) {
if (toVisit.isEmpty())
return true;
final BackLink backLink = toVisit.pullFirst();
if (backLink.depth > maxDepth)
continue;
Object value = backLink.value;
if (lookFor.isAssignableFrom(value.getClass()) && markLeaked(value) && !leakProcessor.process(value, backLink))
return false;
if (visited.add(System.identityHashCode(value))) {
queueStronglyReferencedValues(toVisit, value, shouldExamineValue, backLink);
}
}
}
Aggregations