use of com.intellij.openapi.progress.EmptyProgressIndicator in project smali by JesusFreke.
the class SmaliClassReferenceSearcher method processQuery.
@Override
public void processQuery(final SearchParameters queryParameters, final Processor<PsiReference> consumer) {
final PsiElement element = queryParameters.getElementToSearch();
if (!(element instanceof PsiClass)) {
return;
}
String smaliType = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
String qualifiedName = ((PsiClass) element).getQualifiedName();
if (qualifiedName != null) {
return NameUtils.javaToSmaliType((PsiClass) element);
}
return null;
}
});
if (smaliType == null) {
return;
}
final StringSearcher stringSearcher = new StringSearcher(smaliType, true, true, false, false);
final SingleTargetRequestResultProcessor processor = new SingleTargetRequestResultProcessor(element);
SearchScope querySearchScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
public SearchScope compute() {
return queryParameters.getEffectiveSearchScope();
}
});
if (querySearchScope instanceof LocalSearchScope) {
for (final PsiElement scopeElement : ((LocalSearchScope) querySearchScope).getScope()) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
LowLevelSearchUtil.processElementsContainingWordInElement(new TextOccurenceProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
return processor.processTextOccurrence(element, offsetInElement, consumer);
}
}, scopeElement, stringSearcher, true, new EmptyProgressIndicator());
}
});
}
} else if (querySearchScope instanceof GlobalSearchScope) {
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
// TODO: limit search scope to only smali files. See, e.g. AnnotatedPackagesSearcher.PackageInfoFilesOnly
helper.processAllFilesWithWord(smaliType, (GlobalSearchScope) querySearchScope, new Processor<PsiFile>() {
@Override
public boolean process(PsiFile file) {
LowLevelSearchUtil.processElementsContainingWordInElement(new TextOccurenceProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
return processor.processTextOccurrence(element, offsetInElement, consumer);
}
}, file, stringSearcher, true, new EmptyProgressIndicator());
return true;
}
}, true);
} else {
assert false;
return;
}
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class PsiBuilderImpl method merge.
@NotNull
private DiffLog merge(@NotNull final ASTNode oldRoot, @NotNull StartMarker newRoot, @NotNull CharSequence lastCommittedText) {
DiffLog diffLog = new DiffLog();
DiffTreeChangeBuilder<ASTNode, LighterASTNode> builder = new ConvertFromTokensToASTBuilder(newRoot, diffLog);
MyTreeStructure treeStructure = new MyTreeStructure(newRoot, null);
ShallowNodeComparator<ASTNode, LighterASTNode> comparator = new MyComparator(getUserDataUnprotected(CUSTOM_COMPARATOR), treeStructure);
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
BlockSupportImpl.diffTrees(oldRoot, builder, comparator, treeStructure, indicator == null ? new EmptyProgressIndicator() : indicator, lastCommittedText);
return diffLog;
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class PomModelImpl method reparseFile.
@Nullable
private Runnable reparseFile(@NotNull final PsiFile file, @NotNull FileElement treeElement, @NotNull CharSequence newText) {
TextRange changedPsiRange = DocumentCommitThread.getChangedPsiRange(file, treeElement, newText);
if (changedPsiRange == null)
return null;
Runnable reparseLeaf = tryReparseOneLeaf(treeElement, newText, changedPsiRange);
if (reparseLeaf != null)
return reparseLeaf;
final DiffLog log = BlockSupport.getInstance(myProject).reparseRange(file, treeElement, changedPsiRange, newText, new EmptyProgressIndicator(), treeElement.getText());
return () -> runTransaction(new PomTransactionBase(file, getModelAspect(TreeAspect.class)) {
@Nullable
@Override
public PomModelEvent runInner() throws IncorrectOperationException {
return new TreeAspectEvent(PomModelImpl.this, log.performActualPsiChange(file));
}
});
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class JobUtilTest method testTasksRunEvenWhenReadActionIsHardToGet_Performance.
public void testTasksRunEvenWhenReadActionIsHardToGet_Performance() throws ExecutionException, InterruptedException {
AtomicInteger processorCalled = new AtomicInteger();
final Processor<String> processor = s -> {
busySleep(1);
processorCalled.incrementAndGet();
return true;
};
for (int i = 0; i < 10; /*0*/
i++) {
System.out.println("i = " + i);
processorCalled.set(0);
final ProgressIndicator indicator = new EmptyProgressIndicator();
int N = 10000;
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> {
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(N, ""), indicator, true, false, processor);
assertFalse(indicator.isCanceled());
});
for (int k = 0; k < 10000; k++) {
ApplicationManager.getApplication().runWriteAction(() -> {
busySleep(1);
});
}
future.get();
assertEquals(N, processorCalled.get());
}
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class BackgroundTaskUtil method computeInBackgroundAndTryWait.
/**
* Compute value in background and try wait for its completion.
* <ul>
* <li> If the computation is fast, return computed value synchronously. Callback will not be called in this case.
* <li> If the computation is slow, return <tt>null</tt>. When the computation is completed, pass the value to the callback.
* </ul>
* Callback will be executed on the same thread as the background task.
*/
@NotNull
@CalledInAny
public static <T> Pair<T, ProgressIndicator> computeInBackgroundAndTryWait(@NotNull Function<ProgressIndicator, T> task, @NotNull PairConsumer<T, ProgressIndicator> asyncCallback, @NotNull ModalityState modality, long waitMillis) {
ProgressIndicator indicator = new EmptyProgressIndicator(modality);
Helper<T> helper = new Helper<>();
indicator.start();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
try {
T result = task.fun(indicator);
if (!helper.setResult(result)) {
asyncCallback.consume(result, indicator);
}
} finally {
indicator.stop();
}
}, indicator);
});
T result = null;
if (helper.await(waitMillis)) {
result = helper.getResult();
}
return Pair.create(result, indicator);
}
Aggregations