code cleanup: get rid of redundant Project parameter

This commit is contained in:
Dmitry Batkovich
2016-06-04 08:35:54 +03:00
parent b0cef7f3f3
commit 364f2dcd23
6 changed files with 21 additions and 24 deletions
@@ -56,7 +56,7 @@ public abstract class CleanupIntention implements IntentionAction, LowPriorityAc
final AnalysisScope scope = getScope(project, file);
if (scope != null) {
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
globalContext.codeCleanup(project, scope, profile, getText(), null, false);
globalContext.codeCleanup(scope, profile, getText(), null, false);
}
}
@@ -379,8 +379,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
}
}
public void codeCleanup(@NotNull Project project,
@NotNull AnalysisScope scope,
public void codeCleanup(@NotNull AnalysisScope scope,
@NotNull InspectionProfile profile,
@Nullable String commandName,
@Nullable Runnable postRunnable,
@@ -389,7 +388,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
public static void codeCleanup(@NotNull Project project, @NotNull AnalysisScope scope, @Nullable Runnable runnable) {
GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(false);
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
globalContext.codeCleanup(project, scope, profile, null, runnable, false);
globalContext.codeCleanup(scope, profile, null, runnable, false);
}
public static void cleanupElements(@NotNull final Project project, @Nullable final Runnable runnable, @NotNull PsiElement... scope) {
@@ -419,7 +418,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(false);
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
AnalysisScope analysisScope = new AnalysisScope(new LocalSearchScope(psiElements.toArray(new PsiElement[psiElements.size()])), project);
globalContext.codeCleanup(project, analysisScope, profile, null, runnable, true);
globalContext.codeCleanup(analysisScope, profile, null, runnable, true);
};
Application application = ApplicationManager.getApplication();
@@ -41,7 +41,7 @@ public class CodeCleanupAction extends CodeInspectionAction {
final InspectionProfile profile = myExternalProfile != null ? myExternalProfile : InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
final InspectionManager managerEx = InspectionManager.getInstance(project);
final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)managerEx.createNewGlobalContext(false);
globalContext.codeCleanup(project, scope, profile, getTemplatePresentation().getText(), null, false);
globalContext.codeCleanup(scope, profile, getTemplatePresentation().getText(), null, false);
}
@Override
@@ -181,7 +181,7 @@ public class RunInspectionAction extends GotoActionBase {
@Override
public void actionPerformed(ActionEvent e) {
managerEx.createNewGlobalContext(false)
.codeCleanup(project, getScope(), currentProfile, "Cleanup by " + toolWrapper.getDisplayName(), null, false);
.codeCleanup(getScope(), currentProfile, "Cleanup by " + toolWrapper.getDisplayName(), null, false);
close(DialogWrapper.OK_EXIT_CODE);
}
});
@@ -117,14 +117,14 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
public static void rerunInspection(@NotNull InspectionToolWrapper toolWrapper,
@NotNull InspectionManagerEx managerEx,
@NotNull AnalysisScope scope,
PsiElement psiElement) {
@Nullable PsiElement psiElement) {
GlobalInspectionContextImpl inspectionContext = createContext(toolWrapper, managerEx, psiElement);
inspectionContext.doInspections(scope);
}
public static GlobalInspectionContextImpl createContext(@NotNull InspectionToolWrapper toolWrapper,
@NotNull InspectionManagerEx managerEx,
PsiElement psiElement) {
@Nullable PsiElement psiElement) {
final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile();
LinkedHashSet<InspectionToolWrapper> allWrappers = new LinkedHashSet<InspectionToolWrapper>();
allWrappers.add(toolWrapper);
@@ -846,21 +846,20 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
}
@Override
public void codeCleanup(@NotNull final Project project,
@NotNull final AnalysisScope scope,
public void codeCleanup(@NotNull final AnalysisScope scope,
@NotNull final InspectionProfile profile,
@Nullable final String commandName,
@Nullable final Runnable postRunnable,
final boolean modal) {
Task task = modal ? new Task.Modal(project, "Inspect code...", true) {
Task task = modal ? new Task.Modal(getProject(), "Inspect code...", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
cleanup(scope, profile, project, postRunnable, commandName);
cleanup(scope, profile, postRunnable, commandName);
}
} : new Task.Backgroundable(project, "Inspect code...", true) {
} : new Task.Backgroundable(getProject(), "Inspect code...", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
cleanup(scope, profile, project, postRunnable, commandName);
cleanup(scope, profile, postRunnable, commandName);
}
};
ProgressManager.getInstance().run(task);
@@ -868,7 +867,6 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
private void cleanup(@NotNull final AnalysisScope scope,
@NotNull InspectionProfile profile,
@NotNull final Project project,
@Nullable final Runnable postRunnable,
@Nullable final String commandName) {
setCurrentScope(scope);
@@ -892,7 +890,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
else {
range = null;
}
final Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(project), tools -> {
final Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> {
assert tools != null;
return tools.getTool().getTool() instanceof CleanupLocalInspectionTool;
});
@@ -913,10 +911,10 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
}
if (!lTools.isEmpty()) {
final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(project).getDocument(file), range != null ? range.getStartOffset() : 0,
final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(getProject()).getDocument(file), range != null ? range.getStartOffset() : 0,
range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true,
HighlightInfoProcessor.getEmpty());
Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(project), lTools);
Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools);
ApplicationManager.getApplication().runReadAction(runnable);
final List<HighlightInfo> infos = pass.getInfos();
if (searchScope instanceof LocalSearchScope) {
@@ -950,12 +948,12 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
if (!FileModificationService.getInstance().preparePsiElementsForWrite(results.keySet())) return;
final String title = "Code Cleanup";
final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, title, true);
final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(getProject(), title, true);
progressTask.setMinIterationTime(200);
progressTask.setTask(new SequentialCleanupTask(project, results, progressTask));
CommandProcessor.getInstance().executeCommand(project, () -> {
progressTask.setTask(new SequentialCleanupTask(getProject(), results, progressTask));
CommandProcessor.getInstance().executeCommand(getProject(), () -> {
if (commandName != null) {
CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
CommandProcessor.getInstance().markCurrentCommandAsGlobal(getProject());
}
ProgressManager.getInstance().run(progressTask);
if (postRunnable != null) {
@@ -963,7 +961,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp
}
}, title, null);
};
TransactionGuard.submitTransaction(project, runnable);
TransactionGuard.submitTransaction(getProject(), runnable);
}
private static boolean isBinary(@NotNull PsiFile file) {