private boolean processFilesConcurrently(
      @NotNull Set<VirtualFile> files,
      @NotNull final ProgressIndicator indicator,
      @NotNull final Processor<VirtualFile> processor) {
    final List<VirtualFile> fileList = new ArrayList<VirtualFile>(files);
    // fine but grabs all CPUs
    // return JobLauncher.getInstance().invokeConcurrentlyUnderProgress(fileList, indicator, false,
    // false, processor);

    int parallelism = CacheUpdateRunner.indexingThreadCount();
    final Callable<Boolean> processFileFromSet =
        () -> {
          final boolean[] result = {true};
          ProgressManager.getInstance()
              .executeProcessUnderProgress(
                  () -> {
                    while (true) {
                      ProgressManager.checkCanceled();
                      VirtualFile file;
                      synchronized (fileList) {
                        file = fileList.isEmpty() ? null : fileList.remove(fileList.size() - 1);
                      }
                      if (file == null) {
                        break;
                      }
                      if (!processor.process(file)) {
                        result[0] = false;
                        break;
                      }
                    }
                  },
                  indicator);
          return result[0];
        };
    List<Future<Boolean>> futures =
        ContainerUtil.map(
            Collections.nCopies(parallelism, ""),
            s -> myApplication.executeOnPooledThread(processFileFromSet));

    List<Boolean> results =
        ContainerUtil.map(
            futures,
            future -> {
              try {
                return future.get();
              } catch (Exception e) {
                LOG.error(e);
              }
              return false;
            });

    return !ContainerUtil.exists(
        results,
        result -> {
          return result != null && !result; // null means PCE
        });
  }
Пример #2
0
  @NotNull
  public List<String> createConversions(
      @NotNull PsiPolyadicExpression expression, PsiType expectedType) {
    PsiExpression[] arguments = expression.getOperands();
    int length = arguments.length;
    List<String> conversions = new LinkedList<String>();

    List<PsiType> expectedTypes = Collections.nCopies(length, expectedType);
    List<PsiType> actualTypes = new LinkedList<PsiType>();

    for (PsiExpression e : arguments) actualTypes.add(e.getType());

    assert actualTypes.size() == expectedTypes.size() : "The type list must have the same length";

    for (int i = 0; i < actualTypes.size(); i++)
      conversions.add(i, createConversionForExpression(arguments[i], expectedTypes.get(i)));

    return conversions;
  }