当前位置: 首页>>代码示例>>Java>>正文


Java ProgressWrapper类代码示例

本文整理汇总了Java中com.intellij.openapi.progress.util.ProgressWrapper的典型用法代码示例。如果您正苦于以下问题:Java ProgressWrapper类的具体用法?Java ProgressWrapper怎么用?Java ProgressWrapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProgressWrapper类属于com.intellij.openapi.progress.util包,在下文中一共展示了ProgressWrapper类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invokeConcurrentlyUnderProgress

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
@Override
public <T> boolean invokeConcurrentlyUnderProgress(@NotNull List<? extends T> things,
                                                   ProgressIndicator progress,
                                                   boolean runInReadAction,
                                                   boolean failFastOnAcquireReadAction,
                                                   @NotNull Processor<T> thingProcessor) {
  if (things.isEmpty()) {
    return true;
  }
  if (things.size() == 1) {
    T t = things.get(0);
    return thingProcessor.process(t);
  }

  // can be already wrapped
  final ProgressWrapper wrapper = progress instanceof ProgressWrapper ? (ProgressWrapper)progress : ProgressWrapper.wrap(progress);
  return invokeConcurrentlyForAll(things, runInReadAction, failFastOnAcquireReadAction, thingProcessor, wrapper);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:JobLauncherImpl.java

示例2: startCompletion

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
void startCompletion(final CompletionInitializationContext initContext) {
  boolean sync = ApplicationManager.getApplication().isWriteAccessAllowed();
  myStrategy = sync ? new SyncCompletion() : new AsyncCompletion();
  myStrategy.startThread(ProgressWrapper.wrap(this), this::scheduleAdvertising);
  final WeighingDelegate weigher = myStrategy.delegateWeighing(this);

  class CalculateItems implements Runnable {
    @Override
    public void run() {
      try {
        calculateItems(initContext, weigher);
      }
      catch (ProcessCanceledException ignore) {
        cancel(); // some contributor may just throw PCE; if indicator is not canceled everything will hang
      }
      catch (Throwable t) {
        cancel();
        LOG.error(t);
      }
    }
  }
  myStrategy.startThread(this, new CalculateItems());
}
 
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:CompletionProgressIndicator.java

示例3: processUsagesInFile

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
static int processUsagesInFile(@Nonnull final PsiFile psiFile, @Nonnull final VirtualFile virtualFile, @Nonnull final FindModel findModel, @Nonnull final Processor<UsageInfo> consumer) {
  if (findModel.getStringToFind().isEmpty()) {
    if (!ReadAction.compute(() -> consumer.process(new UsageInfo(psiFile)))) {
      throw new ProcessCanceledException();
    }
    return 1;
  }
  if (virtualFile.getFileType().isBinary()) return 0; // do not decompile .class files
  final Document document = ReadAction.compute(() -> virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null);
  if (document == null) return 0;
  final int[] offset = {0};
  int count = 0;
  int found;
  ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
  TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator);
  do {
    tooManyUsagesStatus.pauseProcessingIfTooManyUsages(); // wait for user out of read action
    found = ReadAction.compute(() -> {
      if (!psiFile.isValid()) return 0;
      return addToUsages(document, consumer, findModel, psiFile, offset, USAGES_PER_READ_ACTION);
    });
    count += found;
  }
  while (found != 0);
  return count;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:27,代码来源:FindInProjectUtil.java

示例4: testWrapperIndicatorGotCanceledTooWhenInnerIndicatorHas

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
public void testWrapperIndicatorGotCanceledTooWhenInnerIndicatorHas() {
  final ProgressIndicator progress = new ProgressIndicatorBase(){
    @Override
    protected boolean isCancelable() {
      return true;
    }
  };
  try {
    ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
      @Override
      public void run() {
        assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
        assertTrue(!progress.isCanceled());
        progress.cancel();
        assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
        assertTrue(progress.isCanceled());
        while (true) { // wait for PCE
          ProgressManager.checkCanceled();
        }
      }
    }, ProgressWrapper.wrap(progress));
    fail("PCE must have been thrown");
  }
  catch (ProcessCanceledException ignored) {

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ProgressIndicatorTest.java

示例5: startCompletion

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
void startCompletion(final CompletionInitializationContext initContext) {
  boolean sync = ApplicationManager.getApplication().isUnitTestMode() && !CompletionAutoPopupHandler.ourTestingAutopopup;
  final CompletionThreading strategy = sync ? new SyncCompletion() : new AsyncCompletion();

  strategy.startThread(ProgressWrapper.wrap(this), new Runnable() {
    @Override
    public void run() {
      scheduleAdvertising();
    }
  });
  final WeighingDelegate weigher = strategy.delegateWeighing(this);

  class CalculateItems implements Runnable {
    @Override
    public void run() {
      try {
        calculateItems(initContext, weigher);
      }
      catch (ProcessCanceledException ignore) {
        cancel(); // some contributor may just throw PCE; if indicator is not canceled everything will hang
      }
      catch (Throwable t) {
        cancel();
        LOG.error(t);
      }
    }
  }
  strategy.startThread(this, new CalculateItems());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:CompletionProgressIndicator.java

示例6: startCompletion

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
AtomicReference<LookupElement[]> startCompletion(final CompletionInitializationContext initContext) {
  boolean sync = ApplicationManager.getApplication().isUnitTestMode() && !CompletionAutoPopupHandler.ourTestingAutopopup;
  final CompletionThreading strategy = sync ? new SyncCompletion() : new AsyncCompletion();

  strategy.startThread(ProgressWrapper.wrap(this), new Runnable() {
    @Override
    public void run() {
      scheduleAdvertising();
    }
  });
  final WeighingDelegate weigher = strategy.delegateWeighing(this);

  final AtomicReference<LookupElement[]> data = new AtomicReference<LookupElement[]>(null);
  class CalculateItems implements Runnable {
    @Override
    public void run() {
      try {
        data.set(calculateItems(initContext, weigher));
      }
      catch (ProcessCanceledException ignore) {
      }
      catch (Throwable t) {
        LOG.error(t);
        cancel();
      }
    }
  }
  strategy.startThread(this, new CalculateItems());
  return data;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:31,代码来源:CompletionProgressIndicator.java

示例7: cancelCurrentSearch

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
protected void cancelCurrentSearch() {
  ProgressIndicator progress = associatedProgress;
  if (progress != null) {
    ProgressWrapper.unwrap(progress).cancel();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:UsageViewImpl.java

示例8: processUsagesInFile

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
static int processUsagesInFile(@NotNull final PsiFile psiFile,
                                       @NotNull final FindModel findModel,
                                       @NotNull final Processor<UsageInfo> consumer) {
  if (findModel.getStringToFind().isEmpty()) {
    if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
            @Override
            public Boolean compute() {
              return consumer.process(new UsageInfo(psiFile,0,0,true));
            }
          })) {
      throw new ProcessCanceledException();
    }
    return 1;
  }
  final VirtualFile virtualFile = psiFile.getVirtualFile();
  if (virtualFile == null) return 0;
  if (virtualFile.getFileType().isBinary()) return 0; // do not decompile .class files
  final Document document = ApplicationManager.getApplication().runReadAction(new Computable<Document>() {
    @Override
    public Document compute() {
      return virtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(virtualFile) : null;
    }
  });
  if (document == null) return 0;
  final int[] offset = {0};
  int count = 0;
  int found;
  ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
  TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator);
  do {
    tooManyUsagesStatus.pauseProcessingIfTooManyUsages(); // wait for user out of read action
    found = ApplicationManager.getApplication().runReadAction(new Computable<Integer>() {
      @Override
      @NotNull
      public Integer compute() {
        if (!psiFile.isValid()) return 0;
        return addToUsages(document, consumer, findModel, psiFile, offset, USAGES_PER_READ_ACTION);
      }
    });
    count += found;
  }
  while (found != 0);
  return count;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:45,代码来源:FindInProjectUtil.java

示例9: checkFile

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
private void checkFile(final PsiFile file,
                       final InspectionManager manager,
                       GlobalInspectionContextBase context,
                       final RefManager refManager,
                       final ProblemDescriptionsProcessor processor) {
  if (!(file instanceof PropertiesFile)) return;
  if (!context.isToCheckFile(file, this)) return;
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
  final PropertiesFile propertiesFile = (PropertiesFile)file;
  final List<IProperty> properties = propertiesFile.getProperties();
  Module module = ModuleUtilCore.findModuleForPsiElement(file);
  if (module == null) return;
  final GlobalSearchScope scope = CURRENT_FILE
                                  ? GlobalSearchScope.fileScope(file)
                                  : MODULE_WITH_DEPENDENCIES
                                    ? GlobalSearchScope.moduleWithDependenciesScope(module)
                                    : GlobalSearchScope.projectScope(file.getProject());
  final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
  final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
  final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator();
  final ProgressIndicator progress = ProgressWrapper.wrap(original);
  ProgressManager.getInstance().runProcess(new Runnable() {
    @Override
    public void run() {
      if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, new Processor<IProperty>() {
        @Override
        public boolean process(final IProperty property) {
          if (original != null) {
            if (original.isCanceled()) return false;
            original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey()));
          }
          processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope);
          processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope);
          return true;
        }
      })) throw new ProcessCanceledException();

      List<ProblemDescriptor> problemDescriptors = new ArrayList<ProblemDescriptor>();
      Map<String, Set<String>> keyToDifferentValues = new HashMap<String, Set<String>>();
      if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
        prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original);
      }
      if (CHECK_DUPLICATE_VALUES) prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original);
      if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
        processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original);
      }
      if (!problemDescriptors.isEmpty()) {
        processor.addProblemElement(refManager.getReference(file),
                                    problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]));
      }
    }
  }, progress);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:54,代码来源:DuplicatePropertyInspection.java

示例10: checkFile

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
private void checkFile(final PsiFile file, final InspectionManager manager, GlobalInspectionContextImpl context, final RefManager refManager, final ProblemDescriptionsProcessor processor) {
  if (!(file instanceof PropertiesFile)) return;
  if (!context.isToCheckFile(file, this)) return;
  final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(file.getProject());
  final PropertiesFile propertiesFile = (PropertiesFile)file;
  final List<IProperty> properties = propertiesFile.getProperties();
  Module module = ModuleUtil.findModuleForPsiElement(file);
  if (module == null) return;
  final GlobalSearchScope scope = CURRENT_FILE
                                  ? GlobalSearchScope.fileScope(file)
                                  : MODULE_WITH_DEPENDENCIES
                                    ? GlobalSearchScope.moduleWithDependenciesScope(module)
                                    : GlobalSearchScope.projectScope(file.getProject());
  final Map<String, Set<PsiFile>> processedValueToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
  final Map<String, Set<PsiFile>> processedKeyToFiles = Collections.synchronizedMap(new HashMap<String, Set<PsiFile>>());
  final ProgressIndicator original = ProgressManager.getInstance().getProgressIndicator();
  final ProgressIndicator progress = ProgressWrapper.wrap(original);
  ProgressManager.getInstance().runProcess(new Runnable() {
    @Override
    public void run() {
      if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(properties, progress, false, new Processor<IProperty>() {
        @Override
        public boolean process(final IProperty property) {
          if (original != null) {
            if (original.isCanceled()) return false;
            original.setText2(PropertiesBundle.message("searching.for.property.key.progress.text", property.getUnescapedKey()));
          }
          processTextUsages(processedValueToFiles, property.getValue(), processedKeyToFiles, searchHelper, scope);
          processTextUsages(processedKeyToFiles, property.getUnescapedKey(), processedValueToFiles, searchHelper, scope);
          return true;
        }
      })) throw new ProcessCanceledException();

      List<ProblemDescriptor> problemDescriptors = new ArrayList<ProblemDescriptor>();
      Map<String, Set<String>> keyToDifferentValues = new HashMap<String, Set<String>>();
      if (CHECK_DUPLICATE_KEYS || CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
        prepareDuplicateKeysByFile(processedKeyToFiles, manager, keyToDifferentValues, problemDescriptors, file, original);
      }
      if (CHECK_DUPLICATE_VALUES) prepareDuplicateValuesByFile(processedValueToFiles, manager, problemDescriptors, file, original);
      if (CHECK_DUPLICATE_KEYS_WITH_DIFFERENT_VALUES) {
        processDuplicateKeysWithDifferentValues(keyToDifferentValues, processedKeyToFiles, problemDescriptors, manager, file, original);
      }
      if (!problemDescriptors.isEmpty()) {
        processor.addProblemElement(refManager.getReference(file),
                                    problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]));
      }
    }
  }, progress);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:50,代码来源:DuplicatePropertyInspection.java

示例11: cancelCurrentSearch

import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
void cancelCurrentSearch() {
  ProgressIndicator progress = associatedProgress;
  if (progress != null) {
    ProgressWrapper.unwrap(progress).cancel();
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:7,代码来源:UsageViewImpl.java


注:本文中的com.intellij.openapi.progress.util.ProgressWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。