mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
avoiding inspection instantiations: simple profile
This commit is contained in:
+6
-6
@@ -26,7 +26,10 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
@@ -102,11 +105,8 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
|
||||
inspectionContext.doInspections(scope, managerEx);
|
||||
}
|
||||
|
||||
public static GlobalInspectionContextImpl createContext(InspectionProfileEntry baseTool, InspectionManagerEx managerEx, PsiElement psiElement) {
|
||||
final InspectionProfileImpl profile = new InspectionProfileImpl(baseTool.getDisplayName());
|
||||
final InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
|
||||
model.disableAllTools();
|
||||
model.enableTool(baseTool.getShortName());
|
||||
public static GlobalInspectionContextImpl createContext(final InspectionProfileEntry baseTool, InspectionManagerEx managerEx, PsiElement psiElement) {
|
||||
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(baseTool.getDisplayName(), baseTool);
|
||||
try {
|
||||
Element element = new Element("toCopy");
|
||||
baseTool.writeSettings(element);
|
||||
|
||||
@@ -40,6 +40,8 @@ import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.SeverityProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
@@ -57,6 +59,13 @@ import java.util.*;
|
||||
public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, InspectionProfile, ExternalizableScheme {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
|
||||
@NonNls private static final String VALID_VERSION = "1.0";
|
||||
private static final Function<InspectionProfileEntry,InspectionToolWrapper> WRAPPER_FUNCTION =
|
||||
new Function<InspectionProfileEntry, InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper fun(InspectionProfileEntry tool) {
|
||||
return InspectionToolRegistrar.wrapTool(tool);
|
||||
}
|
||||
};
|
||||
|
||||
private Map<String, ToolsImpl> myTools = new THashMap<String, ToolsImpl>();
|
||||
|
||||
@@ -107,21 +116,30 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
copyFrom(inspectionProfile);
|
||||
}
|
||||
|
||||
public InspectionProfileImpl(final String inspectionProfile,
|
||||
public InspectionProfileImpl(final String profileName,
|
||||
final InspectionToolRegistrar registrar,
|
||||
final ProfileManager profileManager) {
|
||||
super(inspectionProfile);
|
||||
super(profileName);
|
||||
myRegistrar = registrar;
|
||||
myBaseProfile = getDefaultProfile();
|
||||
setProfileManager(profileManager);
|
||||
}
|
||||
|
||||
public InspectionProfileImpl(@NonNls String name) {
|
||||
super(name);
|
||||
public InspectionProfileImpl(@NonNls String profileName) {
|
||||
super(profileName);
|
||||
myRegistrar = InspectionToolRegistrar.getInstance();
|
||||
setProfileManager(InspectionProfileManager.getInstance());
|
||||
}
|
||||
|
||||
public static InspectionProfileImpl createSimple(String name, final InspectionProfileEntry... tools) {
|
||||
return new InspectionProfileImpl(name, new InspectionToolRegistrar(null) {
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
return ContainerUtil.map(tools, WRAPPER_FUNCTION);
|
||||
}
|
||||
}, InspectionProfileManager.getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionProfile getParentProfile() {
|
||||
return mySource;
|
||||
@@ -460,7 +478,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
|
||||
final List<InspectionToolWrapper> tools;
|
||||
try {
|
||||
tools = myRegistrar.createTools();
|
||||
tools = createTools();
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
return false;
|
||||
@@ -499,6 +517,10 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
return true;
|
||||
}
|
||||
|
||||
protected List<InspectionToolWrapper> createTools() {
|
||||
return myRegistrar.createTools();
|
||||
}
|
||||
|
||||
private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key) {
|
||||
final ToolsImpl tools = getTools(key.toString());
|
||||
LOG.assertTrue(tools != null, "profile name: " + myName + " base profile: " + (myBaseProfile != null ? myBaseProfile.getName() : "-") + " key: " + key);
|
||||
|
||||
+1
-12
@@ -444,18 +444,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final InspectionManagerEx inspectionManager,
|
||||
final InspectionTool... tools) {
|
||||
|
||||
InspectionToolRegistrar registrar = new InspectionToolRegistrar(null) {
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
return ContainerUtil.map(tools, new Function<InspectionTool, InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper fun(InspectionTool tool) {
|
||||
return tool instanceof InspectionToolWrapper ? (InspectionToolWrapper)tool : wrapTool(tool);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
final InspectionProfileImpl profile = new InspectionProfileImpl("test", registrar, InspectionProfileManager.getInstance());
|
||||
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", tools);
|
||||
GlobalInspectionContextImpl globalContext = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
|
||||
@Override
|
||||
protected List<ToolsImpl> getUsedTools() {
|
||||
|
||||
Reference in New Issue
Block a user