mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
OC-6893 ("Run inspection by name" is not working)
This commit is contained in:
+3
-1
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.visibility.VisibilityInspection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -59,7 +60,8 @@ public class GlobalInspectionContextTest extends CodeInsightTestCase {
|
||||
InspectionProfileEntry[] tools = profile.getInspectionTools(null);
|
||||
for (InspectionProfileEntry tool : tools) {
|
||||
if (!tool.isEnabledByDefault()) {
|
||||
GlobalInspectionContextImpl context = RunInspectionIntention.createContext(tool, (InspectionManagerEx)InspectionManager.getInstance(myProject), null);
|
||||
GlobalInspectionContextImpl context = RunInspectionIntention.createContext(tool.getDisplayName(), Collections.singletonList(tool),
|
||||
(InspectionManagerEx)InspectionManager.getInstance(myProject), null);
|
||||
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
|
||||
assertEquals(1, context.getTools().size());
|
||||
return;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.ide.util.gotoByName.SimpleChooseByNameModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
@@ -89,6 +90,11 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
|
||||
return result.toArray(new InspectionProfileEntry[result.size()]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InspectionProfileEntry getProfileEntryByName(String shortName) {
|
||||
return myToolShortNames.get(shortName);
|
||||
}
|
||||
|
||||
public String getElementName(final Object element) {
|
||||
if (element instanceof InspectionProfileEntry) {
|
||||
final InspectionProfileEntry entry = (InspectionProfileEntry)element;
|
||||
|
||||
+22
-3
@@ -43,7 +43,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
@@ -78,15 +81,31 @@ public class RunInspectionAction extends GotoActionBase {
|
||||
public void elementChosen(ChooseByNamePopup popup, final Object element) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
runInspection(project, (InspectionProfileEntry)element, virtualFile, psiElement, psiFile);
|
||||
InspectionProfileEntry profileEntry = (InspectionProfileEntry)element;
|
||||
LinkedHashSet<InspectionProfileEntry> dependentEntries = new LinkedHashSet<InspectionProfileEntry>();
|
||||
collectDependentInspections(profileEntry, dependentEntries, model);
|
||||
runInspection(project, profileEntry.getDisplayName(), new ArrayList<InspectionProfileEntry>(dependentEntries), virtualFile, psiElement, psiFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void collectDependentInspections(@NotNull InspectionProfileEntry profileEntry,
|
||||
@NotNull LinkedHashSet<InspectionProfileEntry> dependentEntries,
|
||||
@NotNull GotoInspectionModel model) {
|
||||
dependentEntries.add(profileEntry);
|
||||
String mainToolId = profileEntry.getMainToolId();
|
||||
InspectionProfileEntry dependentEntry = mainToolId != null ? model.getProfileEntryByName(mainToolId) : null;
|
||||
|
||||
if (dependentEntry != null && !dependentEntries.contains(dependentEntry)) {
|
||||
collectDependentInspections(dependentEntry, dependentEntries, model);
|
||||
}
|
||||
}
|
||||
|
||||
private static void runInspection(@NotNull Project project,
|
||||
@NotNull InspectionProfileEntry profileEntry,
|
||||
@NotNull String profileName,
|
||||
@NotNull List<InspectionProfileEntry> profileEntries,
|
||||
@Nullable VirtualFile virtualFile,
|
||||
PsiElement psiElement, PsiFile psiFile) {
|
||||
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
|
||||
@@ -139,6 +158,6 @@ public class RunInspectionAction extends GotoActionBase {
|
||||
if (!dlg.isOK()) return;
|
||||
final AnalysisUIOptions uiOptions = AnalysisUIOptions.getInstance(project);
|
||||
scope = dlg.getScope(uiOptions, scope, project, module);
|
||||
RunInspectionIntention.rerunInspection(profileEntry, managerEx, scope, psiFile);
|
||||
RunInspectionIntention.rerunInspection(profileName, profileEntries, managerEx, scope, psiFile);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-8
@@ -42,6 +42,9 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 21-Feb-2006
|
||||
@@ -96,26 +99,31 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
|
||||
analysisScope = dlg.getScope(uiOptions, analysisScope, project, module);
|
||||
final InspectionProfileEntry baseTool =
|
||||
InspectionProjectProfileManager.getInstance(project).getInspectionProfile().getInspectionTool(myShortName, file);
|
||||
rerunInspection(baseTool, managerEx, analysisScope, file);
|
||||
rerunInspection(baseTool.getDisplayName(), Collections.singletonList(baseTool), managerEx, analysisScope, file);
|
||||
}
|
||||
|
||||
public static void rerunInspection(final InspectionProfileEntry baseTool, final InspectionManagerEx managerEx, final AnalysisScope scope,
|
||||
public static void rerunInspection(final String profileName, final List<InspectionProfileEntry> baseTools,
|
||||
final InspectionManagerEx managerEx, final AnalysisScope scope,
|
||||
PsiElement psiElement) {
|
||||
GlobalInspectionContextImpl inspectionContext = createContext(baseTool, managerEx, psiElement);
|
||||
GlobalInspectionContextImpl inspectionContext = createContext(profileName, baseTools, managerEx, psiElement);
|
||||
inspectionContext.doInspections(scope, managerEx);
|
||||
}
|
||||
|
||||
public static GlobalInspectionContextImpl createContext(final InspectionProfileEntry baseTool, InspectionManagerEx managerEx, PsiElement psiElement) {
|
||||
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(baseTool.getDisplayName(), baseTool);
|
||||
public static GlobalInspectionContextImpl createContext(final String profileName, final List<InspectionProfileEntry> baseTools,
|
||||
InspectionManagerEx managerEx, PsiElement psiElement) {
|
||||
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(profileName, baseTools);
|
||||
try {
|
||||
Element element = new Element("toCopy");
|
||||
baseTool.writeSettings(element);
|
||||
model.getInspectionTool(baseTool.getShortName(), psiElement).readSettings(element);
|
||||
|
||||
for (InspectionProfileEntry baseTool : baseTools) {
|
||||
baseTool.writeSettings(element);
|
||||
model.getInspectionTool(baseTool.getShortName(), psiElement).readSettings(element);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
//skip
|
||||
}
|
||||
model.setEditable(baseTool.getDisplayName());
|
||||
model.setEditable(profileName);
|
||||
final GlobalInspectionContextImpl inspectionContext = managerEx.createNewGlobalContext(false);
|
||||
inspectionContext.setExternalProfile(model);
|
||||
return inspectionContext;
|
||||
|
||||
@@ -130,7 +130,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
setProfileManager(InspectionProfileManager.getInstance());
|
||||
}
|
||||
|
||||
public static InspectionProfileImpl createSimple(String name, final InspectionProfileEntry... tools) {
|
||||
public static InspectionProfileImpl createSimple(String name, final List<InspectionProfileEntry> tools) {
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar(null) {
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
|
||||
+1
-1
@@ -463,7 +463,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final InspectionManagerEx inspectionManager,
|
||||
final InspectionTool... tools) {
|
||||
|
||||
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", tools);
|
||||
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", Arrays.<InspectionProfileEntry>asList(tools));
|
||||
GlobalInspectionContextImpl globalContext = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
|
||||
@Override
|
||||
protected List<ToolsImpl> getUsedTools() {
|
||||
|
||||
Reference in New Issue
Block a user