Skip to content

Commit

Permalink
Warnings fixed; deprecated API replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
amaembo committed Jun 4, 2020
1 parent ca18ca4 commit 4c55862
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -119,18 +104,10 @@ void actionPerformedImpl(
}

final AtomicBoolean taskCanceled = new AtomicBoolean();
final TransferToEDTQueue<Runnable> transferToEDTQueue = new TransferToEDTQueue<Runnable>("Add New Bug Instance", new Processor<Runnable>() {
@Override
public boolean process(Runnable runnable) {
runnable.run();
return true;
}
}, new Condition<Object>() {
@Override
public boolean value(Object o) {
return project.isDisposed() || taskCanceled.get();
}
}, 500);
final TransferToEDTQueue<Runnable> 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) {
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> SUPPORTED_FILE_TYPES_EXT = new THashSet<String>(Arrays.asList("java", "scala", "groovy", "gradle", "aj"));
private static final Set<String> SUPPORTED_FILE_TYPES_EXT = new THashSet<>(Arrays
.asList("java", "scala", "groovy", "gradle", "aj"));
public static final Set<FileType> SUPPORTED_FILE_TYPES;

static {
final THashSet<FileType> supported = new THashSet<FileType>(4);
final THashSet<FileType> supported = new THashSet<>(4);
supported.add(StdFileTypes.JAVA);
supported.add(StdFileTypes.CLASS);
final FileType scala = FileTypeManager.getInstance().getFileTypeByExtension("SCALA");
Expand All @@ -92,7 +87,7 @@ public final class IdeaUtilImpl {
private static final Set<Language> SUPPORTED_LANGUAGES;

static {
final THashSet<Language> supported = new THashSet<Language>(3);
final THashSet<Language> supported = new THashSet<>(3);
supported.add(JavaLanguage.INSTANCE);
final Language scala = Language.findLanguageByID("Scala");
if (scala != null) {
Expand Down Expand Up @@ -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);
}


Expand All @@ -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);
}


Expand Down Expand Up @@ -197,13 +192,13 @@ public static List<VirtualFile> 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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +49,7 @@
* @version $Revision: 343 $
* @since 0.9.995
*/
final class ChangeCollector extends VirtualFileAdapter {
final class ChangeCollector implements VirtualFileListener {


ChangeCollector() {
Expand Down Expand Up @@ -109,7 +101,7 @@ private static void processRecursively(final VirtualFile fromFile, final boolean
return;
}

VfsUtilCore.visitChildrenRecursively(fromFile, new VirtualFileVisitor() {
VfsUtilCore.visitChildrenRecursively(fromFile, new VirtualFileVisitor<VirtualFile>() {
@NotNull @Override
public Result visitFileEx(@NotNull VirtualFile file) {
if (isIgnoredByBuild(file)) {
Expand Down Expand Up @@ -152,23 +144,17 @@ private static boolean isInContentOfOpenedProject(@NotNull final VirtualFile fil
}


private static final Function<Collection<File>, Void> NOTIFY_CHANGED = new Function<Collection<File>, Void>() {
public Void fun(Collection<File> files) {
notifyFilesChanged(files);
return null;
}
private static final Function<Collection<File>, Void> NOTIFY_CHANGED = files -> {
notifyFilesChanged(files);
return null;
};


private static void collectPathsAndNotify(final VirtualFile file, final Function<Collection<File>, Void> notification) {
final Set<File> pathsToMark = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
final Set<File> 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);
Expand Down
Loading

0 comments on commit 4c55862

Please sign in to comment.