mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
further inspection wrapper propagation
This commit is contained in:
+1
-1
@@ -126,7 +126,7 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
|
||||
if (!(toolById instanceof LocalInspectionToolWrapper)) {
|
||||
continue;
|
||||
}
|
||||
final LocalInspectionToolWrapper tool = new LocalInspectionToolWrapper(((LocalInspectionToolWrapper)toolById).getTool());
|
||||
final LocalInspectionToolWrapper tool = ((LocalInspectionToolWrapper)toolById).createCopy();
|
||||
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
|
||||
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
|
||||
tool.initialize(context);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -24,21 +24,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase {
|
||||
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/highlightSeverity";
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{
|
||||
new UnusedSymbolLocalInspection() {
|
||||
@NotNull
|
||||
@Override
|
||||
public HighlightDisplayLevel getDefaultLevel() {
|
||||
return HighlightDisplayLevel.ERROR;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void testErrorLikeUnusedSymbol() throws Exception {
|
||||
enableInspectionTool(new LocalInspectionToolWrapper(new UnusedSymbolLocalInspection()) {
|
||||
@NotNull
|
||||
@Override
|
||||
public HighlightDisplayLevel getDefaultLevel() {
|
||||
return HighlightDisplayLevel.ERROR;
|
||||
}
|
||||
});
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-19
@@ -28,10 +28,7 @@ import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.InspectionToolProvider;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ModifiableModel;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.ToolsImpl;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.lang.ExternalAnnotatorsFilter;
|
||||
@@ -98,7 +95,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
private final Map<String, InspectionProfileEntry> myAvailableTools = new THashMap<String, InspectionProfileEntry>();
|
||||
private final Map<String, LocalInspectionToolWrapper> myAvailableTools = new THashMap<String, LocalInspectionToolWrapper>();
|
||||
private final FileTreeAccessFilter myFileTreeAccessFilter = new FileTreeAccessFilter();
|
||||
|
||||
@Override
|
||||
@@ -125,14 +122,9 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
|
||||
Collection<InspectionProfileEntry> values = myAvailableTools.values();
|
||||
List<InspectionTool> result = new ArrayList<InspectionTool>();
|
||||
for (InspectionProfileEntry value : values) {
|
||||
InspectionTool tool = value instanceof InspectionTool ? (InspectionTool)value : new LocalInspectionToolWrapper((LocalInspectionTool)value);
|
||||
result.add(tool);
|
||||
}
|
||||
return result.toArray(new InspectionTool[result.size()]);
|
||||
public InspectionTool[] getInspectionTools(PsiElement element) {
|
||||
Collection<LocalInspectionToolWrapper> values = myAvailableTools.values();
|
||||
return values.toArray(new InspectionTool[values.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,8 +154,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
|
||||
@Override
|
||||
public InspectionTool getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
|
||||
InspectionProfileEntry entry = myAvailableTools.get(shortName);
|
||||
return entry == null ? null : entry instanceof InspectionTool ? (InspectionTool)entry : new LocalInspectionToolWrapper((LocalInspectionTool)entry);
|
||||
return myAvailableTools.get(shortName);
|
||||
}
|
||||
};
|
||||
final InspectionProfileManager inspectionProfileManager = InspectionProfileManager.getInstance();
|
||||
@@ -210,13 +201,13 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
protected void enableInspectionTool(InspectionProfileEntry tool){
|
||||
final String shortName = tool.getShortName();
|
||||
LocalInspectionToolWrapper wrapper = new LocalInspectionToolWrapper((LocalInspectionTool)tool);
|
||||
final String shortName = wrapper.getShortName();
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
|
||||
if (key == null) {
|
||||
assert tool instanceof LocalInspectionTool;
|
||||
HighlightDisplayKey.register(shortName, tool.getDisplayName(), ((LocalInspectionTool)tool).getID());
|
||||
HighlightDisplayKey.register(shortName, wrapper.getDisplayName(), wrapper.getID());
|
||||
}
|
||||
myAvailableTools.put(shortName, tool);
|
||||
myAvailableTools.put(shortName, wrapper);
|
||||
}
|
||||
|
||||
protected void enableInspectionToolsFromProvider(InspectionToolProvider toolProvider){
|
||||
|
||||
+4
-6
@@ -20,7 +20,6 @@ import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefVisitor;
|
||||
import com.intellij.codeInspection.ui.InspectionNode;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import org.jdom.Element;
|
||||
@@ -38,14 +37,13 @@ public class CommonInspectionToolWrapper extends InspectionToolWrapper<Inspectio
|
||||
super(tool);
|
||||
}
|
||||
|
||||
CommonInspectionToolWrapper(InspectionEP ep, InspectionTool tool) {
|
||||
super(ep, tool);
|
||||
private CommonInspectionToolWrapper(CommonInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CommonInspectionToolWrapper createCopy(InspectionToolWrapper<InspectionTool, InspectionEP> from) {
|
||||
return new CommonInspectionToolWrapper(from.myEP, from.myTool);
|
||||
public CommonInspectionToolWrapper createCopy() {
|
||||
return new CommonInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -29,13 +29,13 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalIns
|
||||
super(ep);
|
||||
}
|
||||
|
||||
public GlobalInspectionToolWrapper(InspectionEP ep, GlobalInspectionTool tool) {
|
||||
super(ep, tool);
|
||||
private GlobalInspectionToolWrapper(GlobalInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionToolWrapper<GlobalInspectionTool, InspectionEP> createCopy(InspectionToolWrapper<GlobalInspectionTool, InspectionEP> from) {
|
||||
return new GlobalInspectionToolWrapper(from.myEP, from.myTool);
|
||||
public InspectionToolWrapper<GlobalInspectionTool, InspectionEP> createCopy() {
|
||||
return new GlobalInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
public void initialize(@NotNull GlobalInspectionContextImpl context) {
|
||||
|
||||
@@ -530,7 +530,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
@NonNls String tempRoot = "config";
|
||||
Element config = new Element(tempRoot);
|
||||
tool.writeSettings(config);
|
||||
final InspectionTool inspectionTool = tool.createCopy(tool);
|
||||
final InspectionTool inspectionTool = tool.createCopy();
|
||||
inspectionTool.readSettings(config);
|
||||
return inspectionTool;
|
||||
}
|
||||
|
||||
@@ -109,8 +109,11 @@ public class InspectionToolRegistrar {
|
||||
}
|
||||
}
|
||||
|
||||
protected static InspectionToolWrapper wrapTool(InspectionProfileEntry profileEntry) {
|
||||
if (profileEntry instanceof LocalInspectionTool) {
|
||||
public static InspectionToolWrapper wrapTool(InspectionProfileEntry profileEntry) {
|
||||
if (profileEntry instanceof InspectionToolWrapper) {
|
||||
return (InspectionToolWrapper)profileEntry;
|
||||
}
|
||||
else if (profileEntry instanceof LocalInspectionTool) {
|
||||
return new LocalInspectionToolWrapper((LocalInspectionTool)profileEntry);
|
||||
}
|
||||
else if (profileEntry instanceof GlobalInspectionTool) {
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.WriteExternalException;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.net.URL;
|
||||
@@ -50,19 +49,19 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
myEP = null;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
protected InspectionToolWrapper(@Nullable T tool, @Nullable E ep) {
|
||||
myEP = ep;
|
||||
myTool = tool;
|
||||
}
|
||||
|
||||
protected InspectionToolWrapper(E ep, T tool) {
|
||||
myEP = ep;
|
||||
/** Copy ctor */
|
||||
protected InspectionToolWrapper(InspectionToolWrapper<T, E> other) {
|
||||
myEP = other.myEP;
|
||||
//noinspection unchecked
|
||||
myTool = tool == null ? null : (T)InspectionToolRegistrar.instantiateTool(tool.getClass());
|
||||
myTool = other.myTool == null ? null : (T)InspectionToolRegistrar.instantiateTool(other.myTool.getClass());
|
||||
}
|
||||
|
||||
public abstract InspectionToolWrapper<T, E> createCopy(InspectionToolWrapper<T, E> from);
|
||||
public abstract InspectionToolWrapper<T, E> createCopy();
|
||||
|
||||
@NotNull
|
||||
public T getTool() {
|
||||
|
||||
+21
-6
@@ -27,6 +27,8 @@ import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.TripleFunction;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
@@ -41,11 +43,12 @@ import java.util.*;
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public final class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspectionTool, LocalInspectionEP> {
|
||||
public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspectionTool, LocalInspectionEP> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.LocalInspectionToolWrapper");
|
||||
|
||||
/** This should be used in tests primarily */
|
||||
public LocalInspectionToolWrapper(@NotNull LocalInspectionTool tool) {
|
||||
super(tool);
|
||||
super(tool, ourEPMap.getValue().get(tool.getShortName()));
|
||||
}
|
||||
|
||||
public LocalInspectionToolWrapper(LocalInspectionEP ep) {
|
||||
@@ -57,13 +60,13 @@ public final class LocalInspectionToolWrapper extends InspectionToolWrapper<Loca
|
||||
super(tool, ep);
|
||||
}
|
||||
|
||||
public LocalInspectionToolWrapper(LocalInspectionEP ep, LocalInspectionTool tool) {
|
||||
super(ep, tool);
|
||||
private LocalInspectionToolWrapper(LocalInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionToolWrapper<LocalInspectionTool, LocalInspectionEP> createCopy(InspectionToolWrapper<LocalInspectionTool, LocalInspectionEP> from) {
|
||||
return new LocalInspectionToolWrapper(from.myEP, from.myTool);
|
||||
public LocalInspectionToolWrapper createCopy() {
|
||||
return new LocalInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
public void processFile(PsiFile file, final boolean filterSuppressed, final InspectionManager manager) {
|
||||
@@ -215,4 +218,16 @@ public final class LocalInspectionToolWrapper extends InspectionToolWrapper<Loca
|
||||
public boolean runForWholeFile() {
|
||||
return myEP == null ? getTool().runForWholeFile() : myEP.runForWholeFile;
|
||||
}
|
||||
|
||||
private final static NotNullLazyValue<Map<String, LocalInspectionEP>> ourEPMap = new NotNullLazyValue<Map<String, LocalInspectionEP>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, LocalInspectionEP> compute() {
|
||||
HashMap<String, LocalInspectionEP> map = new HashMap<String, LocalInspectionEP>();
|
||||
for (LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
|
||||
map.put(ep.shortName, ep);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class ToolsImpl implements Tools {
|
||||
}
|
||||
final String errorLevel = scopeElement.getAttributeValue(InspectionProfileImpl.LEVEL_TAG);
|
||||
final String enabledInScope = scopeElement.getAttributeValue(InspectionProfileImpl.ENABLED_TAG);
|
||||
final InspectionProfileEntry copyTool = tool.createCopy(tool);
|
||||
final InspectionProfileEntry copyTool = tool.createCopy();
|
||||
copyTool.readSettings(scopeElement);
|
||||
HighlightDisplayLevel scopeLevel = errorLevel != null ?
|
||||
HighlightDisplayLevel
|
||||
|
||||
@@ -308,7 +308,8 @@
|
||||
<localInspection language="XML" shortName="CheckTagEmptyBody" bundle="messages.XmlBundle" key="xml.inspections.check.tag.empty.body"
|
||||
groupKey="xml.inspections.group.name" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.intellij.xml.util.CheckTagEmptyBodyInspection"/>
|
||||
<localInspection language="XML" shortName="CheckDtdRefs" bundle="messages.XmlBundle" key="xml.inspections.check.dtd.references" groupName="XML"
|
||||
<!-- TODO: assign it to XML & DTD -->
|
||||
<localInspection shortName="CheckDtdRefs" bundle="messages.XmlBundle" key="xml.inspections.check.dtd.references" groupName="XML"
|
||||
enabledByDefault="true" level="ERROR" implementationClass="com.intellij.xml.util.CheckDtdReferencesInspection"/>
|
||||
<localInspection language="XML" shortName="CheckEmptyScriptTag" bundle="messages.XmlBundle" key="html.inspections.check.empty.tag" groupName="HTML"
|
||||
enabledByDefault="true" level="WARNING" implementationClass="com.intellij.xml.util.CheckEmptyTagInspection"/>
|
||||
|
||||
+1
-8
@@ -69,7 +69,6 @@ import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.extensions.ExtensionsArea;
|
||||
import com.intellij.openapi.fileEditor.*;
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
|
||||
@@ -153,7 +152,6 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@NonNls private static final String XXX = "XXX";
|
||||
private final FileTreeAccessFilter myJavaFilesFilter = new FileTreeAccessFilter();
|
||||
private boolean myAllowDirt;
|
||||
private final Map<String, LocalInspectionEP> myExtensions = new HashMap<String, LocalInspectionEP>();
|
||||
|
||||
public CodeInsightTestFixtureImpl(IdeaProjectTestFixture projectFixture, TempDirTestFixture tempDirTestFixture) {
|
||||
myProjectFixture = projectFixture;
|
||||
@@ -1048,10 +1046,6 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
|
||||
ensureIndexesUpToDate(getProject());
|
||||
((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities();
|
||||
LocalInspectionEP[] extensions = Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION);
|
||||
for (LocalInspectionEP extension : extensions) {
|
||||
myExtensions.put(extension.shortName, extension);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1086,8 +1080,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
InspectionTool inspectionTool;
|
||||
if (tool instanceof LocalInspectionTool) {
|
||||
LocalInspectionEP ep = myExtensions.get(tool.getShortName());
|
||||
inspectionTool = new LocalInspectionToolWrapper((LocalInspectionTool)tool, ep);
|
||||
inspectionTool = new LocalInspectionToolWrapper((LocalInspectionTool)tool);
|
||||
}
|
||||
else {
|
||||
inspectionTool = (InspectionTool)tool;
|
||||
|
||||
@@ -492,7 +492,7 @@
|
||||
level="WARNING" implementationClass="com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection" />
|
||||
|
||||
<localInspection language="JAVA" suppressId="unchecked" shortName="UNCHECKED_WARNING" displayName="Unchecked warning" groupName=""
|
||||
enabledByDefault="true" level="WARNING" unfair="true"
|
||||
enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection" />
|
||||
<localInspection language="JAVA" shortName="SuspiciousNameCombination" bundle="messages.InspectionsBundle"
|
||||
key="suspicious.name.combination.display.name" groupName="Probable bugs" enabledByDefault="true" level="WARNING"
|
||||
|
||||
Reference in New Issue
Block a user