Skip to content

Commit

Permalink
Fix more deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
amaembo committed Dec 21, 2023
1 parent a562448 commit a81fd2d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ModelScopeItem> 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() {
Expand All @@ -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()};
}
};
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -174,9 +176,8 @@ public void visitFile(final PsiFile file) {
}
}
});
} finally {
psiManager.finishBatchFilesProcessingMode();
}
return null;
});
}

@NonNls
Expand Down Expand Up @@ -240,7 +241,7 @@ private AnalysisScope getInspectionScopeImpl(@NotNull final DataContext dataCont
return new AnalysisScope(psiDirectory);
}
}
final Set<VirtualFile> files = new HashSet<VirtualFile>();
final Set<VirtualFile> files = new HashSet<>();
for (VirtualFile vFile : virtualFiles) {
if (fileIndex.isInContent(vFile)) {
if (vFile instanceof VirtualFileWindow) {
Expand All @@ -260,7 +261,7 @@ private boolean acceptNonProjectDirectories() {
}

private static void collectFilesUnder(@NotNull final VirtualFile vFile, @NotNull final Collection<VirtualFile> files) {
VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor<Void>() {
@Override
public boolean visitFile(@NotNull final VirtualFile file) {
if (!file.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -68,8 +70,8 @@ public final class IdeaUtilImpl {

static {
final THashSet<FileType> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ synchronized void addChanged(@NotNull final Collection<File> paths) {
ProjectFileIndex index;
Set<VirtualFile> changesPerProject;
for (Project project : _listeners) {
index = ProjectFileIndex.SERVICE.getInstance( project );
index = ProjectFileIndex.getInstance( project );
changesPerProject = null;
for (VirtualFile f : vfs) {
if (index.isInSource(f)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectSettings> {

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,11 @@ public List<SuppressReportBugIntentionAction> getIntentionActions() {
@Override
public PopupStep<?> onChosen(final SuppressReportBugIntentionAction selectedValue, final boolean finalChoice) {
final Project project = _psiElement.getProject();
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable();


new WriteCommandAction.Simple/*<Object>*/(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);
}
Expand Down

0 comments on commit a81fd2d

Please sign in to comment.