Java Code Examples for com.intellij.openapi.application.ReadAction#run()

The following examples show how to use com.intellij.openapi.application.ReadAction#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentsCacheService.java    From litho with Apache License 2.0 5 votes vote down vote up
private void maybeUpdateInReadAction(
    PsiClass specClass, String componentQualifiedName, ShouldUpdateChecker checker) {
  final ThrowableRunnable<RuntimeException> job =
      () -> {
        if (checker.shouldStopUpdate()) return;

        final LayoutSpecModel layoutModel = ComponentGenerateUtils.createLayoutModel(specClass);
        update(componentQualifiedName, layoutModel);
      };
  if (ApplicationManager.getApplication().isReadAccessAllowed()) {
    job.run();
  } else {
    ReadAction.run(job);
  }
}
 
Example 2
Source File: IdeaFrameFixture.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
public GradleBuildModelFixture parseBuildFileForModule(@NotNull String moduleName) {
  Module module = getModule(moduleName);
  VirtualFile buildFile = getGradleBuildFile(module);
  Ref<GradleBuildModel> buildModelRef = new Ref<>();
  ReadAction.run(() -> buildModelRef.set(GradleBuildModel.parseBuildFile(buildFile, getProject())));
  return new GradleBuildModelFixture(buildModelRef.get());
}
 
Example 3
Source File: ExternalFilePositionManager.java    From intellij with Apache License 2.0 5 votes vote down vote up
private void indexQualifiedClassNames(PsiFile psiFile) {
  if (!(psiFile instanceof PsiClassOwner)) {
    return;
  }
  ReadAction.run(
      () -> {
        for (PsiClass psiClass : ((PsiClassOwner) psiFile).getClasses()) {
          qualifiedNameToPsiFile.put(psiClass.getQualifiedName(), psiFile);
        }
      });
}
 
Example 4
Source File: UnityPluginFileValidator.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private static void modifyModules(Project project, Consumer<ModifiableRootModel> action)
{
	List<ModifiableRootModel> list = new ArrayList<>();
	ReadAction.run(() ->
	{
		Unity3dRootModuleExtension unity3dRootModuleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(project);

		if(unity3dRootModuleExtension == null)
		{
			return;
		}

		ModuleManager moduleManager = ModuleManager.getInstance(project);

		Module[] modules = moduleManager.getModules();
		for(Module module : modules)
		{
			String name = module.getName();
			if(name.startsWith("Assembly") && name.endsWith("Editor"))
			{
				ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
				ModifiableRootModel modifiableModel = moduleRootManager.getModifiableModel();

				action.consume(modifiableModel);

				list.add(modifiableModel);
			}
		}
	});

	WriteCommandAction.runWriteCommandAction(project, () ->
	{
		for(ModifiableRootModel modifiableRootModel : list)
		{
			modifiableRootModel.commit();
		}
	});
}
 
Example 5
Source File: RefManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<RefElement> getSortedElements() {
  List<RefElement> answer = myCachedSortedRefs;
  if (answer != null) return answer;

  answer = new ArrayList<>(myRefTable.values());
  List<RefElement> list = answer;
  ReadAction.run(() -> ContainerUtil.quickSort(list, (o1, o2) -> {
    VirtualFile v1 = ((RefElementImpl)o1).getVirtualFile();
    VirtualFile v2 = ((RefElementImpl)o2).getVirtualFile();
    return (v1 != null ? v1.hashCode() : 0) - (v2 != null ? v2.hashCode() : 0);
  }));
  myCachedSortedRefs = answer = Collections.unmodifiableList(answer);
  return answer;
}
 
Example 6
Source File: SearchEverywhereUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void fillUsages(Collection<Object> foundElements, Collection<? super Usage> usages, Collection<? super PsiElement> targets) {
  ReadAction.run(() -> foundElements.stream().filter(o -> o instanceof PsiElement).forEach(o -> {
    PsiElement element = (PsiElement)o;
    if (element.getTextRange() != null) {
      UsageInfo usageInfo = new UsageInfo(element);
      usages.add(new UsageInfo2UsageAdapter(usageInfo));
    }
    else {
      targets.add(element);
    }
  }));
}