Skip to content

Commit

Permalink
Use newer ReadAction API
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Dec 12, 2022
1 parent 5040930 commit 20de904
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# CheckStyle-IDEA Changelog

* **5.74.1** Fixed: Ensure scope is checked as read action (#595).
* **5.74.0** New: Added Checkstyle 10.5.0 - thanks to @kennysoft (#596).
* **5.73.0** New: Added Checkstyle 10.4.
* **5.72.0** Now built against IDEA 2021.3.3 (was 2021.1.3).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
// Project Metadata
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

version = '5.74.0'
version = '5.74.1'

intellij {
version = 'IC-2021.3.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiFile;
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void auditFinished(final AuditEvent auditEvent) {

final Application application = ApplicationManager.getApplication();
if (application != null) { // can be null in unit tests
application.runReadAction(findThread);
ReadAction.run(findThread);
problems = findThread.getProblems();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.StaticScanner;
import org.infernus.idea.checkstyle.model.ConfigurationLocation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -12,7 +13,7 @@
import java.util.List;


abstract class ScanAllFilesTask implements Runnable {
abstract class ScanAllFilesTask implements ThrowableRunnable<RuntimeException> {

private final Project project;
private final ConfigurationLocation selectedOverride;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.module.Module;
Expand All @@ -11,6 +11,7 @@
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.model.ScanScope;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -50,7 +51,7 @@ public final void actionPerformed(final @NotNull AnActionEvent event) {
try {
setProgressText(toolWindow, "plugin.status.in-progress.module");

Runnable scanAction = null;
ThrowableRunnable<RuntimeException> scanAction = null;
if (scope == ScanScope.Everything) {
scanAction = new ScanAllFilesInModuleTask(module, getSelectedOverride(toolWindow));
} else {
Expand All @@ -62,7 +63,7 @@ public final void actionPerformed(final @NotNull AnActionEvent event) {
}
}
if (scanAction != null) {
ApplicationManager.getApplication().runReadAction(scanAction);
ReadAction.run(scanAction);
}
} catch (Throwable e) {
LOG.warn("Current Module scan failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.model.ScanScope;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -39,7 +40,7 @@ public void actionPerformed(final @NotNull AnActionEvent event) {
private void executeScan(final Project project, final ScanScope scope, final ToolWindow toolWindow) {
try {
setProgressText(toolWindow, "plugin.status.in-progress.project");
Runnable scanAction = null;
ThrowableRunnable<RuntimeException> scanAction = null;
if (scope == ScanScope.Everything) {
scanAction = new ScanAllFilesInProjectTask(project, getSelectedOverride(toolWindow));
} else {
Expand All @@ -50,7 +51,7 @@ private void executeScan(final Project project, final ScanScope scope, final Too
}
}
if (scanAction != null) {
ApplicationManager.getApplication().runReadAction(scanAction);
ReadAction.run(scanAction);
}
} catch (Throwable e) {
LOG.warn("Project scan failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.openapi.module.Module;
import com.intellij.psi.PsiFile;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -10,7 +11,7 @@
/**
* Action to read the file to a temporary file.
*/
class CreateScannableFileAction implements Runnable {
class CreateScannableFileAction implements ThrowableRunnable<RuntimeException> {

/**
* Any failure that occurred on the thread.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.infernus.idea.checkstyle.checker;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
Expand Down Expand Up @@ -63,15 +63,15 @@ private List<PsiFile> findAllFilesFor(@NotNull final List<VirtualFile> virtualFi
}

private Map<Module, Set<PsiFile>> mapsModulesToFiles() {
final Map<Module, Set<PsiFile>> modulesToFiles = new HashMap<>();
ApplicationManager.getApplication().runReadAction(() -> {
return ReadAction.compute(() -> {
final Map<Module, Set<PsiFile>> modulesToFiles = new HashMap<>();
for (final PsiFile file : files) {
final Module module = ModuleUtil.findModuleForPsiElement(file);
Set<PsiFile> filesForModule = modulesToFiles.computeIfAbsent(module, key -> new HashSet<>());
filesForModule.add(file);
}
return modulesToFiles;
});
return modulesToFiles;
}

@Override
Expand Down Expand Up @@ -132,13 +132,11 @@ private void fireFilesScanned(final int count) {
}

private List<PsiFile> buildFilesList(final PsiManager psiManager, final VirtualFile virtualFile) {
final List<PsiFile> allChildFiles = new ArrayList<>();
ApplicationManager.getApplication().runReadAction(() -> {
return ReadAction.compute(() -> {
final FindChildFiles visitor = new FindChildFiles(virtualFile, psiManager);
VfsUtilCore.visitChildrenRecursively(virtualFile, visitor);
allChildFiles.addAll(visitor.locatedFiles);
return visitor.locatedFiles;
});
return allChildFiles;
}

private Pair<ConfigurationLocationResult, Map<PsiFile, List<Problem>>> processFilesForModuleInfoAndScan() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.infernus.idea.checkstyle.checker;

import com.intellij.application.options.CodeStyle;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -75,7 +75,7 @@ public static List<ScannableFile> createAndValidate(@NotNull final Collection<Ps
@NotNull final Project project,
@Nullable final Module module,
@Nullable final ConfigurationLocation overrideConfigLocation) {
Computable<List<ScannableFile>> action = () -> psiFiles.stream()
ThrowableComputable<List<ScannableFile>, RuntimeException> action = () -> psiFiles.stream()
.filter(currentFile -> PsiFileValidator.isScannable(
currentFile,
ofNullable(module),
Expand All @@ -84,7 +84,7 @@ public static List<ScannableFile> createAndValidate(@NotNull final Collection<Ps
.map(currentFile -> ScannableFile.create(currentFile, module))
.filter(Objects::nonNull)
.collect(Collectors.toCollection(CopyOnWriteArrayList::new));
return ApplicationManager.getApplication().runReadAction(action);
return ReadAction.compute(action);
}

private static PluginConfigurationManager configurationManager(final Project project) {
Expand All @@ -95,7 +95,7 @@ private static PluginConfigurationManager configurationManager(final Project pro
private static ScannableFile create(@NotNull final PsiFile psiFile, @Nullable final Module module) {
try {
final CreateScannableFileAction fileAction = new CreateScannableFileAction(psiFile, module);
ApplicationManager.getApplication().runReadAction(fileAction);
ReadAction.run(fileAction);

if (fileAction.getFailure() != null) {
throw fileAction.getFailure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiInvalidElementAccessException;
import com.intellij.util.ThrowableRunnable;
import org.infernus.idea.checkstyle.checker.Problem;
import org.infernus.idea.checkstyle.checks.Check;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,7 +15,7 @@
import java.util.*;


public class ProcessResultsThread implements Runnable {
public class ProcessResultsThread implements ThrowableRunnable<RuntimeException> {

private static final Logger LOG = Logger.getInstance(ProcessResultsThread.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;

public final class NamedScopeHelper {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</p>
]]>
</description>
<version>5.73.0</version>
<version>5.74.1</version>
<idea-version since-build="213.7172.25"/>
<vendor url="https://infernus.org/" email="[email protected]">Jamie Shiell</vendor>

Expand All @@ -24,6 +24,7 @@
<change-notes>
<![CDATA[
<ul>
<li>5.74.1: Fixed: Ensure scope is checked as read action (#595).</li>
<li>5.74.0: New: Added Checkstyle 10.5.0 - thanks to @kennysoft (#596).</li>
<li>5.73.0: New: Added Checkstyle 10.4.</li>
<li>5.72.0: Now built against IDEA 2021.3.3 (was 2021.1.3).</li>
Expand Down

0 comments on commit 20de904

Please sign in to comment.