diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeModuleFiles.java b/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeModuleFiles.java index 12f66e6d..5cd27918 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeModuleFiles.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzeModuleFiles.java @@ -19,26 +19,19 @@ */ package org.jetbrains.plugins.spotbugs.actions; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DataKeys; -import com.intellij.openapi.compiler.CompileScope; -import com.intellij.openapi.compiler.CompilerManager; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.compiler.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.CompilerModuleExtension; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; import com.intellij.util.Consumer; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.*; import org.jetbrains.plugins.spotbugs.collectors.RecurseFileCollector; -import org.jetbrains.plugins.spotbugs.core.FindBugsProject; -import org.jetbrains.plugins.spotbugs.core.FindBugsProjects; -import org.jetbrains.plugins.spotbugs.core.FindBugsStarter; -import org.jetbrains.plugins.spotbugs.core.FindBugsState; +import org.jetbrains.plugins.spotbugs.core.*; import org.jetbrains.plugins.spotbugs.resources.ResourcesLoader; import java.io.File; @@ -117,6 +110,6 @@ protected boolean configure(@NotNull final ProgressIndicator indicator, @NotNull @Nullable private static Module getModule(@NotNull final AnActionEvent e) { - return DataKeys.MODULE.getData(e.getDataContext()); + return LangDataKeys.MODULE.getData(e.getDataContext()); } } diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/actions/ImportBugCollection.java b/src/main/java/org/jetbrains/plugins/spotbugs/actions/ImportBugCollection.java index b50fdf8f..e9ab308e 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/actions/ImportBugCollection.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/actions/ImportBugCollection.java @@ -23,40 +23,25 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogBuilder; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.Condition; +import com.intellij.openapi.ui.*; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindow; -import com.intellij.util.Processor; import com.intellij.util.containers.TransferToEDTQueue; -import edu.umd.cs.findbugs.BugInstance; -import edu.umd.cs.findbugs.Plugin; -import edu.umd.cs.findbugs.ProjectStats; -import edu.umd.cs.findbugs.SortedBugCollection; +import edu.umd.cs.findbugs.*; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.dom4j.DocumentException; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.spotbugs.common.EventDispatchThreadHelper; -import org.jetbrains.plugins.spotbugs.common.FindBugsPluginConstants; +import org.jetbrains.plugins.spotbugs.common.*; import org.jetbrains.plugins.spotbugs.common.util.New; -import org.jetbrains.plugins.spotbugs.core.Bug; -import org.jetbrains.plugins.spotbugs.core.FindBugsResult; -import org.jetbrains.plugins.spotbugs.core.FindBugsState; -import org.jetbrains.plugins.spotbugs.core.PluginSettings; -import org.jetbrains.plugins.spotbugs.core.ProjectSettings; -import org.jetbrains.plugins.spotbugs.core.WorkspaceSettings; -import org.jetbrains.plugins.spotbugs.gui.common.BalloonTipFactory; -import org.jetbrains.plugins.spotbugs.gui.common.ImportFileDialog; +import org.jetbrains.plugins.spotbugs.core.*; +import org.jetbrains.plugins.spotbugs.gui.common.*; import org.jetbrains.plugins.spotbugs.gui.toolwindow.view.ToolWindowPanel; import org.jetbrains.plugins.spotbugs.messages.MessageBusManager; import org.jetbrains.plugins.spotbugs.tasks.BackgroundableTask; import java.io.IOException; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.*; public final class ImportBugCollection extends AbstractAction { @@ -119,18 +104,10 @@ void actionPerformedImpl( } final AtomicBoolean taskCanceled = new AtomicBoolean(); - final TransferToEDTQueue transferToEDTQueue = new TransferToEDTQueue("Add New Bug Instance", new Processor() { - @Override - public boolean process(Runnable runnable) { - runnable.run(); - return true; - } - }, new Condition() { - @Override - public boolean value(Object o) { - return project.isDisposed() || taskCanceled.get(); - } - }, 500); + final TransferToEDTQueue transferToEDTQueue = new TransferToEDTQueue<>("Add New Bug Instance", runnable -> { + runnable.run(); + return true; + }, o -> project.isDisposed() || taskCanceled.get(), 500); //Create a task to import the bug collection from XML final BackgroundableTask task = new BackgroundableTask(project, "Importing Findbugs Result", true) { @@ -232,10 +209,6 @@ public ProgressIndicator getProgressIndicator() { } private static void showToolWindowErrorNotifier(@NotNull final Project project, final String message) { - EventDispatchThreadHelper.invokeLater(new Runnable() { - public void run() { - BalloonTipFactory.showToolWindowErrorNotifier(project, message); - } - }); + EventDispatchThreadHelper.invokeLater(() -> BalloonTipFactory.showToolWindowErrorNotifier(project, message)); } } 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 2898d0bb..fb4fb42c 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 @@ -21,8 +21,7 @@ import com.intellij.lang.Language; import com.intellij.lang.java.JavaLanguage; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.DataKeys; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.components.ComponentManager; import com.intellij.openapi.components.PathMacroManager; import com.intellij.openapi.editor.Document; @@ -62,16 +61,12 @@ @SuppressWarnings({"HardcodedFileSeparator"}) public final class IdeaUtilImpl { - @NotNull - private static final VirtualFile[] EMPTY_VIRTUAL_FILE = new VirtualFile[0]; - @NotNull - private static final String IDEA_PROJECT_DIR_VAR = "$PROJECT_DIR$"; - - private static final Set SUPPORTED_FILE_TYPES_EXT = new THashSet(Arrays.asList("java", "scala", "groovy", "gradle", "aj")); + private static final Set SUPPORTED_FILE_TYPES_EXT = new THashSet<>(Arrays + .asList("java", "scala", "groovy", "gradle", "aj")); public static final Set SUPPORTED_FILE_TYPES; static { - final THashSet supported = new THashSet(4); + final THashSet supported = new THashSet<>(4); supported.add(StdFileTypes.JAVA); supported.add(StdFileTypes.CLASS); final FileType scala = FileTypeManager.getInstance().getFileTypeByExtension("SCALA"); @@ -92,7 +87,7 @@ public final class IdeaUtilImpl { private static final Set SUPPORTED_LANGUAGES; static { - final THashSet supported = new THashSet(3); + final THashSet supported = new THashSet<>(3); supported.add(JavaLanguage.INSTANCE); final Language scala = Language.findLanguageByID("Scala"); if (scala != null) { @@ -140,7 +135,7 @@ public static File getProjectPath(@Nullable final Project project) { @Nullable public static Project getProject(@NotNull final DataContext dataContext) { - return DataKeys.PROJECT.getData(dataContext); + return PlatformDataKeys.PROJECT.getData(dataContext); } @@ -157,7 +152,7 @@ public static Project getProject(final PsiElement psiElement) { */ @Nullable private static PsiFile getPsiFile(@NotNull final DataContext dataContext) { - return DataKeys.PSI_FILE.getData(dataContext); + return PlatformDataKeys.PSI_FILE.getData(dataContext); } @@ -197,13 +192,13 @@ public static List getAllModifiedFiles(@NotNull final DataContext d @Nullable public static VirtualFile[] getVirtualFiles(@NotNull final DataContext dataContext) { - return DataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); + return PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); } @Nullable public static VirtualFile getVirtualFile(@NotNull final DataContext dataContext) { - return DataKeys.VIRTUAL_FILE.getData(dataContext); + return PlatformDataKeys.VIRTUAL_FILE.getData(dataContext); } @NotNull @@ -226,7 +221,7 @@ public static Module getModule(@NotNull final DataContext dataContext, @NotNull } if (module == null) { - module = DataKeys.MODULE.getData(dataContext); + module = LangDataKeys.MODULE.getData(dataContext); } if (module == null) { @@ -256,12 +251,12 @@ private static Module[] getModules(final Project project) { @Nullable private static PsiElement getCurrentElement(@NotNull final DataContext dataContext) { - /** + /* * Do not use "psi.Element" because this element could be contextless. */ //final PsiElement psiElement = (PsiElement) dataContext.getData("psi.Element"); - final Editor editor = DataKeys.EDITOR.getData(dataContext); + final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (editor != null) { final PsiFile psiFile = getPsiFile(dataContext); if (psiFile != null) { @@ -363,7 +358,7 @@ public static PsiClass findJavaPsiClass(@NotNull final Project project, @Nullabl @Nullable private static PsiClass findJavaPsiClass(final Project project, @NotNull final String dottedFqClassName, @NotNull final GlobalSearchScope searchScope) { - /** + /* * Do not use findClass(), the returned class is "random" (eg: could be ClsClassImpl or PsiClassImpl), see javadoc */ final PsiClass[] classes = JavaPsiFacade.getInstance(project).findClasses(dottedFqClassName, searchScope); diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/core/ChangeCollector.java b/src/main/java/org/jetbrains/plugins/spotbugs/core/ChangeCollector.java index 587ae5d8..9054b4d8 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/core/ChangeCollector.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/core/ChangeCollector.java @@ -28,15 +28,7 @@ import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VfsUtilCore; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileAdapter; -import com.intellij.openapi.vfs.VirtualFileCopyEvent; -import com.intellij.openapi.vfs.VirtualFileEvent; -import com.intellij.openapi.vfs.VirtualFileMoveEvent; -import com.intellij.openapi.vfs.VirtualFilePropertyEvent; -import com.intellij.openapi.vfs.VirtualFileVisitor; +import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.util.Function; import gnu.trove.THashSet; @@ -57,7 +49,7 @@ * @version $Revision: 343 $ * @since 0.9.995 */ -final class ChangeCollector extends VirtualFileAdapter { +final class ChangeCollector implements VirtualFileListener { ChangeCollector() { @@ -109,7 +101,7 @@ private static void processRecursively(final VirtualFile fromFile, final boolean return; } - VfsUtilCore.visitChildrenRecursively(fromFile, new VirtualFileVisitor() { + VfsUtilCore.visitChildrenRecursively(fromFile, new VirtualFileVisitor() { @NotNull @Override public Result visitFileEx(@NotNull VirtualFile file) { if (isIgnoredByBuild(file)) { @@ -152,23 +144,17 @@ private static boolean isInContentOfOpenedProject(@NotNull final VirtualFile fil } - private static final Function, Void> NOTIFY_CHANGED = new Function, Void>() { - public Void fun(Collection files) { - notifyFilesChanged(files); - return null; - } + private static final Function, Void> NOTIFY_CHANGED = files -> { + notifyFilesChanged(files); + return null; }; private static void collectPathsAndNotify(final VirtualFile file, final Function, Void> notification) { - final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); + final Set pathsToMark = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); if (!isIgnoredOrUnderIgnoredDirectory(file)) { final boolean inContent = isInContentOfOpenedProject(file); - processRecursively(file, !inContent, new FileProcessor() { - public void execute(final VirtualFile file) { - pathsToMark.add(new File(file.getPath())); - } - }); + processRecursively(file, !inContent, file1 -> pathsToMark.add(new File(file1.getPath()))); } if (!pathsToMark.isEmpty()) { notification.fun(pathsToMark); diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/core/FindBugsCompileAfterHook.java b/src/main/java/org/jetbrains/plugins/spotbugs/core/FindBugsCompileAfterHook.java index 1649a87d..f6cb525e 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/core/FindBugsCompileAfterHook.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/core/FindBugsCompileAfterHook.java @@ -60,7 +60,7 @@ public class FindBugsCompileAfterHook implements CompilationStatusListener, Proj private static ChangeCollector CHANGE_COLLECTOR; // EDT thread confinement static { - /** + /* * Note that ProjectData is cleared before BuildManagerListener#buildStarted is invoked, * so we can not use BuildManager.getInstance().getFilesChangedSinceLastCompilation(project). * There is no way to get the affect/compiled files (check with source of IC-140.2285.5). @@ -69,11 +69,11 @@ public class FindBugsCompileAfterHook implements CompilationStatusListener, Proj ApplicationManager.getApplication().getMessageBus().connect().subscribe(BuildManagerListener.TOPIC, new BuildManagerListener() { //@Override // introduced with IDEA 15 EA - public void beforeBuildProcessStarted(final Project project, final UUID sessionId) { + public void beforeBuildProcessStarted(final @NotNull Project project, final @NotNull UUID sessionId) { } @Override - public void buildStarted(final Project project, final UUID sessionId, final boolean isAutomake) { + public void buildStarted(final @NotNull Project project, final @NotNull UUID sessionId, final boolean isAutomake) { if (isAutomake && isAfterAutoMakeEnabled(project)) { final Set changed = Changes.INSTANCE.getAndRemoveChanged(project); if (changed != null) { @@ -83,7 +83,7 @@ public void buildStarted(final Project project, final UUID sessionId, final bool } @Override - public void buildFinished(final Project project, final UUID sessionId, final boolean isAutomake) { + public void buildFinished(final @NotNull Project project, final @NotNull UUID sessionId, final boolean isAutomake) { if (isAutomake) { final Set changed = CHANGED_BY_SESSION_ID.remove(sessionId); if (changed != null) { @@ -112,7 +112,7 @@ public FindBugsCompileAfterHook(@NotNull final Project project) { } @Override - public void compilationFinished(final boolean aborted, final int errors, final int warnings, final CompileContext compileContext) { + public void compilationFinished(final boolean aborted, final int errors, final int warnings, final @NotNull CompileContext compileContext) { // note that this is not invoked when auto make trigger compilation if (!aborted && errors == 0) { initWorker(compileContext); @@ -120,14 +120,13 @@ public void compilationFinished(final boolean aborted, final int errors, final i } @Override - public void fileGenerated(final String s, final String s1) { + public void fileGenerated(final @NotNull String s, final @NotNull String s1) { } @SuppressWarnings("UnusedDeclaration") public void fileGenerated(final String s) { } - @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") @NotNull @Override public String getComponentName() { @@ -242,41 +241,31 @@ private static boolean isAfterAutoMakeEnabled(@NotNull final Project project) { } private static void initWorkerForAutoMake(@NotNull final Project project, @NotNull final Collection changed) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - initWorkerForAutoMakeImpl(project, changed); - } - }); + ApplicationManager.getApplication().runReadAction(() -> initWorkerForAutoMakeImpl(project, changed)); } private static void initWorkerForAutoMakeImpl(@NotNull final Project project, @NotNull final Collection changed) { - EventDispatchThreadHelper.invokeLater(new Runnable() { + EventDispatchThreadHelper.invokeLater(() -> new FindBugsStarter( + project, + "Running SpotBugs analysis for affected files...", + ProgressStartType.RunInBackground + ) { @Override - public void run() { - new FindBugsStarter( - project, - "Running SpotBugs analysis for affected files...", - ProgressStartType.RunInBackground - ) { - @Override - protected boolean isCompileBeforeAnalyze() { - return false; - } + protected boolean isCompileBeforeAnalyze() { + return false; + } - @Override - protected void createCompileScope(@NotNull final CompilerManager compilerManager, @NotNull final Consumer consumer) { - throw new UnsupportedOperationException(); - } + @Override + protected void createCompileScope(@NotNull final CompilerManager compilerManager, @NotNull final Consumer consumer) { + throw new UnsupportedOperationException(); + } - @Override - protected boolean configure(@NotNull final ProgressIndicator indicator, @NotNull final FindBugsProjects projects, final boolean justCompiled) { - projects.addFiles(changed, false, hasTests(changed)); - return true; - } - }.start(); + @Override + protected boolean configure(@NotNull final ProgressIndicator indicator, @NotNull final FindBugsProjects projects, final boolean justCompiled) { + projects.addFiles(changed, false, hasTests(changed)); + return true; } - }); + }.start()); } private static class DelayedExecutor { @@ -286,7 +275,7 @@ private static class DelayedExecutor { DelayedExecutor(@NotNull final Project project) { _project = project; - _alarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD); + _alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD); } void schedule(@NotNull final Set changed) { @@ -302,19 +291,16 @@ void schedule(@NotNull final Set changed) { } private void addRequest() { - _alarm.addRequest(new Runnable() { - @Override - public void run() { - if (HeavyProcessLatch.INSTANCE.isRunning()) { - addRequest(); - } else { - final Set changed; - synchronized (DelayedExecutor.this) { - changed = _changed; - _changed = null; - } - initWorkerForAutoMake(_project, changed); + _alarm.addRequest(() -> { + if (HeavyProcessLatch.INSTANCE.isRunning()) { + addRequest(); + } else { + final Set changed; + synchronized (DelayedExecutor.this) { + changed = _changed; + _changed = null; } + initWorkerForAutoMake(_project, changed); } }, DELAY_MS); } diff --git a/src/main/java/org/jetbrains/plugins/spotbugs/intentions/SuppressReportBugIntentionAction.java b/src/main/java/org/jetbrains/plugins/spotbugs/intentions/SuppressReportBugIntentionAction.java index 74ee59a6..c6a4c542 100644 --- a/src/main/java/org/jetbrains/plugins/spotbugs/intentions/SuppressReportBugIntentionAction.java +++ b/src/main/java/org/jetbrains/plugins/spotbugs/intentions/SuppressReportBugIntentionAction.java @@ -153,8 +153,8 @@ public boolean isAvailable(@NotNull final Project project, final Editor editor, public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) throws IncorrectOperationException { if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) { - new Notification("SpotBugs Missing Feature", "Not Supported", "Sorry, insert annotation not supported for this language.", NotificationType.INFORMATION).notify(project); - /** + new Notification("SpotBugs Missing Feature", "Not supported", "Sorry, insert annotation not supported for this language.", NotificationType.INFORMATION).notify(project); + /* * FIXME Scala Plugin: * org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiElementFactory * crash with PsiManager and ScalaPsiManager#instance always return null @@ -170,7 +170,6 @@ public void invoke(@NotNull final Project project, final Editor editor, @NotNull if (!FileModificationServiceUtil.preparePsiElementForWrite(container)) { return; } - @SuppressWarnings({"ConstantConditions"}) final ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(container.getContainingFile().getVirtualFile()); if (status.hasReadonlyFiles()) { return;