mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
improve IDEA-CR-15806 java & platform: write action is unnecessary in some quick fixes
This commit is contained in:
-5
@@ -162,11 +162,6 @@ public class UnnecessaryModuleDependencyInspection extends GlobalInspectionTool
|
||||
return "Remove dependency";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull CommonProblemDescriptor descriptor) {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
|
||||
+15
-23
@@ -27,7 +27,6 @@ import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefGraphAnnotator;
|
||||
import com.intellij.codeInspection.reference.RefManager;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -130,11 +129,6 @@ public class UnusedLibrariesInspection extends GlobalInspectionTool {
|
||||
myFiles = files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
@@ -145,27 +139,25 @@ public class UnusedLibrariesInspection extends GlobalInspectionTool {
|
||||
public void applyFix(@NotNull final Project project, @NotNull final CommonProblemDescriptor descriptor) {
|
||||
final Module module = myRefModule.getModule();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), myOrderEntry.getPresentableName())) {
|
||||
if (myFiles == null) {
|
||||
model.removeOrderEntry(entry);
|
||||
}
|
||||
else {
|
||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||
if (library != null) {
|
||||
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
for (VirtualFile file : myFiles) {
|
||||
modifiableModel.removeRoot(file.getUrl(), OrderRootType.CLASSES);
|
||||
}
|
||||
modifiableModel.commit();
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
for (OrderEntry entry : model.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), myOrderEntry.getPresentableName())) {
|
||||
if (myFiles == null) {
|
||||
model.removeOrderEntry(entry);
|
||||
}
|
||||
else {
|
||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||
if (library != null) {
|
||||
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
for (VirtualFile file : myFiles) {
|
||||
modifiableModel.removeRoot(file.getUrl(), OrderRootType.CLASSES);
|
||||
}
|
||||
modifiableModel.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
model.commit();
|
||||
});
|
||||
}
|
||||
model.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-11
@@ -19,7 +19,6 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.fileTemplates.impl.FileTemplateConfigurable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -98,16 +97,14 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT
|
||||
@Override
|
||||
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
|
||||
final FileTemplateConfigurable configurable = new FileTemplateConfigurable(project);
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
configurable.setTemplate(myTemplateToEdit, null);
|
||||
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
|
||||
if (ok) {
|
||||
WriteCommandAction.runWriteCommandAction(project, () -> {
|
||||
FileTemplateManager.getInstance(project).saveAllTemplates();
|
||||
myReplaceTemplateFix.applyFix(project, descriptor);
|
||||
});
|
||||
}
|
||||
});
|
||||
configurable.setTemplate(myTemplateToEdit, null);
|
||||
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
|
||||
if (ok) {
|
||||
WriteCommandAction.runWriteCommandAction(project, () -> {
|
||||
FileTemplateManager.getInstance(project).saveAllTemplates();
|
||||
myReplaceTemplateFix.applyFix(project, descriptor);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-5
@@ -126,11 +126,6 @@ public class EmptyDirectoryInspection extends BaseGlobalInspection {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
Reference in New Issue
Block a user