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

The following examples show how to use com.intellij.util.containers.ContainerUtil#getFirstItem() . 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: XDebuggerTreeState.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public NodeInfo getChild(XNamedTreeNode node) {
  String name = node.getName();
  if (myChildren == null) {
    return null;
  }
  List<NodeInfo> infos = (List<NodeInfo>)myChildren.get(name);
  if (infos.size() > 1) {
    TreeNode parent = node.getParent();
    if (parent instanceof XDebuggerTreeNode) {
      int idx = 0;
      for (XDebuggerTreeNode treeNode : ((XDebuggerTreeNode)parent).getLoadedChildren()) {
        if (treeNode == node) {
          break;
        }
        if (treeNode instanceof XNamedTreeNode && Comparing.equal(((XNamedTreeNode)treeNode).getName(), name)) {
          idx++;
        }
      }
      if (idx < infos.size()) {
        return infos.get(idx);
      }
    }
  }
  return ContainerUtil.getFirstItem(infos);
}
 
Example 2
Source File: StubUpdatingForwardIndexAccessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public InputDataDiffBuilder<Integer, SerializedStubTree> getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException {
  Ref<Map<Integer, SerializedStubTree>> dataRef = Ref.create();
  StorageException[] ex = {null};
  ProgressManager.getInstance().executeNonCancelableSection(() -> {
    try {
      dataRef.set(myIndex.getIndexedFileData(inputId));
    }
    catch (StorageException e) {
      ex[0] = e;
    }
  });
  if (ex[0] != null) {
    throw new IOException(ex[0]);
  }
  Map<Integer, SerializedStubTree> data = dataRef.get();
  SerializedStubTree tree = ContainerUtil.isEmpty(data) ? null : ContainerUtil.getFirstItem(data.values());
  if (tree != null) {
    tree.restoreIndexedStubs(StubForwardIndexExternalizer.IdeStubForwardIndexesExternalizer.INSTANCE);
  }
  return new StubCumulativeInputDiffBuilder(inputId, tree);
}
 
Example 3
Source File: ExpirationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
static Expiration composeExpiration(Collection<? extends Expiration> expirations) {
  int size = expirations.size();
  if (size == 0) {
    return null;
  }
  else if (size == 1) {
    return ContainerUtil.getFirstItem(expirations);
  }
  else {
    Job job = new Job();

    for (Expiration expiration : expirations) {
      cancelJobOnExpiration(expiration, job);
    }

    return new JobExpiration(job);
  }
}
 
Example 4
Source File: LiveTemplateCompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TemplateImpl findFullMatchedApplicableTemplate(@Nonnull Editor editor,
                                                             int offset,
                                                             @Nonnull Collection<TemplateImpl> availableTemplates) {
  Map<TemplateImpl, String> templates = filterTemplatesByPrefix(availableTemplates, editor, offset, true, false);
  if (templates.size() == 1) {
    TemplateImpl template = ContainerUtil.getFirstItem(templates.keySet());
    if (template != null) {
      return template;
    }
  }
  return null;
}
 
Example 5
Source File: UnusedNamespaceDeclarationInspectionTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void testRemoveUnusedNamespaceDeclarationQuickFix() {
    final String testName = getTestName();

    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends LocalInspectionTool>>();
    inspections.add(UnusedNamespaceDeclarationInspection.class);
    myFixture.enableInspections(inspections);
    myFixture.configureByFile(String.format("%s.xq", testName));

    List<IntentionAction> availableIntentions = myFixture.filterAvailableIntentions(REMOVE_UNUSED_NAMESPACE_DECLARATION_QUICKFIX_NAME);
    IntentionAction action = ContainerUtil.getFirstItem(availableIntentions);
    assertNotNull(action);
    myFixture.launchAction(action);

    myFixture.checkResultByFile(String.format("%s_after.xq", testName));
}
 
Example 6
Source File: FileAnnotation.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static PreviousFileRevisionProvider createDefaultPreviousFileRevisionProvider(@Nonnull FileAnnotation annotation) {
  List<VcsFileRevision> revisions = annotation.getRevisions();
  if (revisions == null) return null;

  Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>();
  for (int i = 0; i < revisions.size(); i++) {
    VcsFileRevision revision = revisions.get(i);
    VcsFileRevision previousRevision = i + 1 < revisions.size() ? revisions.get(i + 1) : null;
    map.put(revision.getRevisionNumber(), previousRevision);
  }

  List<VcsFileRevision> lineToRevision = new ArrayList<>(annotation.getLineCount());
  for (int i = 0; i < annotation.getLineCount(); i++) {
    lineToRevision.add(map.get(annotation.getLineRevisionNumber(i)));
  }

  VcsFileRevision lastRevision = ContainerUtil.getFirstItem(revisions);

  return new PreviousFileRevisionProvider() {
    @javax.annotation.Nullable
    @Override
    public VcsFileRevision getPreviousRevision(int lineNumber) {
      LOG.assertTrue(lineNumber >= 0 && lineNumber < lineToRevision.size());
      return lineToRevision.get(lineNumber);
    }

    @javax.annotation.Nullable
    @Override
    public VcsFileRevision getLastRevision() {
      return lastRevision;
    }
  };
}
 
Example 7
Source File: ProjectLoadingErrorsNotifierImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getInvalidElementsString(ConfigurationErrorType type, Collection<ConfigurationErrorDescription> descriptions) {
  if (descriptions.size() == 1) {
    final ConfigurationErrorDescription description = ContainerUtil.getFirstItem(descriptions);
    return type.getElementKind() + " <b>" + description.getElementName() + "</b>";
  }

  return descriptions.size() + " " + StringUtil.pluralize(type.getElementKind());
}
 
Example 8
Source File: BranchPopupBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Groups prepareGroups(@Nonnull VcsLogDataPack dataPack,
                                    @Nullable Collection<VirtualFile> visibleRoots,
                                    @Nullable List<List<String>> recentItems) {
  Groups filteredGroups = new Groups();
  Collection<VcsRef> allRefs = dataPack.getRefs().getBranches();
  for (Map.Entry<VirtualFile, Set<VcsRef>> entry : VcsLogUtil.groupRefsByRoot(allRefs).entrySet()) {
    VirtualFile root = entry.getKey();
    if (visibleRoots != null && !visibleRoots.contains(root)) continue;
    Collection<VcsRef> refs = entry.getValue();
    VcsLogProvider provider = dataPack.getLogProviders().get(root);
    VcsLogRefManager refManager = provider.getReferenceManager();
    List<RefGroup> refGroups = refManager.groupForBranchFilter(refs);

    putActionsForReferences(refGroups, filteredGroups);
  }

  if (recentItems != null) {
    for (List<String> recentItem : recentItems) {
      if (recentItem.size() == 1) {
        final String item = ContainerUtil.getFirstItem(recentItem);
        if (filteredGroups.singletonGroups.contains(item) ||
            ContainerUtil.find(filteredGroups.expandedGroups.values(), strings -> strings.contains(item)) != null) {
          continue;
        }
      }
      filteredGroups.recentGroups.add(recentItem);
    }
  }

  return filteredGroups;
}
 
Example 9
Source File: DeployToServerConfigurationType.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onNewConfigurationCreated(@Nonnull RunConfiguration configuration) {
  LocalServerRunConfiguration deployConfiguration = (LocalServerRunConfiguration)configuration;

  if (deployConfiguration.getDeploymentSource() == null) {
    List<DeploymentSource> sources = deployConfiguration.getDeploymentConfigurator().getAvailableDeploymentSources();
    DeploymentSource source = ContainerUtil.getFirstItem(sources);
    if (source != null) {
      deployConfiguration.setDeploymentSource(source);
      DeploymentSourceType type = source.getType();
      type.setBuildBeforeRunTask(configuration, source);
    }
  }
}
 
Example 10
Source File: LivePreview.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RangeHighlighter addHighlighter(int startOffset, int endOffset, @Nonnull TextAttributes attributes) {
  Project project = mySearchResults.getProject();
  if (project == null || project.isDisposed()) return null;
  List<RangeHighlighter> sink = new ArrayList<>();
  HighlightManager.getInstance(project).addRangeHighlight(mySearchResults.getEditor(), startOffset, endOffset, attributes, false, sink);
  RangeHighlighter result = ContainerUtil.getFirstItem(sink);
  if (result instanceof RangeHighlighterEx) ((RangeHighlighterEx)result).setVisibleIfFolded(true);
  return result;
}
 
Example 11
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean removeContent(@Nonnull final Content content, final boolean dispose) {
  boolean wasSelected = mySelected == content;
  int oldIndex = myContents.indexOf(content);
  if (wasSelected) {
    removeFromSelection(content);
  }
  boolean result = myContents.remove(content);
  if (dispose) Disposer.dispose(content);
  ContentManagerEvent e = new ContentManagerEvent(this, content, oldIndex, ContentManagerEvent.ContentOperation.remove);
  myDispatcher.getMulticaster().contentRemoved(e);
  Content item = ContainerUtil.getFirstItem(myContents);
  if (item != null) setSelectedContent(item);
  return result;
}
 
Example 12
Source File: EmbeditorUtil.java    From neovim-intellij-complete with MIT License 5 votes vote down vote up
@NotNull
public static ResolveOutcome getSingleResolveOutcome(@NotNull final String path,
                                                     @NotNull final String fileContent,
                                                     final int line,
                                                     final int column) {
    Collection<ResolveOutcome> resolveOutcome = getResolveOutcomes(path, fileContent, line, column);
    return resolveOutcome.size() == 1
            ? ContainerUtil.getFirstItem(resolveOutcome, ResolveOutcome.NULL)
            : ResolveOutcome.NULL;
}
 
Example 13
Source File: GotoActionModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private String getFirstGroupName() {
  List<ActionGroup> path = ContainerUtil.getFirstItem(myPaths);
  return path != null ? getPathName(path) : null;
}
 
Example 14
Source File: CompoundRuntimeException.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized Throwable getCause() {
  return ContainerUtil.getFirstItem(myExceptions);
}
 
Example 15
Source File: CustomTemplateCallback.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public TemplateImpl findApplicableTemplate(@Nonnull String key) {
  return ContainerUtil.getFirstItem(findApplicableTemplates(key));
}
 
Example 16
Source File: UnityProcessDialog.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nullable
public static UnityProcess tryParseIfUnityProcess(ProcessInfo processInfo)
{
	String name = processInfo.getName();

	// Unity 2019.3 linux bug - 2020.1 ok
	if(name.equals("Main"))
	{
		List<String> list = StringUtil.split(processInfo.getCommand(), " ");
		String first = ContainerUtil.getFirstItem(list);
		if(first != null && first.endsWith("/Editor/Unity"))
		{
			return new UnityProcess(processInfo.getPid(), name, "localhost", buildDebuggerPort(processInfo.getPid()));
		}
	}

	if(StringUtil.startsWithIgnoreCase(name, "unity") || StringUtil.containsIgnoreCase(name, "Unity.app"))
	{
		// ignore 'UnityHelper' and 'Unity Helper'
		if(StringUtil.containsIgnoreCase(name, "Unity") && StringUtil.containsIgnoreCase(name, "Helper"))
		{
			return null;
		}

		if(StringUtil.containsIgnoreCase(name, "Unity") && StringUtil.containsIgnoreCase(name, "Hub") || StringUtil.containsIgnoreCase(name, "unityhub"))
		{
			return null;
		}

		if(StringUtil.containsIgnoreCase(name, "Unity") && StringUtil.containsIgnoreCase(name, "CrashHandler"))
		{
			return null;
		}

		// UnityShader - Package Manager - Hub compiler
		if(StringUtil.containsIgnoreCase(name, "UnityShader") || StringUtil.containsIgnoreCase(name, "UnityPackageMan"))
		{
			return null;
		}

		return new UnityProcess(processInfo.getPid(), name, "localhost", buildDebuggerPort(processInfo.getPid()));
	}

	return null;
}
 
Example 17
Source File: SingleEntryIndexForwardIndexAccessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public SingleValueDiffBuilder(int inputId, @Nonnull Map<Integer, V> currentData) {
  this(inputId, !currentData.isEmpty(), ContainerUtil.getFirstItem(currentData.values()));
}
 
Example 18
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link AbstractProjectViewPane#getElementsFromNode(Object)}
 **/
@Deprecated
@Nullable
public PsiElement getPSIElementFromNode(@Nullable TreeNode node) {
  return ContainerUtil.getFirstItem(getElementsFromNode(node));
}
 
Example 19
Source File: MacroFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Macro createMacro(@NonNls String name) {
  return ContainerUtil.getFirstItem(myMacroTable.get(name));
}
 
Example 20
Source File: CommitPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private List<VcsRef> sortRefs(@Nonnull Collection<VcsRef> refs) {
  VcsRef ref = ContainerUtil.getFirstItem(refs);
  if (ref == null) return ContainerUtil.emptyList();
  return ContainerUtil.sorted(refs, myLogData.getLogProvider(ref.getRoot()).getReferenceManager().getLabelsOrderComparator());
}