本文整理汇总了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);
}
示例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());
}
示例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;
}
示例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) {
}
}
示例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());
}
示例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;
}
示例7: cancelCurrentSearch
import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
protected void cancelCurrentSearch() {
ProgressIndicator progress = associatedProgress;
if (progress != null) {
ProgressWrapper.unwrap(progress).cancel();
}
}
示例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;
}
示例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);
}
示例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);
}
示例11: cancelCurrentSearch
import com.intellij.openapi.progress.util.ProgressWrapper; //导入依赖的package包/类
void cancelCurrentSearch() {
ProgressIndicator progress = associatedProgress;
if (progress != null) {
ProgressWrapper.unwrap(progress).cancel();
}
}