diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeScopeFiles.java b/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeScopeFiles.java index f6e0cfab..2a5cce07 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeScopeFiles.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeScopeFiles.java @@ -20,6 +20,7 @@ package org.jetbrains.plugins.spotbugs.actions; import com.intellij.analysis.*; +import com.intellij.analysis.dialog.ModelScopeItem; import com.intellij.ide.highlighter.ArchiveFileType; import com.intellij.injected.editor.VirtualFileWindow; import com.intellij.openapi.actionSystem.ActionPlaces; @@ -28,12 +29,12 @@ import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.Result; import com.intellij.openapi.compiler.CompileScope; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.help.HelpManager; import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; @@ -63,6 +64,7 @@ import javax.swing.Action; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; public final class AnalyzeScopeFiles extends AbstractAnalyzeAction { @@ -94,12 +96,13 @@ void analyze( final boolean rememberScope = e.getPlace().equals(ActionPlaces.MAIN_MENU); final AnalysisUIOptions uiOptions = AnalysisUIOptions.getInstance(project); final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext); + String moduleName = module != null && scope.getScopeType() != AnalysisScope.MODULE ? getModuleNameInReadAction(module) : null; + List modelScopeItems = BaseAnalysisActionDialog.standardItems(project, scope, moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null, element); final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(ResourcesLoader.getString("analysis.specify.scope", "SpotBugs Analyze"), ResourcesLoader.getString("analysis.scope.title", "Analyze"), project, - scope, - module != null && scope.getScopeType() != AnalysisScope.MODULE ? getModuleNameInReadAction(module) : null, - rememberScope, AnalysisUIOptions.getInstance(project), element) { + modelScopeItems, + AnalysisUIOptions.getInstance(project), rememberScope) { @Override protected void doHelpAction() { @@ -109,7 +112,7 @@ protected void doHelpAction() { @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"}) @NotNull @Override - protected Action[] createActions() { + protected Action @NotNull [] createActions() { return new Action[]{getOKAction(), getCancelAction(), getHelpAction()}; } }; @@ -118,7 +121,7 @@ protected Action[] createActions() { return; } final int oldScopeType = uiOptions.SCOPE_TYPE; - scope = dlg.getScope(uiOptions, scope, project, module); + scope = dlg.getScope(scope); if (!rememberScope) { uiOptions.SCOPE_TYPE = oldScopeType; } @@ -158,12 +161,11 @@ private void addClasses( ) { final PsiManager psiManager = PsiManager.getInstance(project); - psiManager.startBatchFilesProcessingMode(); - final int[] count = new int[1]; - try { + psiManager.runInBatchFilesMode(() -> { + final int[] count = new int[1]; scope.accept(new PsiRecursiveElementVisitor() { @Override - public void visitFile(final PsiFile file) { + public void visitFile(final @NotNull PsiFile file) { if (indicator.isCanceled() || FindBugsState.get(project).isAborting()) { throw new ProcessCanceledException(); } @@ -174,9 +176,8 @@ public void visitFile(final PsiFile file) { } } }); - } finally { - psiManager.finishBatchFilesProcessingMode(); - } + return null; + }); } @NonNls @@ -240,7 +241,7 @@ private AnalysisScope getInspectionScopeImpl(@NotNull final DataContext dataCont return new AnalysisScope(psiDirectory); } } - final Set files = new HashSet(); + final Set files = new HashSet<>(); for (VirtualFile vFile : virtualFiles) { if (fileIndex.isInContent(vFile)) { if (vFile instanceof VirtualFileWindow) { @@ -260,7 +261,7 @@ private boolean acceptNonProjectDirectories() { } private static void collectFilesUnder(@NotNull final VirtualFile vFile, @NotNull final Collection files) { - VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() { + VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull final VirtualFile file) { if (!file.isDirectory()) { diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/common/util/IdeaUtilImpl.java b/src/main/java/org/jetbrains/plugins/spotbugs/common/util/IdeaUtilImpl.java index 1878fe3d..fc1b2dec 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/common/util/IdeaUtilImpl.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/common/util/IdeaUtilImpl.java @@ -19,6 +19,8 @@ */ package org.jetbrains.plugins.spotbugs.common.util; +import com.intellij.ide.highlighter.JavaClassFileType; +import com.intellij.ide.highlighter.JavaFileType; import com.intellij.lang.Language; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.actionSystem.*; @@ -68,8 +70,8 @@ public final class IdeaUtilImpl { static { final THashSet supported = new THashSet<>(4); - supported.add(StdFileTypes.JAVA); - supported.add(StdFileTypes.CLASS); + supported.add(JavaFileType.INSTANCE); + supported.add(JavaClassFileType.INSTANCE); final FileType scala = FileTypeManager.getInstance().getFileTypeByExtension("SCALA"); if (!(scala instanceof UnknownFileType)) { supported.add(scala); diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/core/Changes.java b/src/main/java/org/jetbrains/plugins/spotbugs/core/Changes.java index e33703ad..ace97866 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/core/Changes.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/core/Changes.java @@ -88,7 +88,7 @@ synchronized void addChanged(@NotNull final Collection paths) { ProjectFileIndex index; Set changesPerProject; for (Project project : _listeners) { - index = ProjectFileIndex.SERVICE.getInstance( project ); + index = ProjectFileIndex.getInstance( project ); changesPerProject = null; for (VirtualFile f : vfs) { if (index.isInSource(f)) { diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/core/ProjectSettings.java b/src/main/java/org/jetbrains/plugins/spotbugs/core/ProjectSettings.java index 82d0b7af..18099b1c 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/core/ProjectSettings.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/core/ProjectSettings.java @@ -23,32 +23,30 @@ import com.intellij.openapi.project.Project; import com.intellij.util.xmlb.XmlSerializerUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; @Service(Service.Level.PROJECT) @State( name = "FindBugs-IDEA", storages = { // Remove both @Storage entry below and use only this if IDEA 15 support is gone: @Storage("findbugs-idea.xml") - @Storage(file = "$PROJECT_FILE$"), - @Storage(file = "$PROJECT_CONFIG_DIR$/findbugs-idea.xml") + @Storage("$PROJECT_FILE$"), + @Storage("$PROJECT_CONFIG_DIR$/findbugs-idea.xml") } ) public final class ProjectSettings extends AbstractSettings implements PersistentStateComponent { - @Nullable @Override - public ProjectSettings getState() { + public @NotNull ProjectSettings getState() { return this; } @Override - public void loadState(final ProjectSettings state) { + public void loadState(final @NotNull ProjectSettings state) { XmlSerializerUtil.copyBean(state, this); } @NotNull public static ProjectSettings getInstance(@NotNull final Project project) { - return ServiceManager.getService(project, ProjectSettings.class); + return project.getService(ProjectSettings.class); } } diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/gui/intentions/GroupBugIntentionListPopupStep.java b/src/main/java/org/jetbrains/plugins/spotbugs/gui/intentions/GroupBugIntentionListPopupStep.java index 9cbaad88..b1c43a2f 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/gui/intentions/GroupBugIntentionListPopupStep.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/gui/intentions/GroupBugIntentionListPopupStep.java @@ -57,17 +57,11 @@ public List getIntentionActions() { @Override public PopupStep onChosen(final SuppressReportBugIntentionAction selectedValue, final boolean finalChoice) { final Project project = _psiElement.getProject(); - ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(); - - new WriteCommandAction.Simple/**/(project, "Add findbugs-idea Suppress warning", _psiElement.getContainingFile()) { - - @Override - protected void run() { - final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); - selectedValue.invoke(project, editor, _psiElement); - } - }.execute(); + WriteCommandAction.runWriteCommandAction(project, "Add findbugs-idea Suppress warning", null, () -> { + final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); + selectedValue.invoke(project, editor, _psiElement); + }, _psiElement.getContainingFile()); return super.onChosen(selectedValue, finalChoice); }