Java Code Examples for com.intellij.util.containers.ContainerUtil#findInstance()

The following examples show how to use com.intellij.util.containers.ContainerUtil#findInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DuplexConsoleView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AnAction[] createConsoleActions() {
  List<AnAction> actions = Lists.newArrayList();
  actions.addAll(
          mergeConsoleActions(Arrays.asList(myPrimaryConsoleView.createConsoleActions()), Arrays.asList(mySecondaryConsoleView.createConsoleActions())));
  actions.add(mySwitchConsoleAction);

  LanguageConsoleView langConsole = ContainerUtil.findInstance(Arrays.asList(myPrimaryConsoleView, mySecondaryConsoleView), LanguageConsoleView.class);
  ConsoleHistoryController controller = langConsole != null ? ConsoleHistoryController.getController(langConsole) : null;
  if (controller != null) actions.add(controller.getBrowseHistory());

  return ArrayUtil.toObjectArray(actions, AnAction.class);
}
 
Example 2
Source File: ChooseItemAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean hasTemplatePrefix(LookupImpl lookup, char shortcutChar) {
  lookup.refreshUi(false, false); // to bring the list model up to date

  CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
  if (completion == null || !completion.isAutopopupCompletion()) {
    return false;
  }

  if (lookup.isSelectionTouched()) {
    return false;
  }

  final PsiFile file = lookup.getPsiFile();
  if (file == null) return false;

  final Editor editor = lookup.getEditor();
  final int offset = editor.getCaretModel().getOffset();
  PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());

  final LiveTemplateLookupElement liveTemplateLookup = ContainerUtil.findInstance(lookup.getItems(), LiveTemplateLookupElement.class);
  if (liveTemplateLookup == null || !liveTemplateLookup.sudden) {
    // Lookup doesn't contain sudden live templates. It means that
    // - there are no live template with given key:
    //    in this case we should find live template with appropriate prefix (custom live templates doesn't participate in this action).
    // - completion provider worked too long:
    //    in this case we should check custom templates that provides completion lookup.
    if (LiveTemplateCompletionContributor.customTemplateAvailableAndHasCompletionItem(shortcutChar, editor, file, offset)) {
      return true;
    }

    List<TemplateImpl> templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, false);
    TemplateImpl template = LiveTemplateCompletionContributor.findFullMatchedApplicableTemplate(editor, offset, templates);
    if (template != null && shortcutChar == TemplateSettings.getInstance().getShortcutChar(template)) {
      return true;
    }
    return false;
  }

  return liveTemplateLookup.getTemplateShortcut() == shortcutChar;
}
 
Example 3
Source File: MultipleChangeListBrowser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private ChangesBrowserUnversionedFilesNode findUnversionedFilesNode() {
  //noinspection unchecked
  Enumeration<TreeNode> nodes = myViewer.getRoot().breadthFirstEnumeration();

  return ContainerUtil.findInstance(ContainerUtil.iterate(nodes), ChangesBrowserUnversionedFilesNode.class);
}
 
Example 4
Source File: AbstractVcsHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showAnnotation(FileAnnotation annotation, VirtualFile file, AbstractVcs vcs, int line) {
  TextEditor textFileEditor;
  FileEditor fileEditor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
  if (fileEditor instanceof TextEditor) {
    textFileEditor = ((TextEditor)fileEditor);
  }
  else {
    FileEditor[] editors = FileEditorManager.getInstance(myProject).getEditors(file);
    textFileEditor = ContainerUtil.findInstance(editors, TextEditor.class);
  }

  Editor editor;
  if (textFileEditor != null) {
    editor = textFileEditor.getEditor();
  }
  else {
    OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(myProject, file, line, 0);
    editor = FileEditorManager.getInstance(myProject).openTextEditor(openFileDescriptor, true);
  }

  if (editor == null) {
    Messages.showMessageDialog(VcsBundle.message("message.text.cannot.open.editor", file.getPresentableUrl()),
                               VcsBundle.message("message.title.cannot.open.editor"), Messages.getInformationIcon());
    return;
  }

  AnnotateToggleAction.doAnnotate(editor, myProject, file, annotation, vcs);
}
 
Example 5
Source File: RootIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private ModuleSourceOrderEntry getModuleSourceEntry(@Nonnull List<VirtualFile> hierarchy, @Nonnull VirtualFile moduleContentRoot, @Nonnull MultiMap<VirtualFile, OrderEntry> libClassRootEntries) {
  Module module = contentRootOf.get(moduleContentRoot);
  for (VirtualFile root : hierarchy) {
    if (sourceRootOf.get(root).contains(module)) {
      return ContainerUtil.findInstance(ModuleRootManager.getInstance(module).getOrderEntries(), ModuleSourceOrderEntry.class);
    }
    if (libClassRootEntries.containsKey(root)) {
      return null;
    }
  }
  return null;
}
 
Example 6
Source File: XEvaluateInConsoleFromEditorActionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ConsoleExecuteAction getConsoleExecuteAction(@Nullable ConsoleView consoleView) {
  if (!(consoleView instanceof LanguageConsoleView)) {
    return null;
  }

  List<AnAction> actions = ActionUtil.getActions(((LanguageConsoleView)consoleView).getConsoleEditor().getComponent());
  ConsoleExecuteAction action = ContainerUtil.findInstance(actions, ConsoleExecuteAction.class);
  return action == null || !action.isEnabled() ? null : action;
}
 
Example 7
Source File: MessageBusImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void rethrowExceptions(@Nullable List<? extends Throwable> exceptions) {
  if (exceptions == null) return;

  ProcessCanceledException pce = ContainerUtil.findInstance(exceptions, ProcessCanceledException.class);
  if (pce != null) throw pce;

  CompoundRuntimeException.throwIfNotEmpty(exceptions);
}
 
Example 8
Source File: ObjectTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void handleExceptions(@Nonnull List<? extends Throwable> exceptions) {
  if (!exceptions.isEmpty()) {
    for (Throwable exception : exceptions) {
      if (!(exception instanceof ProcessCanceledException)) {
        getLogger().error(exception);
      }
    }

    ProcessCanceledException pce = ContainerUtil.findInstance(exceptions, ProcessCanceledException.class);
    if (pce != null) {
      throw pce;
    }
  }
}
 
Example 9
Source File: VcsLogPersistentIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Set<Integer> filter(@Nonnull List<VcsLogDetailsFilter> detailsFilters) {
  VcsLogTextFilter textFilter = ContainerUtil.findInstance(detailsFilters, VcsLogTextFilter.class);
  VcsLogUserFilter userFilter = ContainerUtil.findInstance(detailsFilters, VcsLogUserFilter.class);
  VcsLogStructureFilter pathFilter = ContainerUtil.findInstance(detailsFilters, VcsLogStructureFilter.class);

  TIntHashSet filteredByMessage = null;
  if (textFilter != null) {
    filteredByMessage = filterMessages(textFilter);
  }

  TIntHashSet filteredByUser = null;
  if (userFilter != null) {
    Set<VcsUser> users = ContainerUtil.newHashSet();
    for (VirtualFile root : myRoots) {
      users.addAll(userFilter.getUsers(root));
    }

    filteredByUser = filterUsers(users);
  }

  TIntHashSet filteredByPath = null;
  if (pathFilter != null) {
    filteredByPath = filterPaths(pathFilter.getFiles());
  }

  return TroveUtil.intersect(filteredByMessage, filteredByPath, filteredByUser);
}
 
Example 10
Source File: KeymapUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getFirstKeyboardShortcutText(@Nonnull AnAction action) {
  Shortcut[] shortcuts = action.getShortcutSet().getShortcuts();
  KeyboardShortcut shortcut = ContainerUtil.findInstance(shortcuts, KeyboardShortcut.class);
  return shortcut == null ? "" : getShortcutText(shortcut);
}
 
Example 11
Source File: HaskellApplicationConfigurationType.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
public static HaskellApplicationConfigurationType getInstance() {
    return ContainerUtil.findInstance(Extensions.getExtensions(CONFIGURATION_TYPE_EP), HaskellApplicationConfigurationType.class);
}
 
Example 12
Source File: KeymapUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getPreferredShortcutText(@Nonnull Shortcut[] shortcuts) {
  KeyboardShortcut shortcut = ContainerUtil.findInstance(shortcuts, KeyboardShortcut.class);
  return shortcut != null ? getShortcutText(shortcut) : shortcuts.length > 0 ? getShortcutText(shortcuts[0]) : "";
}
 
Example 13
Source File: KeymapUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getFirstKeyboardShortcutText(@Nonnull ShortcutSet set) {
  Shortcut[] shortcuts = set.getShortcuts();
  KeyboardShortcut shortcut = ContainerUtil.findInstance(shortcuts, KeyboardShortcut.class);
  return shortcut == null ? "" : getShortcutText(shortcut);
}
 
Example 14
Source File: KeymapUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getFirstKeyboardShortcutText(@Nonnull String actionId) {
  Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionId);
  KeyboardShortcut shortcut = ContainerUtil.findInstance(shortcuts, KeyboardShortcut.class);
  return shortcut == null ? "" : getShortcutText(shortcut);
}
 
Example 15
Source File: XQueryRunConfigurationType.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public static XQueryRunConfigurationType getInstance() {
    return ContainerUtil.findInstance(Extensions.getExtensions(CONFIGURATION_TYPE_EP),
            XQueryRunConfigurationType.class);
}
 
Example 16
Source File: HaxeRunConfigurationType.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public static HaxeRunConfigurationType getInstance() {
  return ContainerUtil.findInstance(Extensions.getExtensions(CONFIGURATION_TYPE_EP), HaxeRunConfigurationType.class);
}
 
Example 17
Source File: GaugeRunTaskConfigurationType.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
public GaugeRunTaskConfigurationType getInstance() {
    return ContainerUtil.findInstance(Extensions.getExtensions(CONFIGURATION_TYPE_EP), GaugeRunTaskConfigurationType.class);
}
 
Example 18
Source File: HaskellTestConfigurationType.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
public static HaskellTestConfigurationType getInstance() {
    return ContainerUtil.findInstance(Extensions.getExtensions(CONFIGURATION_TYPE_EP), HaskellTestConfigurationType.class);
}