use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class ScopeTreeViewPanel method getSelectedPsiElements.
@NotNull
private PsiElement[] getSelectedPsiElements() {
final TreePath[] treePaths = myTree.getSelectionPaths();
if (treePaths != null) {
Set<PsiElement> result = new HashSet<>();
for (TreePath path : treePaths) {
final Object component = path.getLastPathComponent();
if (component instanceof PackageDependenciesNode) {
PackageDependenciesNode node = (PackageDependenciesNode) component;
final PsiElement psiElement = node.getPsiElement();
if (psiElement != null && psiElement.isValid()) {
result.add(psiElement);
}
}
}
return PsiUtilCore.toPsiElementArray(result);
}
return PsiElement.EMPTY_ARRAY;
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class SafeDeleteHandler method invoke.
public static void invoke(final Project project, PsiElement[] elements, @Nullable Module module, boolean checkDelegates, @Nullable final Runnable successRunnable) {
for (PsiElement element : elements) {
if (!SafeDeleteProcessor.validElement(element)) {
return;
}
}
final PsiElement[] temptoDelete = PsiTreeUtil.filterAncestors(elements);
Set<PsiElement> elementsSet = new HashSet<>(Arrays.asList(temptoDelete));
Set<PsiElement> fullElementsSet = new LinkedHashSet<>();
if (checkDelegates) {
for (PsiElement element : temptoDelete) {
boolean found = false;
for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
if (delegate.handlesElement(element)) {
found = true;
Collection<? extends PsiElement> addElements = delegate instanceof SafeDeleteProcessorDelegateBase ? ((SafeDeleteProcessorDelegateBase) delegate).getElementsToSearch(element, module, elementsSet) : delegate.getElementsToSearch(element, elementsSet);
if (addElements == null)
return;
fullElementsSet.addAll(addElements);
break;
}
}
if (!found) {
fullElementsSet.add(element);
}
}
} else {
ContainerUtil.addAll(fullElementsSet, temptoDelete);
}
if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, fullElementsSet, true))
return;
final PsiElement[] elementsToDelete = PsiUtilCore.toPsiElementArray(fullElementsSet);
if (ApplicationManager.getApplication().isUnitTestMode()) {
RefactoringSettings settings = RefactoringSettings.getInstance();
SafeDeleteProcessor.createInstance(project, null, elementsToDelete, settings.SAFE_DELETE_SEARCH_IN_COMMENTS, settings.SAFE_DELETE_SEARCH_IN_NON_JAVA, true).run();
if (successRunnable != null)
successRunnable.run();
} else {
final SafeDeleteDialog.Callback callback = new SafeDeleteDialog.Callback() {
@Override
public void run(final SafeDeleteDialog dialog) {
SafeDeleteProcessor.createInstance(project, () -> {
if (successRunnable != null) {
successRunnable.run();
}
dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
}, elementsToDelete, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true).run();
}
};
SafeDeleteDialog dialog = new SafeDeleteDialog(project, elementsToDelete, callback);
dialog.show();
}
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class AbstractTreeUi method getChildrenFor.
//todo [kirillk] temporary consistency check
private Object[] getChildrenFor(final Object element) {
final Ref<Object[]> passOne = new Ref<>();
try (LockToken ignored = acquireLock()) {
execute(new TreeRunnable("AbstractTreeUi.getChildrenFor") {
@Override
public void perform() {
passOne.set(getTreeStructure().getChildElements(element));
}
});
} catch (IndexNotReadyException e) {
warnOnIndexNotReady(e);
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
if (!Registry.is("ide.tree.checkStructure"))
return passOne.get();
final Object[] passTwo = getTreeStructure().getChildElements(element);
final HashSet<Object> two = new HashSet<>(Arrays.asList(passTwo));
if (passOne.get().length != passTwo.length) {
LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
} else {
for (Object eachInOne : passOne.get()) {
if (!two.contains(eachInOne)) {
LOG.error("AbstractTreeStructure.getChildren() must either provide same objects or new objects but with correct hashCode() and equals() methods. Wrong parent element=" + element);
break;
}
}
}
return passOne.get();
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class SearchResults method updateExcluded.
private void updateExcluded() {
Set<RangeMarker> invalid = new HashSet<>();
for (RangeMarker marker : myExcluded) {
if (!marker.isValid()) {
invalid.add(marker);
marker.dispose();
}
}
myExcluded.removeAll(invalid);
}
use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.
the class GenericInlineHandler method invoke.
public static boolean invoke(final PsiElement element, @Nullable Editor editor, final InlineHandler languageSpecific) {
final PsiReference invocationReference = editor != null ? TargetElementUtil.findReference(editor) : null;
final InlineHandler.Settings settings = languageSpecific.prepareInlineElement(element, editor, invocationReference != null);
if (settings == null || settings == InlineHandler.Settings.CANNOT_INLINE_SETTINGS) {
return settings != null;
}
final Collection<? extends PsiReference> allReferences;
if (settings.isOnlyOneReferenceToInline()) {
allReferences = Collections.singleton(invocationReference);
} else {
final Ref<Collection<? extends PsiReference>> usagesRef = new Ref<>();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> usagesRef.set(ReferencesSearch.search(element).findAll()), "Find Usages", false, element.getProject());
allReferences = usagesRef.get();
}
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final Map<Language, InlineHandler.Inliner> inliners = initializeInliners(element, settings, allReferences);
for (PsiReference reference : allReferences) {
collectConflicts(reference, element, inliners, conflicts);
}
final Project project = element.getProject();
if (!conflicts.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
} else {
final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
if (!conflictsDialog.showAndGet()) {
return true;
}
}
}
HashSet<PsiElement> elements = new HashSet<>();
for (PsiReference reference : allReferences) {
PsiElement refElement = reference.getElement();
if (refElement != null) {
elements.add(refElement);
}
}
if (!settings.isOnlyOneReferenceToInline()) {
elements.add(element);
}
if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, elements, true)) {
return true;
}
ApplicationManager.getApplication().runWriteAction(() -> {
final String subj = element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : "element";
CommandProcessor.getInstance().executeCommand(project, () -> {
final PsiReference[] references = sortDepthFirstRightLeftOrder(allReferences);
final UsageInfo[] usages = new UsageInfo[references.length];
for (int i = 0; i < references.length; i++) {
usages[i] = new UsageInfo(references[i]);
}
for (UsageInfo usage : usages) {
inlineReference(usage, element, inliners);
}
if (!settings.isOnlyOneReferenceToInline()) {
languageSpecific.removeDefinition(element, settings);
}
}, RefactoringBundle.message("inline.command", StringUtil.notNullize(subj, "<nameless>")), null);
});
return true;
}
Aggregations