use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class ConvertParameterToMapEntryIntention method collectOwnerOccurrences.
private static boolean collectOwnerOccurrences(final Project project, final GrParametersOwner owner, final Collection<PsiElement> occurrences) {
final PsiElement namedElem = getReferencedElement(owner);
if (namedElem == null)
return true;
final Ref<Boolean> result = new Ref<>(true);
final Task task = new Task.Modal(project, GroovyIntentionsBundle.message("find.method.ro.closure.usages.0", owner instanceof GrClosableBlock ? CLOSURE_CAPTION : METHOD_CAPTION), true) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
final Collection<PsiReference> references = Collections.synchronizedSet(new HashSet<PsiReference>());
final Processor<PsiReference> consumer = psiReference -> {
references.add(psiReference);
return true;
};
ReferencesSearch.search(namedElem).forEach(consumer);
boolean isProperty = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return namedElem instanceof GrField && ((GrField) namedElem).isProperty();
}
});
if (isProperty) {
final GrAccessorMethod[] getters = ApplicationManager.getApplication().runReadAction(new Computable<GrAccessorMethod[]>() {
@Override
public GrAccessorMethod[] compute() {
return ((GrField) namedElem).getGetters();
}
});
for (GrAccessorMethod getter : getters) {
MethodReferencesSearch.search(getter).forEach(consumer);
}
}
for (final PsiReference reference : references) {
ApplicationManager.getApplication().runReadAction(() -> {
final PsiElement element = reference.getElement();
if (element != null) {
occurrences.add(element);
}
});
}
}
@Override
public void onCancel() {
result.set(false);
}
@Override
public void onThrowable(@NotNull Throwable error) {
super.onThrowable(error);
result.set(false);
}
@Override
public void onSuccess() {
result.set(true);
}
};
ProgressManager.getInstance().run(task);
return result.get().booleanValue();
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class GrAliasImportIntention method runTemplate.
private static void runTemplate(Project project, final GrImportStatement context, PsiMember resolved, final GroovyFileBase file, final List<UsageInfo> usages, GrImportStatement templateImport) {
PostprocessReformattingAspect.getInstance(project).doPostponedFormatting();
TemplateBuilderImpl templateBuilder = new TemplateBuilderImpl(templateImport);
LinkedHashSet<String> names = getSuggestedNames(resolved, context);
final PsiElement aliasNameElement = templateImport.getAliasNameElement();
assert aliasNameElement != null;
templateBuilder.replaceElement(aliasNameElement, new MyLookupExpression(resolved.getName(), names, (PsiNamedElement) resolved, resolved, true, null));
Template built = templateBuilder.buildTemplate();
final Editor newEditor = IntentionUtils.positionCursor(project, file, templateImport);
final Document document = newEditor.getDocument();
final RangeMarker contextImportPointer = document.createRangeMarker(context.getTextRange());
final TextRange range = templateImport.getTextRange();
document.deleteString(range.getStartOffset(), range.getEndOffset());
final String name = resolved.getName();
TemplateManager manager = TemplateManager.getInstance(project);
manager.startTemplate(newEditor, built, new TemplateEditingAdapter() {
@Override
public void templateFinished(Template template, boolean brokenOff) {
final GrImportStatement importStatement = ApplicationManager.getApplication().runReadAction(new Computable<GrImportStatement>() {
@Nullable
@Override
public GrImportStatement compute() {
return PsiTreeUtil.findElementOfClassAtOffset(file, range.getStartOffset(), GrImportStatement.class, true);
}
});
if (brokenOff) {
if (importStatement != null) {
ApplicationManager.getApplication().runWriteAction(() -> importStatement.delete());
}
return;
}
updateRefs(usages, name, importStatement);
ApplicationManager.getApplication().runWriteAction(() -> {
final GrImportStatement context1 = PsiTreeUtil.findElementOfClassAtRange(file, contextImportPointer.getStartOffset(), contextImportPointer.getEndOffset(), GrImportStatement.class);
if (context1 != null) {
context1.delete();
}
});
}
});
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class RerunFailedTestsAction method getRunProfile.
@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
final TestNGConfiguration configuration = (TestNGConfiguration) myConsoleProperties.getConfiguration();
final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
return new MyRunProfile(configuration) {
@Override
@NotNull
public Module[] getModules() {
return configuration.getModules();
}
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
return new TestNGRunnableState(env, configuration) {
@Override
public SearchingForTestsTask createSearchingForTestsTask() {
return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile) {
@Override
protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = ContainerUtil.newHashMap();
super.fillTestObjects(fullClassList);
for (final PsiClass aClass : fullClassList.keySet()) {
if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return TestNGUtil.hasTest(aClass);
}
})) {
classes.put(aClass, fullClassList.get(aClass));
}
}
final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope();
final Project project = getConfiguration().getProject();
for (final AbstractTestProxy proxy : failedTests) {
ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy));
}
}
};
}
};
}
};
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class JavaLineMarkerProvider method collectSlowLineMarkers.
@Override
public void collectSlowLineMarkers(@NotNull final List<PsiElement> elements, @NotNull final Collection<LineMarkerInfo> result) {
ApplicationManager.getApplication().assertReadAccessAllowed();
List<Computable<List<LineMarkerInfo>>> tasks = new ArrayList<>();
MultiMap<PsiClass, PsiMethod> byClass = MultiMap.create();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < elements.size(); i++) {
PsiElement element = elements.get(i);
ProgressManager.checkCanceled();
if (!(element instanceof PsiIdentifier))
continue;
PsiElement parent = element.getParent();
if (parent instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) parent;
PsiClass psiClass = method.getContainingClass();
if (PsiUtil.canBeOverriden(method) && psiClass != null) {
byClass.putValue(psiClass, method);
}
} else if (parent instanceof PsiClass && !(parent instanceof PsiTypeParameter)) {
tasks.add(() -> collectInheritingClasses((PsiClass) parent));
}
}
for (PsiClass psiClass : byClass.keySet()) {
Collection<PsiMethod> methods = byClass.get(psiClass);
tasks.add(() -> collectSiblingInheritedMethods(methods));
tasks.add(() -> collectOverridingMethods(methods, psiClass));
}
Object lock = new Object();
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(tasks, indicator, true, computable -> {
List<LineMarkerInfo> infos = computable.compute();
synchronized (lock) {
result.addAll(infos);
}
return true;
});
}
use of com.intellij.openapi.util.Computable in project intellij-community by JetBrains.
the class StaticIconFieldsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = LangDataKeys.PROJECT.getData(e.getDataContext());
final UsageViewPresentation presentation = new UsageViewPresentation();
presentation.setTabName("Statics");
presentation.setTabText("Statitcs");
final UsageView view = UsageViewManager.getInstance(project).showUsages(UsageTarget.EMPTY_ARRAY, Usage.EMPTY_ARRAY, presentation);
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Searching icons usages") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope all = GlobalSearchScope.allScope(project);
PsiClass allIcons = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
@Override
public PsiClass compute() {
return facade.findClass("com.intellij.icons.AllIcons", all);
}
});
searchFields(allIcons, view, indicator);
PsiClass[] classes = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass[]>() {
@Override
public PsiClass[] compute() {
return facade.findPackage("icons").getClasses(all);
}
});
for (PsiClass iconsClass : classes) {
searchFields(iconsClass, view, indicator);
}
}
});
}
Aggregations