use InspectionToolWrapper instead of InspectionTool

This commit is contained in:
Alexey Kudravtsev
2013-06-17 10:34:58 +04:00
parent 9cf0ee63c8
commit 3cb9e4796b
61 changed files with 985 additions and 847 deletions
@@ -16,7 +16,7 @@
package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.InspectionTool;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
import com.intellij.psi.*;
@@ -32,8 +32,8 @@ public class RemoveRedundantUncheckedSuppressionTest extends LightQuickFixTestCa
final UncheckedWarningLocalInspection warningLocalInspection = new UncheckedWarningLocalInspection();
final RedundantSuppressInspection inspection = new RedundantSuppressInspection(){
@Override
protected InspectionTool[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
return new InspectionTool[]{
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
return new InspectionToolWrapper[]{
new LocalInspectionToolWrapper(varargsInspection),
new LocalInspectionToolWrapper(warningLocalInspection)
};
@@ -1,4 +1,3 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
@@ -19,7 +18,6 @@ package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance;
import com.intellij.codeInspection.deprecation.DeprecationInspection;
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection;
import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
@@ -33,7 +31,7 @@ public class Suppress15InspectionsTest extends LightQuickFixTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
enableInspectionTool(new GlobalInspectionToolWrapper(new UnusedParametersInspection()));
enableInspectionTool(new UnusedParametersInspection());
}
@NotNull
@@ -56,11 +56,12 @@ public class GlobalInspectionContextTest extends CodeInsightTestCase {
public void testRunInspectionContext() throws Exception {
InspectionProfile profile = new InspectionProfileImpl("foo");
InspectionProfileEntry[] tools = profile.getInspectionTools(null);
for (InspectionProfileEntry tool : tools) {
if (!tool.isEnabledByDefault()) {
GlobalInspectionContextImpl context = RunInspectionIntention.createContext(tool, (InspectionManagerEx)InspectionManager.getInstance(myProject), null);
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
InspectionToolWrapper[] tools = (InspectionToolWrapper[])profile.getInspectionTools(null);
for (InspectionToolWrapper toolWrapper : tools) {
if (!toolWrapper.isEnabledByDefault()) {
InspectionManagerEx instance = (InspectionManagerEx)InspectionManager.getInstance(myProject);
GlobalInspectionContextImpl context = RunInspectionIntention.createContext(toolWrapper, instance, null);
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
assertEquals(1, context.getTools().size());
return;
}
@@ -267,7 +267,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
context.setExternalProfile(profile);
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
}
public void testInspectionsInitialization() throws Exception {
@@ -299,11 +299,11 @@ public class InspectionProfileTest extends LightIdeaTestCase {
InspectionProfileImpl profile = new InspectionProfileImpl("profile");
profile.setBaseProfile(InspectionProfileImpl.getDefaultProfile());
assertEquals(0, countInitializedTools(profile));
InspectionProfileEntry[] tools = profile.getInspectionTools(null);
assertTrue(tools.length > 0);
InspectionProfileEntry tool = profile.getInspectionTool(new DataFlowInspection().getShortName());
assertNotNull(tool);
String id = tool.getShortName();
InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(null);
assertTrue(toolWrappers.length > 0);
InspectionToolWrapper toolWrapper = profile.getInspectionTool(new DataFlowInspection().getShortName());
assertNotNull(toolWrapper);
String id = toolWrapper.getShortName();
System.out.println(id);
if (profile.isToolEnabled(HighlightDisplayKey.findById(id))) {
profile.disableTool(id);
@@ -313,9 +313,9 @@ public class InspectionProfileTest extends LightIdeaTestCase {
}
assertEquals(0, countInitializedTools(profile));
profile.writeExternal(new Element("profile"));
List<InspectionProfileEntry> initializedTools = getInitializedTools(profile);
List<InspectionToolWrapper> initializedTools = getInitializedTools(profile);
if (initializedTools.size() != 1) {
for (InspectionProfileEntry initializedTool : initializedTools) {
for (InspectionToolWrapper initializedTool : initializedTools) {
System.out.println(initializedTool.getShortName());
}
fail();
@@ -340,14 +340,14 @@ public class InspectionProfileTest extends LightIdeaTestCase {
return getInitializedTools(foo).size();
}
public static List<InspectionProfileEntry> getInitializedTools(Profile foo) {
List<InspectionProfileEntry> initialized = new ArrayList<InspectionProfileEntry>();
@NotNull
public static List<InspectionToolWrapper> getInitializedTools(@NotNull Profile foo) {
List<InspectionToolWrapper> initialized = new ArrayList<InspectionToolWrapper>();
List<ScopeToolState> tools = ((InspectionProfileImpl)foo).getAllTools();
for (ScopeToolState tool : tools) {
InspectionProfileEntry entry = tool.getTool();
assertTrue(entry instanceof InspectionToolWrapper);
if (entry.isInitialized()) {
initialized.add(entry);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)tool.getTool();
if (toolWrapper.isInitialized()) {
initialized.add(toolWrapper);
}
}
return initialized;
@@ -8,19 +8,19 @@ import com.intellij.testFramework.InspectionTestCase;
public class RedundantSuppressTest extends InspectionTestCase {
private GlobalInspectionToolWrapper myWrapper;
private InspectionTool[] myInspectionTools;
private InspectionToolWrapper[] myInspectionToolWrappers;
@Override
protected void setUp() throws Exception {
super.setUp();
InspectionToolRegistrar.getInstance().ensureInitialized();
myInspectionTools = new InspectionTool[]{new LocalInspectionToolWrapper(new I18nInspection()),
myInspectionToolWrappers = new InspectionToolWrapper[]{new LocalInspectionToolWrapper(new I18nInspection()),
new GlobalInspectionToolWrapper(new EmptyMethodInspection())};
myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection() {
@Override
protected InspectionTool[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
return myInspectionTools;
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
return myInspectionToolWrappers;
}
});
}
@@ -17,6 +17,7 @@ package com.intellij.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.ex.CommonInspectionToolWrapper;
import com.intellij.codeInspection.ex.EntryPointsManagerImpl;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
@@ -40,7 +41,7 @@ public class UnusedDeclarationTest extends InspectionTestCase {
}
private void doTest() {
doTest("deadCode/" + getTestName(true), myTool);
doTest("deadCode/" + getTestName(true), new CommonInspectionToolWrapper(myTool));
}
public void testSCR6067() {
@@ -151,7 +152,7 @@ public class UnusedDeclarationTest extends InspectionTestCase {
public void testJunitAbstractClassWithoutInheritor() {
doTest();
}
public void testJunitEntryPointCustomRunWith() {
doTest();
}