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

The following examples show how to use com.intellij.util.containers.ContainerUtil#isEmpty() . 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: 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 2
Source File: PluginsAdvertiserHolder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void update(@Nullable List<PluginDescriptor> list) {
  ourLoadedPluginDescriptors = ContainerUtil.isEmpty(list) ? null : list;

  if (list != null) {
    InstalledPluginsState pluginsState = InstalledPluginsState.getInstance();

    for (PluginDescriptor newPluginDescriptor : list) {
      final PluginDescriptor installed = PluginManager.getPlugin(newPluginDescriptor.getPluginId());
      if (installed != null) {
        int state = StringUtil.compareVersionNumbers(newPluginDescriptor.getVersion(), installed.getVersion());

        if (state > 0 &&
            !PluginManager.isIncompatible(newPluginDescriptor) &&
            !pluginsState.getUpdatedPlugins().contains(newPluginDescriptor.getPluginId())) {
          pluginsState.getOutdatedPlugins().add(newPluginDescriptor.getPluginId());
        }
      }
    }
  }
}
 
Example 3
Source File: XmlElementStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void analyzeExternalChangesAndUpdateIfNeed(@Nonnull Set<String> result) {
  StorageData oldData = myLoadedData;
  StorageData newData = getStorageData(true);
  if (oldData == null) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("analyzeExternalChangesAndUpdateIfNeed: old data null, load new for " + toString());
    }
    result.addAll(newData.getComponentNames());
  }
  else {
    Set<String> changedComponentNames = oldData.getChangedComponentNames(newData, myPathMacroSubstitutor);
    if (LOG.isDebugEnabled()) {
      LOG.debug("analyzeExternalChangesAndUpdateIfNeed: changedComponentNames + " + changedComponentNames + " for " + toString());
    }
    if (!ContainerUtil.isEmpty(changedComponentNames)) {
      result.addAll(changedComponentNames);
    }
  }
}
 
Example 4
Source File: ProjectManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private boolean shouldReloadProject(@Nonnull Project project) {
  if (project.isDisposed()) {
    return false;
  }

  Collection<StateStorage> causes = new SmartList<>();
  Collection<StateStorage> changes;
  synchronized (myChangedProjectFiles) {
    changes = myChangedProjectFiles.remove(project);
    if (!ContainerUtil.isEmpty(changes)) {
      for (StateStorage change : changes) {
        causes.add(change);
      }
    }
  }
  return !causes.isEmpty() && askToRestart(causes);
}
 
Example 5
Source File: XDebugSessionTab.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setSession(@Nonnull XDebugSessionImpl session, @Nullable ExecutionEnvironment environment, @Nullable Image icon) {
  myEnvironment = environment;
  mySession = session;
  mySessionData = session.getSessionData();
  myConsole = session.getConsoleView();

  AnAction[] restartActions;
  List<AnAction> restartActionsList = session.getRestartActions();
  if (ContainerUtil.isEmpty(restartActionsList)) {
    restartActions = AnAction.EMPTY_ARRAY;
  }
  else {
    restartActions = restartActionsList.toArray(new AnAction[restartActionsList.size()]);
  }

  myRunContentDescriptor =
          new RunContentDescriptor(myConsole, session.getDebugProcess().getProcessHandler(), myUi.getComponent(), session.getSessionName(), icon,
                                   myRebuildWatchesRunnable, restartActions);
  Disposer.register(myRunContentDescriptor, this);
  Disposer.register(myProject, myRunContentDescriptor);
}
 
Example 6
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public TreeModelBuilder setLocallyDeletedPaths(@javax.annotation.Nullable Collection<LocallyDeletedChange> locallyDeletedChanges) {
  if (ContainerUtil.isEmpty(locallyDeletedChanges)) return this;
  ChangesBrowserNode subtreeRoot = createTagNode(ChangesBrowserNode.LOCALLY_DELETED_NODE_TAG);

  for (LocallyDeletedChange change : locallyDeletedChanges) {
    // whether a folder does not matter
    final StaticFilePath key = new StaticFilePath(false, change.getPresentableUrl(), change.getPath().getVirtualFile());
    ChangesBrowserNode oldNode = getFolderCache(subtreeRoot).get(key.getKey());
    if (oldNode == null) {
      ChangesBrowserNode node = ChangesBrowserNode.create(change);
      ChangesBrowserNode parent = getParentNodeFor(key, subtreeRoot);
      myModel.insertNodeInto(node, parent, parent.getChildCount());
      getFolderCache(subtreeRoot).put(key.getKey(), node);
    }
  }
  return this;
}
 
Example 7
Source File: CommonProxy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public List<Proxy> select(@Nullable URI uri) {
  isInstalledAssertion();
  if (uri == null) {
    return NO_PROXY_LIST;
  }
  LOG.debug("CommonProxy.select called for " + uri.toString());

  if (Boolean.TRUE.equals(ourReenterDefence.get())) {
    return NO_PROXY_LIST;
  }
  try {
    ourReenterDefence.set(Boolean.TRUE);
    String host = StringUtil.notNullize(uri.getHost());
    if (NetUtils.isLocalhost(host)) {
      return NO_PROXY_LIST;
    }

    final HostInfo info = new HostInfo(uri.getScheme(), host, correctPortByProtocol(uri));
    final Map<String, ProxySelector> copy;
    synchronized (myLock) {
      if (myNoProxy.contains(Pair.create(info, Thread.currentThread()))) {
        LOG.debug("CommonProxy.select returns no proxy (in no proxy list) for " + uri.toString());
        return NO_PROXY_LIST;
      }
      copy = new THashMap<>(myCustom);
    }
    for (Map.Entry<String, ProxySelector> entry : copy.entrySet()) {
      final List<Proxy> proxies = entry.getValue().select(uri);
      if (!ContainerUtil.isEmpty(proxies)) {
        LOG.debug("CommonProxy.select returns custom proxy for " + uri.toString() + ", " + proxies.toString());
        return proxies;
      }
    }
    return NO_PROXY_LIST;
  }
  finally {
    ourReenterDefence.remove();
  }
}
 
Example 8
Source File: RunManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void fireRunConfigurationsRemoved(@Nullable List<RunnerAndConfigurationSettings> removed) {
  if (!ContainerUtil.isEmpty(removed)) {
    myRecentlyUsedTemporaries.removeAll(removed);
    for (RunnerAndConfigurationSettings settings : removed) {
      getEventPublisher().runConfigurationRemoved(settings);
    }
  }
}
 
Example 9
Source File: ProjectRunConfigurationManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Element getState() {
  Element state = new Element("state");
  for (RunnerAndConfigurationSettings configuration : myManager.getStableConfigurations(true)) {
    myManager.addConfigurationElement(state, configuration);
  }
  if (!ContainerUtil.isEmpty(myUnloadedElements)) {
    for (Element unloadedElement : myUnloadedElements) {
      state.addContent(unloadedElement.clone());
    }
  }
  return state;
}
 
Example 10
Source File: VcsRevisionNumberArrayRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public VcsRevisionNumber[] getData(@Nonnull DataProvider dataProvider) {
  List<VcsRevisionNumber> revisionNumbers = getRevisionNumbers(dataProvider);

  return !ContainerUtil.isEmpty(revisionNumbers) ? ArrayUtil.toObjectArray(revisionNumbers, VcsRevisionNumber.class) : null;
}
 
Example 11
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public TreeModelBuilder setLogicallyLockedFiles(@javax.annotation.Nullable Map<VirtualFile, LogicalLock> logicallyLockedFiles) {
  if (ContainerUtil.isEmpty(logicallyLockedFiles)) return this;
  final ChangesBrowserNode subtreeRoot = createTagNode(ChangesBrowserNode.LOGICALLY_LOCKED_TAG);

  List<VirtualFile> keys = ContainerUtil.sorted(logicallyLockedFiles.keySet(), VirtualFileHierarchicalComparator.getInstance());

  for (VirtualFile file : keys) {
    final LogicalLock lock = logicallyLockedFiles.get(file);
    final ChangesBrowserLogicallyLockedFile obj = new ChangesBrowserLogicallyLockedFile(myProject, file, lock);
    insertChangeNode(obj, subtreeRoot, ChangesBrowserNode.create(myProject, obj));
  }
  return this;
}
 
Example 12
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public TreeModelBuilder setIgnored(@javax.annotation.Nullable List<VirtualFile> ignoredFiles, boolean updatingMode) {
  if (ContainerUtil.isEmpty(ignoredFiles)) return this;
  int dirsCount = ContainerUtil.count(ignoredFiles, it -> it.isDirectory());
  int filesCount = ignoredFiles.size() - dirsCount;
  boolean manyFiles = ignoredFiles.size() > UNVERSIONED_MAX_SIZE;
  ChangesBrowserIgnoredFilesNode node = new ChangesBrowserIgnoredFilesNode(myProject, filesCount, dirsCount, manyFiles, updatingMode);
  return insertSpecificNodeToModel(ignoredFiles, node);
}
 
Example 13
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public TreeModelBuilder setUnversioned(@javax.annotation.Nullable List<VirtualFile> unversionedFiles) {
  if (ContainerUtil.isEmpty(unversionedFiles)) return this;
  int dirsCount = ContainerUtil.count(unversionedFiles, it -> it.isDirectory());
  int filesCount = unversionedFiles.size() - dirsCount;
  boolean manyFiles = unversionedFiles.size() > UNVERSIONED_MAX_SIZE;
  ChangesBrowserUnversionedFilesNode node = new ChangesBrowserUnversionedFilesNode(myProject, filesCount, dirsCount, manyFiles);
  return insertSpecificNodeToModel(unversionedFiles, node);
}
 
Example 14
Source File: ApplyPatchDifferentiatedDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void run() {
  final FilePresentationModel filePresentationModel = myRecentPathFileChange.get();
  final VirtualFile file = filePresentationModel != null ? filePresentationModel.getVf() : null;
  if (file == null) {
    ApplicationManager.getApplication().invokeLater(myReset, ModalityState.stateForComponent(myCenterPanel));
    return;
  }

  final PatchReader patchReader = loadPatches(file);
  List<FilePatch> filePatches = patchReader != null ? ContainerUtil.newArrayList(patchReader.getPatches()) : Collections.emptyList();
  if (!ContainerUtil.isEmpty(myBinaryShelvedPatches)) {
    filePatches.addAll(myBinaryShelvedPatches);
  }
  final List<AbstractFilePatchInProgress> matchedPatches = new MatchPatchPaths(myProject).execute(filePatches, myUseProjectRootAsPredefinedBase);

  ApplicationManager.getApplication().invokeLater(() -> {
    if (myShouldUpdateChangeListName) {
      myChangeListChooser.setSuggestedName(file.getNameWithoutExtension().replace('_', ' ').trim());
    }
    myPatches.clear();
    myPatches.addAll(matchedPatches);
    myReader = patchReader;
    updateTree(true);
    paintBusy(false);
    updateOkActions();
  }, ModalityState.stateForComponent(myCenterPanel));
}
 
Example 15
Source File: CompoundRuntimeException.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void throwIfNotEmpty(@Nullable List<? extends Throwable> throwables) {
  if (ContainerUtil.isEmpty(throwables)) {
    return;
  }

  if (throwables.size() == 1) {
    ExceptionUtil.rethrow(throwables.get(0));
  }
  else {
    throw new CompoundRuntimeException(throwables);
  }
}
 
Example 16
Source File: Notification.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean isImportant() {
  if (myImportant != null) {
    return myImportant;
  }

  return getListener() != null || !ContainerUtil.isEmpty(myActions);
}
 
Example 17
Source File: TreeModelBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private TreeModelBuilder setVirtualFiles(@javax.annotation.Nullable Collection<VirtualFile> files, @javax.annotation.Nullable Object tag) {
  if (ContainerUtil.isEmpty(files)) return this;
  insertFilesIntoNode(files, createTagNode(tag));
  return this;
}
 
Example 18
Source File: GenericInferenceUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static GenericInferenceResult inferenceGenericExtractor(@Nonnull CSharpCallArgument[] callArguments,
		@Nonnull DotNetTypeRef[] typeArgumentListRefs,
		@Nonnull PsiElement scope,
		@Nonnull DotNetLikeMethodDeclaration methodDeclaration)
{
	DotNetGenericParameter[] genericParameters = methodDeclaration.getGenericParameters();
	if(genericParameters.length == 0 || typeArgumentListRefs.length > 0)
	{
		DotNetGenericExtractor extractor = genericParameters.length != typeArgumentListRefs.length ? DotNetGenericExtractor.EMPTY : CSharpGenericExtractor.create(genericParameters,
				typeArgumentListRefs);
		return new GenericInferenceResult(genericParameters.length == typeArgumentListRefs.length, extractor);
	}

	List<NCallArgument> methodCallArguments = RecursionManager.doPreventingRecursion(methodDeclaration, false, () -> NCallArgumentBuilder.buildCallArguments(callArguments, methodDeclaration, scope));

	if(ContainerUtil.isEmpty(methodCallArguments))
	{
		return new GenericInferenceResult(true, DotNetGenericExtractor.EMPTY);
	}

	final Map<DotNetGenericParameter, DotNetTypeRef> map = new THashMap<>();

	for(NCallArgument nCallArgument : methodCallArguments)
	{
		ProgressManager.checkCanceled();

		DotNetTypeRef parameterTypeRef = nCallArgument.getParameterTypeRef();
		if(parameterTypeRef == null)
		{
			continue;
		}

		DotNetTypeRef expressionTypeRef = unwrapPossibleGenericTypeRefs(nCallArgument, parameterTypeRef, map, scope);
		if(expressionTypeRef instanceof CSharpFastImplicitTypeRef)
		{
			DotNetTypeRef mirror = ((CSharpFastImplicitTypeRef) expressionTypeRef).doMirror(parameterTypeRef, scope);
			if(mirror != null)
			{
				expressionTypeRef = mirror;
			}
		}

		DotNetTypeResolveResult parameterTypeResolveResult = parameterTypeRef.resolve();
		DotNetTypeResolveResult expressionTypeResolveResult = expressionTypeRef.resolve();

		if(parameterTypeResolveResult instanceof CSharpLambdaResolveResult && expressionTypeResolveResult instanceof CSharpLambdaResolveResult)
		{
			CSharpLambdaResolveResult pLambdaResolveResult = (CSharpLambdaResolveResult) parameterTypeResolveResult;
			CSharpLambdaResolveResult eLambdaResolveResult = (CSharpLambdaResolveResult) expressionTypeResolveResult;

			DotNetTypeRef[] pParameterTypeRefs = pLambdaResolveResult.getParameterTypeRefs();
			DotNetTypeRef[] eParameterTypeRefs = eLambdaResolveResult.getParameterTypeRefs();

			if(pParameterTypeRefs.length == eParameterTypeRefs.length)
			{
				for(int i = 0; i < eParameterTypeRefs.length; i++)
				{
					DotNetTypeRef pParameterTypeRef = pParameterTypeRefs[i];
					DotNetTypeRef eParameterTypeRef = eParameterTypeRefs[i];

					inferenceGenericFromExpressionTypeRefAndParameterTypeRef(genericParameters, map, pParameterTypeRef, eParameterTypeRef, scope);
				}
			}

			inferenceGenericFromExpressionTypeRefAndParameterTypeRef(genericParameters, map, pLambdaResolveResult.getReturnTypeRef(), eLambdaResolveResult.getReturnTypeRef(), scope);
		}

		if(parameterTypeResolveResult instanceof CSharpArrayTypeRef.ArrayResolveResult && expressionTypeResolveResult instanceof CSharpArrayTypeRef.ArrayResolveResult)
		{
			DotNetTypeRef pTypeRef = ((CSharpArrayTypeRef.ArrayResolveResult) parameterTypeResolveResult).getInnerTypeRef();
			DotNetTypeRef eTypeRef = ((CSharpArrayTypeRef.ArrayResolveResult) expressionTypeResolveResult).getInnerTypeRef();
			inferenceGenericFromExpressionTypeRefAndParameterTypeRef(genericParameters, map, pTypeRef, eTypeRef, scope);
		}

		inferenceGenericFromExpressionTypeRefAndParameterTypeRef(genericParameters, map, parameterTypeRef, expressionTypeRef, scope);
	}

	return new GenericInferenceResult(genericParameters.length == map.size(), CSharpGenericExtractor.create(map));
}
 
Example 19
Source File: GotoActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean historyEnabled() {
  return !ContainerUtil.isEmpty(ourHistory.get(myInAction));
}
 
Example 20
Source File: AdjustWhiteSpacesState.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean isReformatSelectedRangesContext() {
  return myReformatContext && !ContainerUtil.isEmpty(myAlignmentsInsideRangesToModify);
}