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
@@ -20,9 +20,8 @@
*/
package com.intellij.codeInsight.daemon;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ModifiableModel;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import org.jdom.Element;
@@ -53,8 +52,8 @@ public class JavaAwareInspectionProfileCoverter extends InspectionProfileConvert
super.fillErrorLevels(profile);
//javadoc attributes
final InspectionProfileEntry inspectionTool = profile.getInspectionTool(JavaDocLocalInspection.SHORT_NAME, null);
JavaDocLocalInspection inspection = (JavaDocLocalInspection)((LocalInspectionToolWrapper)inspectionTool).getTool();
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(JavaDocLocalInspection.SHORT_NAME, null);
JavaDocLocalInspection inspection = (JavaDocLocalInspection)toolWrapper.getTool();
inspection.myAdditionalJavadocTags = myAdditionalJavadocTags;
}
}
@@ -25,11 +25,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.LocalInspectionsPass;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
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.codeInspection.ex.*;
import com.intellij.codeInspection.reference.RefManagerImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@@ -122,20 +118,20 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
if (!(value instanceof String)) {
continue;
}
final InspectionProfileEntry toolById = ((InspectionProfileImpl)inspectionProfile).getToolById((String)value, target);
InspectionToolWrapper toolById = ((InspectionProfileImpl)inspectionProfile).getToolById((String)value, target);
if (!(toolById instanceof LocalInspectionToolWrapper)) {
continue;
}
final LocalInspectionToolWrapper tool = ((LocalInspectionToolWrapper)toolById).createCopy();
final LocalInspectionToolWrapper toolWrapper = ((LocalInspectionToolWrapper)toolById).createCopy();
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
tool.initialize(context);
toolWrapper.initialize(context);
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
Runnable inspect = new Runnable() {
@Override
public void run() {
pass.doInspectInBatch(managerEx, Collections.<LocalInspectionToolWrapper>singletonList(tool));
pass.doInspectInBatch(managerEx, Collections.<LocalInspectionToolWrapper>singletonList(toolWrapper));
}
};
if (indicator == null) {
@@ -141,7 +141,7 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
private void checkElement(final PsiElement owner) {
String idsString = SuppressManager.getInstance().getSuppressedInspectionIdsIn(owner);
if (idsString != null && idsString.length() != 0) {
if (idsString != null && !idsString.isEmpty()) {
List<String> ids = StringUtil.split(idsString, ",");
if (IGNORE_ALL && (ids.contains(SuppressionUtil.ALL) || ids.contains(SuppressionUtil.ALL.toLowerCase()))) return;
Collection<String> suppressed = suppressedScopes.get(owner);
@@ -162,27 +162,29 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
if (suppressedScopes.values().isEmpty()) return null;
// have to visit all file from scratch since inspections can be written in any perversive way including checkFile() overriding
Collection<InspectionTool> suppressedTools = new THashSet<InspectionTool>();
InspectionTool[] tools = getInspectionTools(psiElement, manager);
Collection<InspectionToolWrapper> suppressedTools = new THashSet<InspectionToolWrapper>();
InspectionToolWrapper[] toolWrappers = getInspectionTools(psiElement, manager);
for (Collection<String> ids : suppressedScopes.values()) {
for (Iterator<String> iterator = ids.iterator(); iterator.hasNext(); ) {
final String shortName = iterator.next().trim();
for (InspectionTool tool : tools) {
if (tool instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)tool).getTool().getID().equals(shortName)) {
if (!((LocalInspectionToolWrapper)tool).isUnfair()) {
suppressedTools.add(tool);
} else {
for (InspectionToolWrapper toolWrapper : toolWrappers) {
if (toolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)toolWrapper).getTool().getID().equals(shortName)) {
if (((LocalInspectionToolWrapper)toolWrapper).isUnfair()) {
iterator.remove();
break;
}
else {
suppressedTools.add(toolWrapper);
}
}
else if (tool.getShortName().equals(shortName)) {
else if (toolWrapper.getShortName().equals(shortName)) {
//ignore global unused as it won't be checked anyway
if (!(tool instanceof LocalInspectionToolWrapper) && !(tool instanceof GlobalInspectionToolWrapper)) {
if (toolWrapper instanceof LocalInspectionToolWrapper || toolWrapper instanceof GlobalInspectionToolWrapper) {
suppressedTools.add(toolWrapper);
}
else {
iterator.remove();
break;
} else {
suppressedTools.add(tool);
}
}
}
@@ -190,26 +192,26 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
}
final AnalysisScope scope = new AnalysisScope(psiElement.getContainingFile());
final InspectionManagerEx inspectionManagerEx = ((InspectionManagerEx)InspectionManager.getInstance(project));
final InspectionManagerEx inspectionManagerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
GlobalInspectionContextImpl globalContext = inspectionManagerEx.createNewGlobalContext(false);
globalContext.setCurrentScope(scope);
final RefManagerImpl refManager = ((RefManagerImpl)globalContext.getRefManager());
final RefManagerImpl refManager = (RefManagerImpl)globalContext.getRefManager();
refManager.inspectionReadActionStarted();
final List<ProblemDescriptor> result;
try {
result = new ArrayList<ProblemDescriptor>();
for (InspectionTool tool : suppressedTools) {
String toolId = tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getTool().getID() : tool.getShortName();
tool.initialize(globalContext);
for (InspectionToolWrapper toolWrapper : suppressedTools) {
String toolId = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getID() : toolWrapper.getShortName();
toolWrapper.initialize(globalContext);
Collection<CommonProblemDescriptor> descriptors;
if (tool instanceof LocalInspectionToolWrapper) {
LocalInspectionToolWrapper local = (LocalInspectionToolWrapper)tool;
if (toolWrapper instanceof LocalInspectionToolWrapper) {
LocalInspectionToolWrapper local = (LocalInspectionToolWrapper)toolWrapper;
if (local.isUnfair()) continue; //cant't work with passes other than LocalInspectionPass
local.processFile(psiElement.getContainingFile(), false, manager);
descriptors = local.getProblemDescriptors();
}
else if (tool instanceof GlobalInspectionToolWrapper) {
GlobalInspectionToolWrapper global = (GlobalInspectionToolWrapper)tool;
else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
GlobalInspectionToolWrapper global = (GlobalInspectionToolWrapper)toolWrapper;
if (global.getTool().isGraphNeeded()) {
refManager.findAllDeclarations();
}
@@ -283,13 +285,12 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
return result.toArray(new ProblemDescriptor[result.size()]);
}
protected InspectionTool[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
final ModifiableModel
model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel();
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
ModifiableModel model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel();
InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile)model);
profile.init(manager.getProject());
return profile.getInspectionTools(psiElement);
return (InspectionToolWrapper[])profile.getInspectionTools(psiElement);
}
@@ -23,7 +23,6 @@ package com.intellij.codeInspection.ex;
import com.intellij.CommonBundle;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.reference.*;
import com.intellij.lang.StdLanguages;
import com.intellij.openapi.application.ApplicationManager;
@@ -413,32 +412,26 @@ public class GlobalJavaInspectionContextImpl extends GlobalJavaInspectionContext
}
@Override
public void performPreRunActivities(final List<Tools> globalTools, final List<Tools> localTools,
final GlobalInspectionContext context) {
public void performPreRunActivities(@NotNull final List<Tools> globalTools,
@NotNull final List<Tools> localTools,
@NotNull final GlobalInspectionContext context) {
getEntryPointsManager(context.getRefManager()).resolveEntryPoints(context.getRefManager());
for (int i = 0; i < globalTools.size(); i++) {
InspectionProfileEntry tool = globalTools.get(i).getTool();
if (UnusedDeclarationInspection.SHORT_NAME.equals(tool.getShortName())) {
Collections.swap(globalTools, i, 0);
break;
}
}
}
@Override
public void performPostRunActivities(List<InspectionProfileEntry> needRepeatSearchRequest, final GlobalInspectionContext context) {
public void performPostRunActivities(@NotNull List<InspectionProfileEntry> needRepeatSearchRequest, @NotNull final GlobalInspectionContext context) {
JobDescriptor progress = context.getStdJobDescriptors().FIND_EXTERNAL_USAGES;
progress.setTotalAmount(getRequestCount());
do {
processSearchRequests(context);
InspectionProfileEntry[] requestors = needRepeatSearchRequest.toArray(new InspectionProfileEntry[needRepeatSearchRequest.size()]);
for (InspectionProfileEntry requestor : requestors) {
if (requestor instanceof InspectionTool &&
!((InspectionTool)requestor).queryExternalUsagesRequests(InspectionManager.getInstance(context.getProject()))) {
needRepeatSearchRequest.remove(requestor);
InspectionToolWrapper[] requestors = needRepeatSearchRequest.toArray(new InspectionToolWrapper[needRepeatSearchRequest.size()]);
for (InspectionToolWrapper wrapper : requestors) {
InspectionProfileEntry requestor = wrapper.getTool();
if (requestor instanceof InspectionTool && !((InspectionTool)requestor).queryExternalUsagesRequests(InspectionManager.getInstance(context.getProject()))) {
needRepeatSearchRequest.remove(wrapper);
}
}
int oldSearchRequestCount = progress.getTotalAmount();
@@ -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();
}
@@ -119,16 +119,17 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
@Override
@NotNull
public InspectionTool[] getInspectionTools(PsiElement element) {
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
Collection<InspectionToolWrapper> values = myAvailableTools.values();
return values.toArray(new InspectionTool[values.size()]);
return values.toArray(new InspectionToolWrapper[values.size()]);
}
@NotNull
@Override
public List<ToolsImpl> getAllEnabledInspectionTools(Project project) {
List<ToolsImpl> result = new ArrayList<ToolsImpl>();
for (InspectionProfileEntry entry : getInspectionTools(null)) {
result.add(new ToolsImpl(entry, entry.getDefaultLevel(), true));
public List<Tools> getAllEnabledInspectionTools(Project project) {
List<Tools> result = new ArrayList<Tools>();
for (InspectionToolWrapper toolWrapper : getInspectionTools(null)) {
result.add(new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true));
}
return result;
}
@@ -140,12 +141,12 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
@Override
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, PsiElement element) {
final InspectionProfileEntry localInspectionTool = myAvailableTools.get(key.toString());
final InspectionToolWrapper localInspectionTool = myAvailableTools.get(key.toString());
return localInspectionTool != null ? localInspectionTool.getDefaultLevel() : HighlightDisplayLevel.WARNING;
}
@Override
public InspectionTool getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
return myAvailableTools.get(shortName);
}
};
@@ -192,7 +193,8 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
//((VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance()).assertPointersDisposed();
}
protected void enableInspectionTool(InspectionProfileEntry tool){
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool){
assert !(tool instanceof InspectionToolWrapper) : tool;
InspectionToolWrapper wrapper = InspectionToolRegistrar.wrapTool(tool);
final String shortName = wrapper.getShortName();
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
@@ -76,11 +76,11 @@ public abstract class InspectionTestCase extends PsiTestCase {
doTest(folderName, new GlobalInspectionToolWrapper(tool), "java 1.4", checkRange, runDeadCodeFirst);
}
public void doTest(@NonNls String folderName, InspectionTool tool) {
public void doTest(@NonNls String folderName, InspectionToolWrapper tool) {
doTest(folderName, tool, "java 1.4");
}
public void doTest(@NonNls String folderName, InspectionTool tool, final boolean checkRange) {
public void doTest(@NonNls String folderName, InspectionToolWrapper tool, final boolean checkRange) {
doTest(folderName, tool, "java 1.4", checkRange);
}
@@ -88,35 +88,35 @@ public abstract class InspectionTestCase extends PsiTestCase {
doTest(folderName, new LocalInspectionToolWrapper(tool), jdkName);
}
public void doTest(@NonNls String folderName, InspectionTool tool, @NonNls final String jdkName) {
public void doTest(@NonNls String folderName, InspectionToolWrapper tool, @NonNls final String jdkName) {
doTest(folderName, tool, jdkName, false);
}
public void doTest(@NonNls String folderName, InspectionTool tool, @NonNls final String jdkName, boolean checkRange) {
public void doTest(@NonNls String folderName, InspectionToolWrapper tool, @NonNls final String jdkName, boolean checkRange) {
doTest(folderName, tool, jdkName, checkRange, false);
}
public void doTest(@NonNls String folderName,
InspectionTool tool,
InspectionToolWrapper toolWrapper,
@NonNls final String jdkName,
boolean checkRange,
boolean runDeadCodeFirst,
InspectionTool... additional) {
InspectionToolWrapper... additional) {
final String testDir = getTestDataPath() + "/" + folderName;
runTool(testDir, jdkName, runDeadCodeFirst, tool, additional);
runTool(testDir, jdkName, runDeadCodeFirst, toolWrapper, additional);
InspectionTestUtil.compareToolResults(tool, checkRange, testDir);
InspectionTestUtil.compareToolResults(toolWrapper, checkRange, testDir);
}
protected void runTool(@NonNls final String testDir, @NonNls final String jdkName, final InspectionTool tool) {
protected void runTool(@NonNls final String testDir, @NonNls final String jdkName, final InspectionToolWrapper tool) {
runTool(testDir, jdkName, false, tool);
}
protected void runTool(final String testDir,
final String jdkName,
boolean runDeadCodeFirst,
final InspectionTool tool,
InspectionTool... additional) {
final InspectionToolWrapper toolWrapper,
@NotNull InspectionToolWrapper... additional) {
final VirtualFile[] sourceDir = new VirtualFile[1];
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
@@ -132,12 +132,12 @@ public abstract class InspectionTestCase extends PsiTestCase {
AnalysisScope scope = createAnalysisScope(sourceDir[0].getParent());
InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
InspectionTool[] tools = runDeadCodeFirst ? new InspectionTool[]{new UnusedDeclarationInspection(), tool} : new InspectionTool[]{tool};
tools = ArrayUtil.mergeArrays(tools, additional);
InspectionToolWrapper[] toolWrappers = runDeadCodeFirst ? new InspectionToolWrapper []{new CommonInspectionToolWrapper(new UnusedDeclarationInspection()), toolWrapper} : new InspectionToolWrapper []{toolWrapper};
toolWrappers = ArrayUtil.mergeArrays(toolWrappers, additional);
final GlobalInspectionContextImpl globalContext =
CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, tools);
CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrappers);
InspectionTestUtil.runTool(tool, scope, globalContext, inspectionManager);
InspectionTestUtil.runTool(toolWrapper, scope, globalContext, inspectionManager);
}
protected AnalysisScope createAnalysisScope(VirtualFile sourceDir) {
@@ -18,6 +18,7 @@ package com.intellij.codeInspection;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.ex.Tools;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.profile.Profile;
@@ -26,6 +27,8 @@ import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* User: anna
* Date: Dec 7, 2004
@@ -37,6 +40,7 @@ public interface InspectionProfile extends Profile {
/**
* If you need to modify tool's settings, please use {@link #modifyToolSettings}
*/
// InspectionProfileWrapper
InspectionProfileEntry getInspectionTool(@NotNull String shortName, @NotNull PsiElement element);
@Nullable
@@ -61,7 +65,7 @@ public interface InspectionProfile extends Profile {
* @since 12.1
*/
<T extends InspectionProfileEntry>
void modifyToolSettings(Key<T> shortNameKey, @NotNull PsiElement psiElement, Consumer<T> toolConsumer);
void modifyToolSettings(@NotNull Key<T> shortNameKey, @NotNull PsiElement psiElement, @NotNull Consumer<T> toolConsumer);
/**
* @param element context element
@@ -70,7 +74,7 @@ public interface InspectionProfile extends Profile {
@NotNull
InspectionProfileEntry[] getInspectionTools(@Nullable PsiElement element);
void cleanup(Project project);
void cleanup(@NotNull Project project);
/**
* @see #modifyProfile(com.intellij.util.Consumer)
@@ -90,4 +94,7 @@ public interface InspectionProfile extends Profile {
String getDisplayName();
void scopesChanged();
@NotNull
List<Tools> getAllEnabledInspectionTools(Project project);
}
@@ -56,6 +56,10 @@ public abstract class InspectionProfileEntry {
private static final Object BLACK_LIST_LOCK = new Object();
private Boolean myUseNewSerializer = null;
public void cleanup() {
}
interface DefaultNameProvider {
@Nullable String getDefaultShortName();
@Nullable String getDefaultDisplayName();
@@ -16,16 +16,15 @@
package com.intellij.codeInspection;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.*;
import org.intellij.lang.annotations.Language;
import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author max
*/
@@ -172,4 +171,29 @@ public abstract class LocalInspectionTool extends InspectionProfileEntry {
@Deprecated()
public void inspectionFinished(@NotNull LocalInspectionToolSession session) {}
@NotNull
public List<ProblemDescriptor> processFile(@NotNull PsiFile file,
@NotNull InspectionManager manager) {
final ProblemsHolder holder = new ProblemsHolder(manager, file, false);
LocalInspectionToolSession session = new LocalInspectionToolSession(file, 0, file.getTextLength());
final PsiElementVisitor customVisitor = buildVisitor(holder, false, session);
LOG.assertTrue(!(customVisitor instanceof PsiRecursiveElementVisitor),
"The visitor returned from LocalInspectionTool.buildVisitor() must not be recursive");
inspectionStarted(session, false);
file.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
element.accept(customVisitor);
super.visitElement(element);
}
});
inspectionFinished(session, holder);
return holder.getResults();
}
}
@@ -39,7 +39,7 @@ public class ScopeToolState {
private NamedScope myScope;
@NotNull
private final String myScopeName;
private InspectionProfileEntry myTool;
private /*InspectionToolWrapper*/InspectionProfileEntry myTool;
private boolean myEnabled;
private HighlightDisplayLevel myLevel;
@@ -73,6 +73,7 @@ public class ScopeToolState {
return myScopeName;
}
// InspectionToolWrapper
@NotNull
public InspectionProfileEntry getTool() {
return myTool;
@@ -18,6 +18,7 @@ package com.intellij.codeInspection.ex;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
@@ -26,7 +27,6 @@ import com.intellij.util.Function;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -40,40 +40,29 @@ public class InspectionProfileWrapper {
/**
* Key that is assumed to hold strategy that customizes {@link InspectionProfileWrapper} object to use.
* <p/>
* I.e. given strategy (if any) receives {@link InspectionProfileWrapper} object that is going to be used so far and returns
* I.e. given strategy (if any) receives {@link InspectionProfileWrapper} object that is going to be used so far and returns
* {@link InspectionProfileWrapper} object that should be used later.
*/
public static final Key<Function<InspectionProfileWrapper, InspectionProfileWrapper>> CUSTOMIZATION_KEY
= Key.create("Inspection Profile Wrapper Customization");
private final InspectionProfileImpl myProfile;
protected final InspectionProfile myProfile;
public InspectionProfileWrapper(final InspectionProfile profile) {
myProfile = (InspectionProfileImpl)profile;
public InspectionProfileWrapper(@NotNull InspectionProfile profile) {
myProfile = profile;
}
public InspectionTool[] getInspectionTools(PsiElement element){
return (InspectionTool[])myProfile.getInspectionTools(element);
}
public List<LocalInspectionToolWrapper> getHighlightingLocalInspectionTools(PsiElement element) {
List<LocalInspectionToolWrapper> enabled = new ArrayList<LocalInspectionToolWrapper>();
final InspectionTool[] tools = getInspectionTools(element);
checkInspectionsDuplicates(tools);
for (InspectionTool tool : tools) {
if (tool instanceof LocalInspectionToolWrapper && myProfile.isToolEnabled(HighlightDisplayKey.find(tool.getShortName()), element)) {
enabled.add((LocalInspectionToolWrapper)tool);
}
}
return enabled;
@NotNull
public InspectionProfileEntry[] getInspectionTools(PsiElement element){
return myProfile.getInspectionTools(element);
}
// check whether some inspection got registered twice by accident. 've bit once.
private static boolean alreadyChecked;
private static void checkInspectionsDuplicates(@NotNull InspectionTool[] tools) {
public static void checkInspectionsDuplicates(@NotNull InspectionProfileEntry[] tools) {
if (alreadyChecked) return;
alreadyChecked = true;
Set<InspectionTool> uniqTools = new THashSet<InspectionTool>(tools.length);
for (InspectionTool tool : tools) {
Set<InspectionProfileEntry> uniqTools = new THashSet<InspectionProfileEntry>(tools.length);
for (InspectionProfileEntry tool : tools) {
if (!uniqTools.add(tool)) {
LOG.error("Inspection " + tool.getDisplayName() + " (" + tool.getClass() + ") already registered");
}
@@ -92,12 +81,13 @@ public class InspectionProfileWrapper {
return myProfile.isToolEnabled(key);
}
public InspectionTool getInspectionTool(final String shortName, PsiElement element) {
return (InspectionTool)myProfile.getInspectionTool(shortName, element);
// InspectionToolWrapper
public InspectionProfileEntry getInspectionTool(final String shortName, PsiElement element) {
return myProfile.getInspectionTool(shortName, element);
}
public void init(final Project project) {
final List<ToolsImpl> profileEntries = myProfile.getAllEnabledInspectionTools(project);
final List<Tools> profileEntries = myProfile.getAllEnabledInspectionTools(project);
for (Tools profileEntry : profileEntries) {
for (ScopeToolState toolState : profileEntry.getTools()) {
toolState.getTool().projectOpened(project);
@@ -105,10 +95,11 @@ public class InspectionProfileWrapper {
}
}
public void cleanup(final Project project){
public void cleanup(@NotNull Project project){
myProfile.cleanup(project);
}
@NotNull
public InspectionProfile getInspectionProfile() {
return myProfile;
}
@@ -27,20 +27,18 @@ import org.jetbrains.annotations.NotNull;
* User: anna
* Date: 01-Dec-2005
*/
public class ProfileEx implements Profile {
public abstract class ProfileEx implements Profile {
public String myName;
private static final Logger LOG = Logger.getInstance("com.intellij.profile.ProfileEx");
public boolean myLocal = true;
protected ProfileManager myProfileManager;
@NonNls public static final String SCOPE = "scope";
public static final String NAME = "name";
public ProfileEx(@NotNull String name) {
myName = name;
}
public ProfileEx(@NotNull String name, final Element element) {
this(name);
}
@Override
public String getName() {
return myName;
@@ -72,7 +70,7 @@ public class ProfileEx implements Profile {
}
@Override
public void setName(String name) {
public void setName(@NotNull String name) {
myName = name;
}
@@ -119,4 +117,6 @@ public class ProfileEx implements Profile {
}
return 0;
}
public void convert(@NotNull Element element) {}
}
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
* Date: 4/20/11
* Time: 9:27 PM
*/
public class IntentionWrapper implements LocalQuickFix, IntentionAction {
public class IntentionWrapper implements LocalQuickFix, IntentionAction, ActionClassHolder {
private final IntentionAction myAction;
private final PsiFile myFile;
@@ -74,6 +74,7 @@ public class IntentionWrapper implements LocalQuickFix, IntentionAction {
return myAction.startInWriteAction();
}
@NotNull
public IntentionAction getAction() {
return myAction;
}
@@ -87,5 +88,11 @@ public class IntentionWrapper implements LocalQuickFix, IntentionAction {
myAction.invoke(project, editor instanceof TextEditor ? ((TextEditor) editor).getEditor() : null, myFile);
}
}
@NotNull
@Override
public Class getActionClass() {
return getAction().getClass();
}
}
@@ -18,9 +18,9 @@ package com.intellij.codeInsight.daemon;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ModifiableModel;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
@@ -116,9 +116,9 @@ public class InspectionProfileConvertor {
public static Element convertToNewFormat(Element profileFile, InspectionProfile profile) throws IOException, JDOMException {
Element rootElement = new Element(INSPECTIONS_TAG);
rootElement.setAttribute(NAME_ATT, profile.getName());
final InspectionProfileEntry[] tools = profile.getInspectionTools(null);
final InspectionToolWrapper[] tools = (InspectionToolWrapper[])profile.getInspectionTools(null);
for (final Object o : profileFile.getChildren(INSP_TOOL_TAG)) {
Element toolElement = (Element)((Element)o).clone();
Element toolElement = ((Element)o).clone();
String toolClassName = toolElement.getAttributeValue(CLASS_ATT);
final String shortName = convertToShortName(toolClassName, tools);
if (shortName == null) {
@@ -162,8 +162,8 @@ public class InspectionProfileConvertor {
}
protected void fillErrorLevels(final ModifiableModel profile) {
InspectionProfileEntry[] tools = profile.getInspectionTools(null);
LOG.assertTrue(tools != null, "Profile was not correctly init");
InspectionToolWrapper[] toolWrappers = (InspectionToolWrapper[])profile.getInspectionTools(null);
LOG.assertTrue(toolWrappers != null, "Profile was not correctly init");
//fill error levels
for (final String shortName : myDisplayLevelMap.keySet()) {
//key <-> short name
@@ -187,9 +187,9 @@ public class InspectionProfileConvertor {
@Nullable
private static String convertToShortName(String displayName, InspectionProfileEntry[] tools) {
private static String convertToShortName(String displayName, InspectionToolWrapper[] tools) {
if (displayName == null) return null;
for (InspectionProfileEntry tool : tools) {
for (InspectionToolWrapper tool : tools) {
if (displayName.equals(tool.getDisplayName())) {
return tool.getShortName();
}
@@ -651,10 +651,14 @@ public class HighlightInfo implements Segment {
}
private static void appendFixes(@Nullable TextRange fixedRange, HighlightInfo info, List<Annotation.QuickFixInfo> fixes) {
if (info == null) return;
if (fixes != null) {
for (final Annotation.QuickFixInfo quickFixInfo : fixes) {
QuickFixAction.registerQuickFixAction(info, fixedRange != null ? fixedRange : quickFixInfo.textRange, quickFixInfo.quickFix,
quickFixInfo.key != null ? quickFixInfo.key : HighlightDisplayKey.find(DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection.ANNOTATOR_SHORT_NAME));
TextRange range = fixedRange != null ? fixedRange : quickFixInfo.textRange;
HighlightDisplayKey key = quickFixInfo.key != null
? quickFixInfo.key
: HighlightDisplayKey.find(DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection.ANNOTATOR_SHORT_NAME);
QuickFixAction.registerQuickFixAction(info, range, quickFixInfo.quickFix, key);
}
}
}
@@ -772,46 +776,52 @@ public class HighlightInfo implements Segment {
}
List<IntentionAction> newOptions = IntentionManager.getInstance().getStandardIntentionOptions(key, element);
InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
InspectionProfileEntry tool = profile.getInspectionTool(key.toString(), element);
if (!(tool instanceof LocalInspectionToolWrapper)) {
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(key.toString(), element);
if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
if (idkey != null) {
tool = profile.getInspectionTool(idkey.toString(), element);
toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(idkey.toString(), element);
}
}
InspectionProfileEntry wrappedTool = tool;
if (tool instanceof LocalInspectionToolWrapper) {
wrappedTool = ((LocalInspectionToolWrapper)tool).getTool();
Class aClass = myAction.getClass();
if (myAction instanceof QuickFixWrapper) {
aClass = ((QuickFixWrapper)myAction).getFix().getClass();
}
newOptions.add(new CleanupInspectionIntention((LocalInspectionToolWrapper)tool, aClass));
} else if (tool instanceof GlobalInspectionToolWrapper) {
wrappedTool = ((GlobalInspectionToolWrapper)tool).getTool();
if (wrappedTool instanceof GlobalSimpleInspectionTool && (myAction instanceof LocalQuickFix || myAction instanceof QuickFixWrapper)) {
if (toolWrapper != null) {
InspectionProfileEntry wrappedTool;
if (toolWrapper instanceof LocalInspectionToolWrapper) {
wrappedTool = ((LocalInspectionToolWrapper)toolWrapper).getTool();
Class aClass = myAction.getClass();
if (myAction instanceof QuickFixWrapper) {
aClass = ((QuickFixWrapper)myAction).getFix().getClass();
}
newOptions.add(new CleanupInspectionIntention((GlobalInspectionToolWrapper)tool, aClass));
newOptions.add(new CleanupInspectionIntention(toolWrapper, aClass));
}
}
if (wrappedTool instanceof CustomSuppressableInspectionTool) {
final IntentionAction[] suppressActions = ((CustomSuppressableInspectionTool)wrappedTool).getSuppressActions(element);
if (suppressActions != null) {
ContainerUtil.addAll(newOptions, suppressActions);
}
}
if (wrappedTool instanceof BatchSuppressableTool) {
final SuppressQuickFix[] suppressActions = ((BatchSuppressableTool)wrappedTool).getBatchSuppressActions(element);
ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressActions, new Function<SuppressQuickFix, IntentionAction>() {
@Override
public IntentionAction fun(SuppressQuickFix fix) {
return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix);
else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
wrappedTool = ((GlobalInspectionToolWrapper)toolWrapper).getTool();
if (wrappedTool instanceof GlobalSimpleInspectionTool && (myAction instanceof LocalQuickFix || myAction instanceof QuickFixWrapper)) {
Class aClass = myAction.getClass();
if (myAction instanceof QuickFixWrapper) {
aClass = ((QuickFixWrapper)myAction).getFix().getClass();
}
newOptions.add(new CleanupInspectionIntention(toolWrapper, aClass));
}
}));
}
else {
throw new AssertionError("unknown tool: " + toolWrapper+"; key: "+myKey);
}
if (wrappedTool instanceof CustomSuppressableInspectionTool) {
final IntentionAction[] suppressActions = ((CustomSuppressableInspectionTool)wrappedTool).getSuppressActions(element);
if (suppressActions != null) {
ContainerUtil.addAll(newOptions, suppressActions);
}
}
if (wrappedTool instanceof BatchSuppressableTool) {
final SuppressQuickFix[] suppressActions = ((BatchSuppressableTool)wrappedTool).getBatchSuppressActions(element);
ContainerUtil.addAll(newOptions, ContainerUtil.map(suppressActions, new Function<SuppressQuickFix, IntentionAction>() {
@Override
public IntentionAction fun(SuppressQuickFix fix) {
return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix);
}
}));
}
}
if (myProblemGroup instanceof SuppressableProblemGroup) {
final IntentionAction[] suppressActions = ((SuppressableProblemGroup)myProblemGroup).getSuppressActions(element);
@@ -159,7 +159,9 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
for (InspectionResult inspectionResult : resultList) {
LocalInspectionToolWrapper toolWrapper = inspectionResult.tool;
for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
toolWrapper.addProblemDescriptors(Collections.singletonList(descriptor), myIgnoreSuppressed);
LocalInspectionToolWrapper.addProblemDescriptors(Collections.singletonList(descriptor), toolWrapper, myIgnoreSuppressed,
toolWrapper.getContext(),
toolWrapper.getTool());
}
}
}
@@ -194,7 +196,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
}
ProblemDescriptor patchedDescriptor = iManager.createProblemDescriptor(myFile, hostRange, descriptor.getDescriptionTemplate(),
descriptor.getHighlightType(), true, localFixes);
tool.addProblemDescriptors(Collections.singletonList(patchedDescriptor), true);
LocalInspectionToolWrapper.addProblemDescriptors(Collections.singletonList(patchedDescriptor), tool, true, tool.getContext(),
tool.getTool());
}
}
}
@@ -711,16 +714,30 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
return new ArrayList<PsiElement>(result);
}
@NotNull
private List<LocalInspectionToolWrapper> getHighlightingLocalInspectionTools(@NotNull InspectionProfileWrapper profile, PsiElement element) {
List<LocalInspectionToolWrapper> enabled = new ArrayList<LocalInspectionToolWrapper>();
final InspectionToolWrapper[] toolWrappers = (InspectionToolWrapper[])profile.getInspectionTools(element);
InspectionProfileWrapper.checkInspectionsDuplicates(toolWrappers);
for (InspectionToolWrapper toolWrapper : toolWrappers) {
if (!profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), element)) continue;
LocalInspectionToolWrapper wrapper = null;
if (toolWrapper instanceof LocalInspectionToolWrapper) {
wrapper = (LocalInspectionToolWrapper)toolWrapper;
}
if (wrapper == null) continue;
if (myIgnoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(myFile, wrapper.getTool())) {
continue;
}
enabled.add(wrapper);
}
return enabled;
}
@NotNull
List<LocalInspectionToolWrapper> getInspectionTools(@NotNull InspectionProfileWrapper profile) {
final List<LocalInspectionToolWrapper> tools = profile.getHighlightingLocalInspectionTools(myFile);
for (Iterator<LocalInspectionToolWrapper> iterator = tools.iterator(); iterator.hasNext(); ) {
LocalInspectionToolWrapper tool = iterator.next();
if (myIgnoreSuppressed && InspectionManagerEx.inspectionResultSuppressed(myFile, tool.getTool())) {
iterator.remove();
}
}
return tools;
return getHighlightingLocalInspectionTools(profile, myFile);
}
private void doInspectInjectedPsi(@NotNull PsiFile injectedPsi,
@@ -18,9 +18,10 @@ package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerAdapter;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.PsiElement;
@@ -46,6 +47,15 @@ public class HighlightingSettingsPerFile implements PersistentStateComponent<Ele
private final Map<VirtualFile, FileHighlightingSetting[]> myHighlightSettings = new HashMap<VirtualFile, FileHighlightingSetting[]>();
private final Map<PsiFile, InspectionProfile> myProfileSettings = new WeakHashMap<PsiFile, InspectionProfile>();
public HighlightingSettingsPerFile(Project project) {
project.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {
@Override
public void projectClosed(Project project) {
cleanProfileSettings();
}
});
}
public FileHighlightingSetting getHighlightingSettingForRoot(@NotNull PsiElement root){
final PsiFile containingFile = root.getContainingFile();
final VirtualFile virtualFile = containingFile.getVirtualFile();
@@ -17,8 +17,8 @@ package com.intellij.codeInsight.hint;
import com.intellij.codeInsight.highlighting.TooltipLinkHandler;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
@@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Handles tooltip links in format <code>#inspection/inspection_short_name</code>.
* On a click or expend acton returns more detailed description for given inspection.
*
*
* @author peter
*/
public class InspectionDescriptionLinkHandler extends TooltipLinkHandler {
@@ -50,10 +50,10 @@ public class InspectionDescriptionLinkHandler extends TooltipLinkHandler {
}
final InspectionProfile profile = (InspectionProfile)InspectionProfileManager.getInstance().getRootProfile();
final InspectionProfileEntry tool = profile.getInspectionTool(refSuffix, file);
if (tool == null) return null;
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(refSuffix, file);
if (toolWrapper == null) return null;
String description = tool.loadDescription();
String description = toolWrapper.loadDescription();
if (description == null) {
LOG.warn("No description for inspection '" + refSuffix + "'");
description = InspectionsBundle.message("inspection.tool.description.under.construction.text");
@@ -17,10 +17,7 @@
package com.intellij.codeInspection;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
import com.intellij.codeInspection.ex.InspectionManagerEx;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.XSLTReportConverter;
import com.intellij.codeInspection.ex.*;
import com.intellij.conversion.ConversionListener;
import com.intellij.conversion.ConversionService;
import com.intellij.ide.impl.PatchProjectUtil;
@@ -438,16 +435,16 @@ public class InspectionApplication {
}
private static void describeInspections(@NonNls String myOutputPath, final String name) throws IOException {
final InspectionProfileEntry[] profileEntries = InspectionProfileImpl.getDefaultProfile().getInspectionTools(null);
final Map<String, Set<InspectionProfileEntry>> map = new HashMap<String, Set<InspectionProfileEntry>>();
for (InspectionProfileEntry entry : profileEntries) {
final String groupName = entry.getGroupDisplayName();
Set<InspectionProfileEntry> groupInspections = map.get(groupName);
final InspectionToolWrapper[] toolWrappers = InspectionProfileImpl.getDefaultProfile().getInspectionTools(null);
final Map<String, Set<InspectionToolWrapper>> map = new HashMap<String, Set<InspectionToolWrapper>>();
for (InspectionToolWrapper toolWrapper : toolWrappers) {
final String groupName = toolWrapper.getGroupDisplayName();
Set<InspectionToolWrapper> groupInspections = map.get(groupName);
if (groupInspections == null) {
groupInspections = new HashSet<InspectionProfileEntry>();
groupInspections = new HashSet<InspectionToolWrapper>();
map.put(groupName, groupInspections);
}
groupInspections.add(entry);
groupInspections.add(toolWrapper);
}
FileWriter fw = new FileWriter(myOutputPath);
@@ -460,8 +457,8 @@ public class InspectionApplication {
for (String groupName : map.keySet()) {
xmlWriter.startNode("group");
xmlWriter.addAttribute("name", groupName);
final Set<InspectionProfileEntry> entries = map.get(groupName);
for (InspectionProfileEntry entry : entries) {
final Set<InspectionToolWrapper> entries = map.get(groupName);
for (InspectionToolWrapper entry : entries) {
xmlWriter.startNode("inspection");
xmlWriter.addAttribute("shortName", entry.getShortName());
xmlWriter.addAttribute("displayName", entry.getDisplayName());
@@ -470,7 +467,7 @@ public class InspectionApplication {
xmlWriter.setValue(description);
}
else {
LOG.error(entry.getShortName() + " descriptionUrl==" + entry.getDescriptionUrl());
LOG.error(entry.getShortName() + " descriptionUrl==" + entry);
}
xmlWriter.endNode();
}
@@ -15,12 +15,16 @@
*/
package com.intellij.codeInspection;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator;
import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefManagerImpl;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -34,29 +38,38 @@ public class InspectionRunningUtil {
return runInspectionOnFile(file, new LocalInspectionToolWrapper(inspectionTool));
}
@NotNull
public static List<CommonProblemDescriptor> runInspectionOnFile(@NotNull PsiFile file, @NotNull InspectionToolWrapper tool) {
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(file.getProject());
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
tool.initialize(context);
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
RefManagerImpl refManager = (RefManagerImpl)context.getRefManager();
refManager.inspectionReadActionStarted();
try {
if (tool instanceof LocalInspectionToolWrapper) {
((LocalInspectionToolWrapper)tool).processFile(file, true, managerEx, false);
return new ArrayList<CommonProblemDescriptor>(tool.getProblemDescriptors());
LocalInspectionTool localTool = ((LocalInspectionToolWrapper)tool).getTool();
List<ProblemDescriptor> descriptors =
InspectionEngine.inspect(Collections.singletonList(localTool), file, managerEx, false, false, new DaemonProgressIndicator());
return new ArrayList<CommonProblemDescriptor>(descriptors);
}
else if (tool instanceof GlobalInspectionToolWrapper) {
final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper)tool).getTool();
if (globalInspectionTool instanceof GlobalSimpleInspectionTool) {
if (tool instanceof GlobalInspectionToolWrapper) {
final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper)tool).getTool();
if (globalTool instanceof GlobalSimpleInspectionTool) {
GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool)globalTool;
ProblemsHolder problemsHolder = new ProblemsHolder(managerEx, file, false);
((GlobalSimpleInspectionTool)globalInspectionTool)
.checkFile(file, managerEx, problemsHolder, context, tool);
simpleTool.checkFile(file, managerEx, problemsHolder, context, tool);
return new ArrayList<CommonProblemDescriptor>(tool.getProblemDescriptors());
}
RefElement fileRef = refManager.getReference(file);
CommonProblemDescriptor[] descriptors = globalTool.checkElement(fileRef, new AnalysisScope(file), managerEx, context);
if (descriptors != null) {
return Arrays.asList(descriptors);
}
}
return Collections.emptyList();
}
finally {
((RefManagerImpl)context.getRefManager()).inspectionReadActionFinished();
refManager.inspectionReadActionFinished();
tool.cleanup();
context.cleanup(managerEx);
}
@@ -45,18 +45,18 @@ import java.util.List;
* Date: 21-Feb-2006
*/
public class CleanupInspectionIntention implements IntentionAction, HighPriorityAction {
private final InspectionToolWrapper myTool;
private final InspectionToolWrapper myToolWrapper;
private final Class myQuickfixClass;
public CleanupInspectionIntention(@NotNull InspectionToolWrapper tool, Class quickFixClass) {
myTool = tool;
public CleanupInspectionIntention(@NotNull InspectionToolWrapper toolWrapper, Class quickFixClass) {
myToolWrapper = toolWrapper;
myQuickfixClass = quickFixClass;
}
@Override
@NotNull
public String getText() {
return InspectionsBundle.message("fix.all.inspection.problems.in.file", myTool.getDisplayName());
return InspectionsBundle.message("fix.all.inspection.problems.in.file", myToolWrapper.getDisplayName());
}
@Override
@@ -72,7 +72,7 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
ProgressManager.getInstance().runProcess(new Computable<List<CommonProblemDescriptor>>() {
@Override
public List<CommonProblemDescriptor> compute() {
return InspectionRunningUtil.runInspectionOnFile(file, myTool);
return InspectionRunningUtil.runInspectionOnFile(file, myToolWrapper);
}
}, new EmptyProgressIndicator());
@@ -111,8 +111,8 @@ public class CleanupInspectionIntention implements IntentionAction, HighPriority
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
return myQuickfixClass != null && myQuickfixClass != EmptyIntentionAction.class && !(myTool instanceof LocalInspectionToolWrapper &&
((LocalInspectionToolWrapper)myTool).isUnfair());
return myQuickfixClass != null && myQuickfixClass != EmptyIntentionAction.class && !(myToolWrapper instanceof LocalInspectionToolWrapper &&
((LocalInspectionToolWrapper)myToolWrapper).isUnfair());
}
@Override
@@ -15,8 +15,8 @@
*/
package com.intellij.codeInspection.actions;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.ex.ScopeToolState;
import com.intellij.ide.IdeBundle;
@@ -26,15 +26,18 @@ import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.util.ArrayUtil;
import javax.swing.*;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* @author Konstantin Bulenkov
*/
public class GotoInspectionModel extends SimpleChooseByNameModel {
private final Map<String, InspectionProfileEntry> myToolNames = new HashMap<String, InspectionProfileEntry>();
private final Map<String, Set<InspectionProfileEntry>> myGroupNames = new HashMap<String, Set<InspectionProfileEntry>>();
private final Map<String, InspectionProfileEntry> myToolShortNames = new HashMap<String, InspectionProfileEntry>();
private final Map<String, InspectionToolWrapper> myToolNames = new HashMap<String, InspectionToolWrapper>();
private final Map<String, Set<InspectionToolWrapper>> myGroupNames = new HashMap<String, Set<InspectionToolWrapper>>();
private final Map<String, InspectionToolWrapper> myToolShortNames = new HashMap<String, InspectionToolWrapper>();
private final String[] myNames;
private final ListCellRenderer myListCellRenderer = new InspectionListCellRenderer();
@@ -43,8 +46,8 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
super(project, IdeBundle.message("prompt.goto.inspection.enter.name"), "goto.inspection.help.id");
final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile();
for (ScopeToolState state : rootProfile.getAllTools()) {
final InspectionProfileEntry tool = state.getTool();
InspectionProfileEntry workingTool = tool;
InspectionToolWrapper tool = (InspectionToolWrapper)state.getTool();
InspectionToolWrapper workingTool = tool;
if (tool instanceof LocalInspectionToolWrapper) {
workingTool = LocalInspectionToolWrapper.findTool2RunInBatch(project, null, tool.getShortName());
if (workingTool == null) {
@@ -53,9 +56,9 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
}
myToolNames.put(tool.getDisplayName(), workingTool);
final String groupName = tool.getGroupDisplayName();
Set<InspectionProfileEntry> toolsInGroup = myGroupNames.get(groupName);
Set<InspectionToolWrapper> toolsInGroup = myGroupNames.get(groupName);
if (toolsInGroup == null) {
toolsInGroup = new HashSet<InspectionProfileEntry>();
toolsInGroup = new HashSet<InspectionToolWrapper>();
myGroupNames.put(groupName, toolsInGroup);
}
toolsInGroup.add(workingTool);
@@ -80,8 +83,8 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
@Override
public Object[] getElementsByName(final String id, final String pattern) {
final Set<InspectionProfileEntry> result = new HashSet<InspectionProfileEntry>();
InspectionProfileEntry e = myToolNames.get(id);
final Set<InspectionToolWrapper> result = new HashSet<InspectionToolWrapper>();
InspectionToolWrapper e = myToolNames.get(id);
if (e != null) {
result.add(e);
}
@@ -89,17 +92,17 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
if (e != null) {
result.add(e);
}
final Set<InspectionProfileEntry> entries = myGroupNames.get(id);
final Set<InspectionToolWrapper> entries = myGroupNames.get(id);
if (entries != null) {
result.addAll(entries);
}
return result.toArray(new InspectionProfileEntry[result.size()]);
return result.toArray(new InspectionToolWrapper[result.size()]);
}
@Override
public String getElementName(final Object element) {
if (element instanceof InspectionProfileEntry) {
final InspectionProfileEntry entry = (InspectionProfileEntry)element;
if (element instanceof InspectionToolWrapper) {
InspectionToolWrapper entry = (InspectionToolWrapper)element;
return entry.getDisplayName() + " " + entry.getGroupDisplayName();
}
return null;
@@ -15,8 +15,7 @@
*/
package com.intellij.codeInspection.actions;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.ide.util.gotoByName.ChooseByNameBase;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.LanguageFileType;
@@ -27,8 +26,8 @@ import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.speedSearch.SpeedSearchUtil;
import com.intellij.util.text.Matcher;
import com.intellij.util.text.MatcherHolder;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
@@ -38,8 +37,6 @@ import java.awt.*;
*/
@SuppressWarnings({"GtkPreferredJComboBoxRenderer"})
public class InspectionListCellRenderer extends DefaultListCellRenderer implements MatcherHolder {
private static final Icon EMPTY_ICON = EmptyIcon.ICON_18;
private Matcher myMatcher;
private final SimpleTextAttributes SELECTED;
private final SimpleTextAttributes PLAIN;
@@ -67,19 +64,19 @@ public class InspectionListCellRenderer extends DefaultListCellRenderer implemen
panel.setForeground(fg);
SimpleTextAttributes attr = sel ? SELECTED : PLAIN;
if (value instanceof InspectionProfileEntry) {
final InspectionProfileEntry tool = (InspectionProfileEntry)value;
if (value instanceof InspectionToolWrapper) {
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)value;
final SimpleColoredComponent c = new SimpleColoredComponent();
SpeedSearchUtil.appendColoredFragmentForMatcher(" " + tool.getDisplayName(), c, attr, myMatcher, bg, sel);
SpeedSearchUtil.appendColoredFragmentForMatcher(" " + toolWrapper.getDisplayName(), c, attr, myMatcher, bg, sel);
panel.add(c, BorderLayout.WEST);
final SimpleColoredComponent group = new SimpleColoredComponent();
SpeedSearchUtil.appendColoredFragmentForMatcher(tool.getGroupDisplayName() + " ", group, attr, myMatcher, bg, sel);
SpeedSearchUtil.appendColoredFragmentForMatcher(toolWrapper.getGroupDisplayName() + " ", group, attr, myMatcher, bg, sel);
final JPanel right = new JPanel(new BorderLayout());
right.setBackground(bg);
right.setForeground(fg);
right.add(group, BorderLayout.CENTER);
final JLabel icon = new JLabel(getIcon(tool));
final JLabel icon = new JLabel(getIcon(toolWrapper));
icon.setBackground(bg);
icon.setForeground(fg);
right.add(icon, BorderLayout.EAST);
@@ -94,15 +91,14 @@ public class InspectionListCellRenderer extends DefaultListCellRenderer implemen
return panel;
}
private static Icon getIcon(InspectionProfileEntry tool) {
@NotNull
private static Icon getIcon(@NotNull InspectionToolWrapper tool) {
Icon icon = null;
if (tool instanceof LocalInspectionToolWrapper) {
final Language language = Language.findLanguageByID(((LocalInspectionToolWrapper)tool).getLanguage());
if (language != null) {
final LanguageFileType fileType = language.getAssociatedFileType();
if (fileType != null) {
icon = fileType.getIcon();
}
final Language language = Language.findLanguageByID(tool.getLanguage());
if (language != null) {
final LanguageFileType fileType = language.getAssociatedFileType();
if (fileType != null) {
icon = fileType.getIcon();
}
}
if (icon == null) {
@@ -20,9 +20,9 @@ import com.intellij.analysis.AnalysisScopeBundle;
import com.intellij.analysis.AnalysisUIOptions;
import com.intellij.analysis.BaseAnalysisActionDialog;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.ex.InspectionManagerEx;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.actions.GotoActionBase;
@@ -79,7 +79,7 @@ public class RunInspectionAction extends GotoActionBase {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
runInspection(project, (InspectionProfileEntry)element, virtualFile, psiElement, psiFile);
runInspection(project, (InspectionToolWrapper)element, virtualFile, psiElement, psiFile);
}
});
}
@@ -87,7 +87,7 @@ public class RunInspectionAction extends GotoActionBase {
}
private static void runInspection(@NotNull Project project,
@NotNull InspectionProfileEntry profileEntry,
@NotNull InspectionToolWrapper toolWrapper,
@Nullable VirtualFile virtualFile,
PsiElement psiElement, PsiFile psiFile) {
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
@@ -140,6 +140,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(toolWrapper, managerEx, scope, psiFile);
}
}
@@ -93,31 +93,32 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
rerunInspection(LocalInspectionToolWrapper.findTool2RunInBatch(project, file, myShortName), managerEx, analysisScope, file);
}
public static void rerunInspection(final InspectionProfileEntry baseTool, final InspectionManagerEx managerEx, final AnalysisScope scope,
public static void rerunInspection(final InspectionToolWrapper toolWrapper,
final InspectionManagerEx managerEx, final AnalysisScope scope,
PsiElement psiElement) {
GlobalInspectionContextImpl inspectionContext = createContext(baseTool, managerEx, psiElement);
GlobalInspectionContextImpl inspectionContext = createContext(toolWrapper, managerEx, psiElement);
inspectionContext.doInspections(scope, managerEx);
}
public static GlobalInspectionContextImpl createContext(final InspectionProfileEntry baseTool, InspectionManagerEx managerEx, PsiElement psiElement) {
public static GlobalInspectionContextImpl createContext(final InspectionToolWrapper toolWrapper, InspectionManagerEx managerEx, PsiElement psiElement) {
final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile();
LinkedHashSet<InspectionProfileEntry> allEntries = new LinkedHashSet<InspectionProfileEntry>();
allEntries.add(baseTool);
rootProfile.collectDependentInspections(baseTool, allEntries);
InspectionProfileEntry[] toolsArray = allEntries.toArray(new InspectionProfileEntry[allEntries.size()]);
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(baseTool.getDisplayName(), toolsArray);
LinkedHashSet<InspectionToolWrapper> allWrappers = new LinkedHashSet<InspectionToolWrapper>();
allWrappers.add(toolWrapper);
rootProfile.collectDependentInspections(toolWrapper, allWrappers);
InspectionToolWrapper[] toolWrappers = allWrappers.toArray(new InspectionToolWrapper[allWrappers.size()]);
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(toolWrapper.getDisplayName(), toolWrappers);
try {
Element element = new Element("toCopy");
for (InspectionProfileEntry tool : allEntries) {
tool.writeSettings(element);
model.getInspectionTool(tool.getShortName(), psiElement).readSettings(element);
for (InspectionToolWrapper wrapper : allWrappers) {
wrapper.writeSettings(element);
model.getInspectionTool(wrapper.getShortName(), psiElement).readSettings(element);
}
}
catch (Exception e) {
//skip
}
model.setEditable(baseTool.getDisplayName());
model.setEditable(toolWrapper.getDisplayName());
final GlobalInspectionContextImpl inspectionContext = managerEx.createNewGlobalContext(false);
inspectionContext.setExternalProfile(model);
return inspectionContext;
@@ -211,23 +211,24 @@ public class ViewOfflineResultsAction extends AnAction implements DumbAware {
return showOfflineView(project, resMap, inspectionProfile, title);
}
public static InspectionResultsView showOfflineView(final Project project,
final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap,
@NotNull
public static InspectionResultsView showOfflineView(@NotNull Project project,
@NotNull Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap,
final InspectionProfile inspectionProfile,
final String title) {
final AnalysisScope scope = new AnalysisScope(project);
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
final GlobalInspectionContextImpl inspectionContext = managerEx.createNewGlobalContext(false);
inspectionContext.setExternalProfile(inspectionProfile);
inspectionContext.setCurrentScope(scope);
inspectionContext.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
final InspectionResultsView view = new InspectionResultsView(project, inspectionProfile, scope, inspectionContext,
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
context.setExternalProfile(inspectionProfile);
context.setCurrentScope(scope);
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
final InspectionResultsView view = new InspectionResultsView(project, inspectionProfile, scope, context,
new OfflineInspectionRVContentProvider(resMap, project));
((RefManagerImpl)inspectionContext.getRefManager()).inspectionReadActionStarted();
((RefManagerImpl)context.getRefManager()).inspectionReadActionStarted();
view.update();
TreeUtil.selectFirstNode(view.getTree());
if (inspectionContext.getContentManager() != null) { //test
inspectionContext.addView(view, title);
if (context.getContentManager() != null) { //test
context.addView(view, title);
}
return view;
}
@@ -41,6 +41,7 @@ public class CommonInspectionToolWrapper extends InspectionToolWrapper<Inspectio
public CommonInspectionToolWrapper(@NotNull InspectionTool tool) {
super(tool);
assert !(tool instanceof InspectionToolWrapper);
}
private CommonInspectionToolWrapper(@NotNull CommonInspectionToolWrapper other) {
@@ -36,7 +36,7 @@ public class Descriptor {
private final HighlightDisplayKey myKey;
private Element myConfig;
private final InspectionProfileEntry myTool;
private final InspectionToolWrapper myToolWrapper;
private final HighlightDisplayLevel myLevel;
private boolean myEnabled = false;
private final NamedScope myScope;
@@ -47,14 +47,14 @@ public class Descriptor {
public Descriptor(@NotNull ScopeToolState state, @NotNull InspectionProfileImpl inspectionProfile) {
myState = state;
myInspectionProfile = inspectionProfile;
final InspectionProfileEntry tool = state.getTool();
InspectionToolWrapper tool = (InspectionToolWrapper)state.getTool();
myText = tool.getDisplayName();
final String[] groupPath = tool.getGroupPath();
myGroup = groupPath.length == 0 ? new String[]{InspectionProfileEntry.GENERAL_GROUP_NAME} : groupPath;
myKey = HighlightDisplayKey.find(tool.getShortName());
myLevel = inspectionProfile.getErrorLevel(myKey, ScopeToolStateUtil.getScope(state));
myEnabled = inspectionProfile.isToolEnabled(myKey, ScopeToolStateUtil.getScope(state));
myTool = tool;
myToolWrapper = tool;
myScope = ScopeToolStateUtil.getScope(state);
}
@@ -98,28 +98,29 @@ public class Descriptor {
return myConfig;
}
public InspectionProfileEntry getTool() {
return myTool;
@NotNull
public InspectionToolWrapper getTool() {
return myToolWrapper;
}
@Nullable
public String loadDescription() {
if (myConfig == null) {
myConfig = createConfigElement(getTool());
InspectionToolWrapper toolWrapper = getTool();
myConfig = createConfigElement(toolWrapper);
}
if (!(myTool instanceof InspectionTool)) return null;
return myTool.loadDescription();
return myToolWrapper.loadDescription();
}
public InspectionProfileImpl getInspectionProfile() {
return myInspectionProfile;
}
public static Element createConfigElement(InspectionProfileEntry tool) {
public static Element createConfigElement(InspectionToolWrapper toolWrapper) {
Element element = new Element("options");
try {
tool.writeSettings(element);
toolWrapper.writeSettings(element);
}
catch (WriteExternalException e) {
LOG.error(e);
@@ -63,8 +63,8 @@ public class DisableInspectionToolAction implements IntentionAction, Iconable {
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project);
InspectionProfile inspectionProfile = profileManager.getInspectionProfile();
InspectionProfileEntry tool = inspectionProfile.getInspectionTool(myToolId);
return tool == null || tool.getDefaultLevel() != HighlightDisplayLevel.NON_SWITCHABLE_ERROR;
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)inspectionProfile.getInspectionTool(myToolId);
return toolWrapper == null || toolWrapper.getDefaultLevel() != HighlightDisplayLevel.NON_SWITCHABLE_ERROR;
}
@Override
@@ -17,7 +17,6 @@
package com.intellij.codeInspection.ex;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.lang.InspectionExtensionsFactory;
import com.intellij.openapi.editor.Editor;
@@ -83,15 +82,15 @@ public class EditInspectionToolsSettingsInSuppressedPlaceIntention implements In
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
myId = getSuppressedId(editor, file);
if (myId != null) {
InspectionProfileEntry tool = getTool(project, file);
if (tool == null) return false;
myDisplayName = tool.getDisplayName();
InspectionToolWrapper toolWrapper = getTool(project, file);
if (toolWrapper == null) return false;
myDisplayName = toolWrapper.getDisplayName();
}
return myId != null;
}
@Nullable
private InspectionProfileEntry getTool(final Project project, final PsiFile file) {
private InspectionToolWrapper getTool(final Project project, final PsiFile file) {
final InspectionProjectProfileManager projectProfileManager = InspectionProjectProfileManager.getInstance(project);
final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)projectProfileManager.getInspectionProfile();
return inspectionProfile.getToolById(myId, file);
@@ -99,11 +98,11 @@ public class EditInspectionToolsSettingsInSuppressedPlaceIntention implements In
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
InspectionProfileEntry tool = getTool(project, file);
if (tool == null) return;
InspectionToolWrapper toolWrapper = getTool(project, file);
if (toolWrapper == null) return;
final InspectionProjectProfileManager projectProfileManager = InspectionProjectProfileManager.getInstance(project);
final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)projectProfileManager.getInspectionProfile();
EditInspectionToolsSettingsAction.editToolSettings(project, inspectionProfile, false, tool.getShortName());
EditInspectionToolsSettingsAction.editToolSettings(project, inspectionProfile, false, toolWrapper.getShortName());
}
@Override
@@ -79,14 +79,14 @@ import java.util.*;
public class GlobalInspectionContextImpl extends UserDataHolderBase implements GlobalInspectionContext {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.GlobalInspectionContextImpl");
private static final TObjectHashingStrategy<ToolsImpl> TOOLS_HASHING_STRATEGY = new TObjectHashingStrategy<ToolsImpl>() {
private static final TObjectHashingStrategy<Tools> TOOLS_HASHING_STRATEGY = new TObjectHashingStrategy<Tools>() {
@Override
public int computeHashCode(ToolsImpl object) {
public int computeHashCode(Tools object) {
return object.getShortName().hashCode();
}
@Override
public boolean equals(ToolsImpl o1, ToolsImpl o2) {
public boolean equals(Tools o1, Tools o2) {
return o1.getShortName().equals(o2.getShortName());
}
};
@@ -102,8 +102,8 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
private Content myContent = null;
private ProgressIndicator myProgressIndicator;
private final StdJobDescriptors myStdJobDescriptors = new StdJobDescriptors();
private ProgressIndicator myProgressIndicator;
private InspectionProfile myExternalProfile = null;
@@ -155,7 +155,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
if (profile != null) return (InspectionProfile)profile;
final String[] availableProfileNames = inspectionProfileManager.getAvailableProfileNames();
if (availableProfileNames == null || availableProfileNames.length == 0) {
if (availableProfileNames.length == 0) {
//can't be
return null;
}
@@ -204,7 +204,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
public synchronized void addView(InspectionResultsView view, String title) {
public synchronized void addView(@NotNull InspectionResultsView view, String title) {
if (myContent != null) return;
myContentManager.getValue().addContentManagerListener(new ContentManagerAdapter() {
@Override
@@ -230,7 +230,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.INSPECTION).activate(null);
}
protected void addView(InspectionResultsView view) {
protected void addView(@NotNull InspectionResultsView view) {
addView(view, view.getCurrentProfileName() == null
? InspectionsBundle.message("inspection.results.title")
: InspectionsBundle.message("inspection.results.for.profile.toolwindow.title", view.getCurrentProfileName()));
@@ -246,7 +246,8 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
for (Tools tools : myTools.values()) {
for (ScopeToolState state : tools.getTools()) {
((InspectionTool)state.getTool()).cleanup();
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
toolWrapper.cleanup();
}
}
myTools.clear();
@@ -331,11 +332,12 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
String toolName = stringSetEntry.getKey();
if (sameTools != null) {
for (ScopeToolState toolDescr : sameTools.getTools()) {
final InspectionTool tool = (InspectionTool)toolDescr.getTool();
if (tool instanceof LocalInspectionToolWrapper) {
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)toolDescr.getTool();
if (toolWrapper instanceof LocalInspectionToolWrapper) {
hasProblems = new File(outputPath, toolName + ext).exists();
}
else {
else if (toolWrapper.getTool() instanceof InspectionTool) {
InspectionTool tool = (InspectionTool)toolWrapper.getTool();
tool.updateContent();
if (tool.hasReportedProblems()) {
final Element root = new Element(InspectionsBundle.message("inspection.problems"));
@@ -365,7 +367,8 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
final Tools tools = globalTools.get(element);
for (ScopeToolState state : tools.getTools()) {
try {
((InspectionTool)state.getTool()).exportResults(element, refEntity);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
toolWrapper.exportResults(element, refEntity);
}
catch (Exception e) {
LOG.error("Problem when exporting: " + refEntity.getExternalName(), e);
@@ -407,22 +410,19 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
public boolean isToCheckMember(@NotNull RefElement owner, InspectionProfileEntry tool) {
public boolean isToCheckMember(@NotNull RefElement owner, @NotNull InspectionProfileEntry tool) {
return isToCheckFile(((RefElementImpl)owner).getContainingFile(), tool) && !((RefElementImpl)owner).isSuppressed(tool.getShortName());
}
public boolean isToCheckFile(PsiFile file, final InspectionProfileEntry tool) {
public boolean isToCheckFile(PsiFile file, @NotNull InspectionProfileEntry tool) {
final Tools tools = myTools.get(tool.getShortName());
if (tools != null && file != null) {
for (ScopeToolState state : tools.getTools()) {
final NamedScope namedScope = state.getScope(file.getProject());
if (namedScope == null || namedScope.getValue().contains(file, getCurrentProfile().getProfileManager().getScopesManager())) {
if (state.isEnabled()) {
final InspectionProfileEntry entry = state.getTool();
if (entry instanceof InspectionToolWrapper && ((InspectionToolWrapper)entry).getTool() == tool) return true;
if (entry == tool) {
return true;
}
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
if (toolWrapper.getTool() == tool) return true;
}
return false;
}
@@ -431,12 +431,13 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
return false;
}
public void ignoreElement(final InspectionTool tool, final PsiElement element) {
public void ignoreElement(@NotNull InspectionProfileEntry tool, final PsiElement element) {
final RefElement refElement = getRefManager().getReference(element);
final Tools tools = myTools.get(tool.getShortName());
if (tools != null){
for (ScopeToolState state : tools.getTools()) {
ignoreElementRecursively((InspectionTool)state.getTool(), refElement);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
ignoreElementRecursively(toolWrapper, refElement);
}
}
}
@@ -445,13 +446,16 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
return myView;
}
private static void ignoreElementRecursively(final InspectionTool tool, final RefEntity refElement) {
private static void ignoreElementRecursively(@NotNull InspectionToolWrapper toolWrapper, final RefEntity refElement) {
if (refElement != null) {
tool.ignoreCurrentElement(refElement);
InspectionProfileEntry tool = toolWrapper.getTool();
if (tool instanceof InspectionTool) {
((InspectionTool)tool).ignoreCurrentElement(refElement);
}
final List<RefEntity> children = refElement.getChildren();
if (children != null) {
for (RefEntity child : children) {
ignoreElementRecursively(tool, child);
ignoreElementRecursively(toolWrapper, child);
}
}
}
@@ -469,7 +473,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
return myUIOptions.getAutoScrollToSourceHandler().createToggleAction();
}
private void launchInspections(final AnalysisScope scope, final InspectionManager manager) {
private void launchInspections(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
myUIOptions = AnalysisUIOptions.getInstance(myProject).copy();
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
@@ -553,22 +557,50 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
private void runTools(@NotNull AnalysisScope scope, @NotNull final InspectionManager manager) {
final List<Tools> globalTools = new ArrayList<Tools>();
List<Tools> globalTools = new ArrayList<Tools>();
final List<Tools> localTools = new ArrayList<Tools>();
final List<Tools> globalSimpleTools = new ArrayList<Tools>();
initializeTools(globalTools, localTools, globalSimpleTools);
final List<InspectionProfileEntry> needRepeatSearchRequest = new ArrayList<InspectionProfileEntry>();
List<Tools> specialTools = new ArrayList<Tools>();
initializeTools(globalTools, localTools, globalSimpleTools, specialTools);
final List<InspectionToolWrapper> needRepeatSearchRequest = new ArrayList<InspectionToolWrapper>();
((RefManagerImpl)getRefManager()).initializeAnnotators();
for (Tools tools : globalTools) {
// run special tools first
for (Tools tools : specialTools) {
for (ScopeToolState state : tools.getTools()) {
final InspectionTool tool = (InspectionTool)state.getTool();
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
InspectionTool tool = (InspectionTool)toolWrapper.getTool();
try {
if (tool.isGraphNeeded()) {
((RefManagerImpl)getRefManager()).findAllDeclarations();
}
tool.runInspection(scope, manager);
if (tool.queryExternalUsagesRequests(manager)) {
needRepeatSearchRequest.add(tool);
needRepeatSearchRequest.add(toolWrapper);
}
}
catch (ProcessCanceledException e) {
throw e;
}
catch (IndexNotReadyException e) {
throw e;
}
catch (Exception e) {
LOG.error(e);
}
}
}
for (Tools tools : globalTools) {
for (ScopeToolState state : tools.getTools()) {
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool();
try {
if (tool.isGraphNeeded()) {
((RefManagerImpl)getRefManager()).findAllDeclarations();
}
tool.runInspection(scope, manager, this, toolWrapper);
if (tool.queryExternalUsagesRequests(manager,this, toolWrapper)) {
needRepeatSearchRequest.add(toolWrapper);
}
}
catch (ProcessCanceledException e) {
@@ -638,7 +670,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool)toolWrapper.getTool();
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, false);
GlobalInspectionToolWrapper problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
ProblemDescriptionsProcessor problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
tool.checkFile(file, manager, problemsHolder, GlobalInspectionContextImpl.this, problemDescriptionProcessor);
LocalInspectionToolWrapper.addProblemDescriptors(problemsHolder.getResults(), false, GlobalInspectionContextImpl.this, null,
CONVERT, toolWrapper);
@@ -666,14 +698,14 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
for (Tools tools : globalSimpleTools) {
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool)toolWrapper.getTool();
GlobalInspectionToolWrapper problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
ProblemDescriptionsProcessor problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
tool.inspectionFinished(manager, this, problemDescriptionProcessor);
}
}
private static GlobalInspectionToolWrapper getProblemDescriptionProcessor(@NotNull final GlobalInspectionToolWrapper toolWrapper,
final Map<String, DescriptorProviderInspection> wrappersMap) {
@NotNull
private static ProblemDescriptionsProcessor getProblemDescriptionProcessor(@NotNull final GlobalInspectionToolWrapper toolWrapper,
@NotNull final Map<String, DescriptorProviderInspection> wrappersMap) {
return new GlobalInspectionToolWrapper(toolWrapper.getTool()) {
@Override
public void addProblemElement(RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
@@ -698,17 +730,16 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
@NotNull
private static Map<String, DescriptorProviderInspection> getInspectionWrappersMap(List<Tools> tools) {
Map<String, DescriptorProviderInspection> toolWrappers = new HashMap<String, DescriptorProviderInspection>(tools.size());
private static Map<String, DescriptorProviderInspection> getInspectionWrappersMap(@NotNull List<Tools> tools) {
Map<String, DescriptorProviderInspection> name2Inspection = new HashMap<String, DescriptorProviderInspection>(tools.size());
for (Tools tool : tools) {
InspectionProfileEntry profileEntry = tool.getTool();
if (profileEntry instanceof DescriptorProviderInspection) {
toolWrappers.put(profileEntry.getShortName(), (DescriptorProviderInspection)profileEntry);
name2Inspection.put(profileEntry.getShortName(), (DescriptorProviderInspection)profileEntry);
}
}
return toolWrappers;
return name2Inspection;
}
private static final TripleFunction<LocalInspectionTool,PsiElement,GlobalInspectionContext,RefElement> CONVERT =
@@ -730,17 +761,20 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
public void initializeTools(@NotNull List<Tools> outGlobalTools,
@NotNull List<Tools> outLocalTools,
@NotNull List<Tools> outGlobalSimpleTools) {
@NotNull List<Tools> outGlobalSimpleTools,
@NotNull List<Tools> outSpecialTools
) {
myJobDescriptors = new ArrayList<JobDescriptor>();
final List<ToolsImpl> usedTools = getUsedTools();
final List<Tools> usedTools = getUsedTools();
for (Tools currentTools : usedTools) {
final String shortName = currentTools.getShortName();
myTools.put(shortName, currentTools);
final InspectionTool tool = (InspectionTool)currentTools.getTool();
classifyTool(outGlobalTools, outLocalTools, outGlobalSimpleTools, currentTools, tool);
InspectionToolWrapper toolWrapper1 = (InspectionToolWrapper)currentTools.getTool();
classifyTool(outGlobalTools, outLocalTools, outGlobalSimpleTools, outSpecialTools, currentTools, toolWrapper1);
for (ScopeToolState state : currentTools.getTools()) {
((InspectionTool)state.getTool()).initialize(this);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
toolWrapper.initialize(this);
}
}
for (GlobalInspectionContextExtension extension : myExtensions.values()) {
@@ -748,44 +782,57 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
}
protected List<ToolsImpl> getUsedTools() {
protected List<Tools> getUsedTools() {
InspectionProfileImpl profile = new InspectionProfileImpl((InspectionProfileImpl)getCurrentProfile());
List<ToolsImpl> tools = profile.getAllEnabledInspectionTools(myProject);
Set<InspectionProfileEntry> dependentTools = new LinkedHashSet<InspectionProfileEntry>();
for (ToolsImpl tool : tools) {
profile.collectDependentInspections(tool.getTool(), dependentTools);
List<Tools> tools = profile.getAllEnabledInspectionTools(myProject);
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<InspectionToolWrapper>();
for (Tools tool : tools) {
profile.collectDependentInspections((InspectionToolWrapper)tool.getTool(), dependentTools);
}
if (!dependentTools.isEmpty()) {
THashSet<ToolsImpl> set = new THashSet<ToolsImpl>(tools, TOOLS_HASHING_STRATEGY);
set.addAll(ContainerUtil.map(dependentTools, new Function<InspectionProfileEntry, ToolsImpl>() {
@Override
public ToolsImpl fun(InspectionProfileEntry entry) {
return new ToolsImpl(entry, entry.getDefaultLevel(), true, true);
}
}));
return new ArrayList<ToolsImpl>(set);
}
else {
if (dependentTools.isEmpty()) {
return tools;
}
Set<Tools> set = new THashSet<Tools>(tools, TOOLS_HASHING_STRATEGY);
set.addAll(ContainerUtil.map(dependentTools, new Function<InspectionToolWrapper, ToolsImpl>() {
@Override
public ToolsImpl fun(InspectionToolWrapper toolWrapper) {
return new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true, true);
}
}));
return new ArrayList<Tools>(set);
}
private void classifyTool(List<Tools> outGlobalTools,
List<Tools> outLocalTools,
List<Tools> outGlobalSimpleTools,
Tools currentTools,
InspectionTool tool) {
if (tool instanceof LocalInspectionToolWrapper) {
private void classifyTool(@NotNull List<Tools> outGlobalTools,
@NotNull List<Tools> outLocalTools,
@NotNull List<Tools> outGlobalSimpleTools,
@NotNull List<Tools> outSpecialTools,
@NotNull Tools currentTools,
@NotNull InspectionToolWrapper toolWrapper) {
if (toolWrapper instanceof LocalInspectionToolWrapper) {
outLocalTools.add(currentTools);
}
else if (tool instanceof GlobalInspectionToolWrapper && ((GlobalInspectionToolWrapper)tool).getTool() instanceof GlobalSimpleInspectionTool) {
outGlobalSimpleTools.add(currentTools);
else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
if (toolWrapper.getTool() instanceof GlobalSimpleInspectionTool) {
outGlobalSimpleTools.add(currentTools);
}
else if (toolWrapper.getTool() instanceof GlobalInspectionTool) {
outGlobalTools.add(currentTools);
}
else if (toolWrapper.getTool() instanceof InspectionTool) {
outSpecialTools.add(currentTools);
}
else {
throw new RuntimeException("unknown global tool " + toolWrapper);
}
}
else if (toolWrapper.getTool() instanceof InspectionTool) {
outSpecialTools.add(currentTools);
}
else {
outGlobalTools.add(currentTools);
throw new RuntimeException("unknown tool " + toolWrapper);
}
JobDescriptor[] jobDescriptors = tool.getJobDescriptors(this);
JobDescriptor[] jobDescriptors = toolWrapper.getJobDescriptors(this);
for (JobDescriptor jobDescriptor : jobDescriptors) {
appendJobDescriptor(jobDescriptor);
}
@@ -820,7 +867,8 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
managerEx.closeRunningContext(this);
for (Tools tools : myTools.values()) {
for (ScopeToolState state : tools.getTools()) {
((InspectionTool)state.getTool()).finalCleanup();
InspectionToolWrapper tool = (InspectionToolWrapper)state.getTool();
tool.finalCleanup();
}
}
cleanup();
@@ -848,22 +896,21 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
private float getTotalProgress() {
float totalProgress = 0;
int liveDescriptors = 0;
float totalDone = 0;
int totalTotal = 0;
for (JobDescriptor jobDescriptor : myJobDescriptors) {
totalProgress += jobDescriptor.getProgress();
liveDescriptors += jobDescriptor.getTotalAmount() == 0 ? 0 : 1;
totalDone += jobDescriptor.getDoneAmount();
totalTotal += jobDescriptor.getTotalAmount();
}
return totalProgress / liveDescriptors;
return totalTotal == 0 ? 1 : totalDone / totalTotal;
}
public void setExternalProfile(InspectionProfile profile) {
myExternalProfile = profile;
}
@NotNull
@Override
@NotNull
public StdJobDescriptors getStdJobDescriptors() {
return myStdJobDescriptors;
}
@@ -20,16 +20,15 @@ import org.jetbrains.annotations.Nullable;
* Date: 28-Dec-2005
*/
public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalInspectionTool, InspectionEP> {
public GlobalInspectionToolWrapper(@NotNull GlobalInspectionTool globalInspectionTool) {
super(globalInspectionTool);
}
public GlobalInspectionToolWrapper(InspectionEP ep) {
public GlobalInspectionToolWrapper(@NotNull InspectionEP ep) {
super(ep);
}
private GlobalInspectionToolWrapper(GlobalInspectionToolWrapper other) {
private GlobalInspectionToolWrapper(@NotNull GlobalInspectionToolWrapper other) {
super(other);
}
@@ -50,12 +49,14 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalIns
@Override
public void runInspection(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
getTool().runInspection(scope, manager, getContext(), this);
throw new RuntimeException();
//getTool().runInspection(scope, manager, getContext(), this);
}
@Override
public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager) {
return getTool().queryExternalUsagesRequests(manager, getContext(), this);
throw new RuntimeException();
//return getTool().queryExternalUsagesRequests(manager, getContext(), this);
}
@Override
@@ -63,16 +64,17 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalIns
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context) {
final JobDescriptor[] additionalJobs = getTool().getAdditionalJobs();
if (additionalJobs == null) {
return isGraphNeeded() ? context.getStdJobDescriptors().BUILD_GRAPH_ONLY : JobDescriptor.EMPTY_ARRAY;
return getTool().isGraphNeeded() ? context.getStdJobDescriptors().BUILD_GRAPH_ONLY : JobDescriptor.EMPTY_ARRAY;
}
else {
return isGraphNeeded() ? ArrayUtil.append(additionalJobs, context.getStdJobDescriptors().BUILD_GRAPH) : additionalJobs;
return getTool().isGraphNeeded() ? ArrayUtil.append(additionalJobs, context.getStdJobDescriptors().BUILD_GRAPH) : additionalJobs;
}
}
@Override
public boolean isGraphNeeded() {
return getTool().isGraphNeeded();
throw new RuntimeException();
//return getTool().isGraphNeeded();
}
public void processFile(@NotNull final AnalysisScope analysisScope,
@@ -81,8 +83,7 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalIns
final boolean filterSuppressed) {
context.getRefManager().iterate(new RefVisitor() {
@Override public void visitElement(@NotNull RefEntity refEntity) {
CommonProblemDescriptor[] descriptors = getTool()
.checkElement(refEntity, analysisScope, manager, context, GlobalInspectionToolWrapper.this);
CommonProblemDescriptor[] descriptors = getTool().checkElement(refEntity, analysisScope, manager, context, GlobalInspectionToolWrapper.this);
if (descriptors != null) {
addProblemElement(refEntity, filterSuppressed, descriptors);
}
@@ -105,47 +106,45 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalIns
@Nullable
public IntentionAction findQuickFixes(final CommonProblemDescriptor problemDescriptor, final String hint) {
final QuickFix fix = getTool().getQuickFix(hint);
if (fix != null) {
if (problemDescriptor instanceof ProblemDescriptor) {
final ProblemDescriptor descriptor = new ProblemDescriptorImpl(((ProblemDescriptor)problemDescriptor).getStartElement(),
((ProblemDescriptor)problemDescriptor).getEndElement(),
problemDescriptor.getDescriptionTemplate(),
new LocalQuickFix[]{(LocalQuickFix)fix},
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false, null, false);
return QuickFixWrapper.wrap(descriptor, 0);
}
else {
return new IntentionAction() {
@Override
@NotNull
public String getText() {
return fix.getName();
}
@Override
@NotNull
public String getFamilyName() {
return fix.getFamilyName();
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return true;
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
fix.applyFix(project, problemDescriptor); //todo check type consistency
}
@Override
public boolean startInWriteAction() {
return true;
}
};
}
if (fix == null) {
return null;
}
return null;
if (problemDescriptor instanceof ProblemDescriptor) {
final ProblemDescriptor descriptor = new ProblemDescriptorImpl(((ProblemDescriptor)problemDescriptor).getStartElement(),
((ProblemDescriptor)problemDescriptor).getEndElement(),
problemDescriptor.getDescriptionTemplate(),
new LocalQuickFix[]{(LocalQuickFix)fix},
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false, null, false);
return QuickFixWrapper.wrap(descriptor, 0);
}
return new IntentionAction() {
@Override
@NotNull
public String getText() {
return fix.getName();
}
@Override
@NotNull
public String getFamilyName() {
return fix.getFamilyName();
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return true;
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
fix.applyFix(project, problemDescriptor); //todo check type consistency
}
@Override
public boolean startInWriteAction() {
return true;
}
};
}
public boolean worksInBatchModeOnly() {
@@ -58,13 +58,6 @@ 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(@NotNull InspectionProfileEntry tool) {
return InspectionToolRegistrar.wrapTool(tool);
}
};
private Map<String, ToolsImpl> myTools = new THashMap<String, ToolsImpl>();
@@ -80,7 +73,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@NonNls private static final String CLASS_TAG = "class";
@NonNls private static final String PROFILE_NAME_TAG = "profile_name";
@NonNls private static final String ROOT_ELEMENT_TAG = "inspections";
@NonNls static final String SCOPE = "scope";
private String myEnabledTool = null;
@NonNls private static final String USED_LEVELS = "used_levels";
@@ -88,7 +80,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
final InspectionToolRegistrar myRegistrar;
@NonNls private static final String IS_LOCKED = "is_locked";
private final ExternalInfo myExternalInfo = new ExternalInfo();
static final String NAME = "name";
public static boolean INIT_INSPECTIONS = false;
@Override
@@ -132,12 +123,12 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@NotNull
public static InspectionProfileImpl createSimple(@NotNull String name, @NotNull final InspectionProfileEntry... tools) {
public static InspectionProfileImpl createSimple(@NotNull String name, @NotNull final InspectionToolWrapper ... toolWrappers) {
InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar(null) {
@NotNull
@Override
public List<InspectionToolWrapper> createTools() {
return ContainerUtil.map(tools, WRAPPER_FUNCTION);
return Arrays.asList(toolWrappers);
}
}, InspectionProfileManager.getInstance());
boolean init = INIT_INSPECTIONS;
@@ -148,8 +139,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
finally {
INIT_INSPECTIONS = init;
}
for (InspectionProfileEntry tool : tools) {
profile.enableTool(tool.getShortName());
for (InspectionToolWrapper toolWrapper : toolWrappers) {
profile.enableTool(toolWrapper.getShortName());
}
return profile;
}
@@ -178,8 +169,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
private static boolean toolSettingsAreEqual(String toolName, @NotNull InspectionProfileImpl profile1, @NotNull InspectionProfileImpl profile2) {
final ToolsImpl toolList1 = profile1.myTools.get(toolName);
final ToolsImpl toolList2 = profile2.myTools.get(toolName);
final Tools toolList1 = profile1.myTools.get(toolName);
final Tools toolList2 = profile2.myTools.get(toolName);
return Comparing.equal(toolList1, toolList2);
}
@@ -192,8 +183,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
public boolean isProperSetting(String toolId) {
if (myBaseProfile != null) {
final ToolsImpl tools = myBaseProfile.getTools(toolId);
final ToolsImpl currentTools = myTools.get(toolId);
final Tools tools = myBaseProfile.getTools(toolId);
final Tools currentTools = myTools.get(toolId);
return !Comparing.equal(tools, currentTools);
}
return false;
@@ -209,9 +200,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
public void resetToEmpty() {
final InspectionProfileEntry[] profileEntries = getInspectionTools(null);
for (InspectionProfileEntry entry : profileEntries) {
disableTool(entry.getShortName());
final InspectionToolWrapper[] profileEntries = getInspectionTools(null);
for (InspectionToolWrapper toolWrapper : profileEntries) {
disableTool(toolWrapper.getShortName());
}
}
@@ -258,7 +249,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
for (final Object o : element.getChildren(INSPECTION_TOOL_TAG)) {
// make clone to avoid retaining memory via o.parent pointers
Element toolElement = (Element)((Element)o).clone();
Element toolElement = ((Element)o).clone();
IdeaPluginDescriptorImpl.internJDOMElement(toolElement);
String toolClassName = toolElement.getAttributeValue(CLASS_TAG);
@@ -271,7 +262,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
public Set<HighlightSeverity> getUsedSeverities() {
LOG.assertTrue(myInitialized);
final Set<HighlightSeverity> result = new HashSet<HighlightSeverity>();
for (ToolsImpl tools : myTools.values()) {
for (Tools tools : myTools.values()) {
for (ScopeToolState state : tools.getTools()) {
result.add(state.getLevel().getSeverity());
}
@@ -289,7 +280,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
synchronized (myExternalInfo) {
if (!myInitialized) {
for (Element el : myDeinstalledInspectionsSettings.values()) {
element.addContent((Element)el.clone());
element.addContent(el.clone());
}
return;
}
@@ -315,22 +306,21 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
element.addContent(inspectionElement);
}
else {
element.addContent((Element)toolElement.clone());
element.addContent(toolElement.clone());
}
}
}
}
public void collectDependentInspections(@NotNull InspectionProfileEntry profileEntry, @NotNull Set<InspectionProfileEntry> dependentEntries) {
String mainToolId = profileEntry.getMainToolId();
public void collectDependentInspections(@NotNull InspectionToolWrapper toolWrapper, @NotNull Set<InspectionToolWrapper> dependentEntries) {
String mainToolId = toolWrapper.getMainToolId();
if (mainToolId != null) {
InspectionProfileEntry dependentEntry = getInspectionTool(mainToolId);
InspectionToolWrapper dependentEntryWrapper = getInspectionTool(mainToolId);
if (dependentEntry != null) {
if (!dependentEntries.contains(dependentEntry)) {
dependentEntries.add(dependentEntry);
collectDependentInspections(dependentEntry, dependentEntries);
if (dependentEntryWrapper != null) {
if (!dependentEntries.add(dependentEntryWrapper)) {
collectDependentInspections(dependentEntryWrapper, dependentEntries);
}
}
else {
@@ -341,16 +331,16 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
@Nullable
public InspectionProfileEntry getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
final Tools toolList = getTools(shortName);
return toolList != null ? toolList.getInspectionTool(element) : null;
return toolList != null ? (InspectionToolWrapper)toolList.getInspectionTool(element) : null;
}
@Nullable
@Override
public InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element) {
InspectionProfileEntry tool = getInspectionTool(shortName, element);
return tool instanceof InspectionToolWrapper ? ((InspectionToolWrapper)tool).getTool() : tool;
InspectionToolWrapper tool = getInspectionTool(shortName, element);
return tool == null ? tool : tool.getTool();
}
@Override
@@ -387,15 +377,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
@Nullable
public InspectionProfileEntry getInspectionTool(@NotNull String shortName) {
public InspectionToolWrapper getInspectionTool(@NotNull String shortName) {
final ToolsImpl tools = getTools(shortName);
return tools != null? tools.getTool() : null;
}
public InspectionProfileEntry getToolById(@NotNull String id, @NotNull PsiElement element) {
public InspectionToolWrapper getToolById(@NotNull String id, @NotNull PsiElement element) {
initInspectionTools(element.getProject());
for (Tools toolList : myTools.values()) {
final InspectionProfileEntry tool = toolList.getInspectionTool(element);
final InspectionToolWrapper tool = (InspectionToolWrapper)toolList.getInspectionTool(element);
String toolId =
tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getID() : tool.getShortName();
if (id.equals(toolId)) return tool;
@@ -459,18 +449,20 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
@NotNull
public InspectionProfileEntry[] getInspectionTools(@Nullable PsiElement element) {
public InspectionToolWrapper[] getInspectionTools(@Nullable PsiElement element) {
initInspectionTools(element != null ? element.getProject() : null);
List<InspectionTool> result = new ArrayList<InspectionTool>();
List<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
for (Tools toolList : myTools.values()) {
result.add((InspectionTool)toolList.getInspectionTool(element));
result.add((InspectionToolWrapper)toolList.getInspectionTool(element));
}
return result.toArray(new InspectionTool[result.size()]);
return result.toArray(new InspectionToolWrapper[result.size()]);
}
public List<ToolsImpl> getAllEnabledInspectionTools(Project project) {
@Override
@NotNull
public List<Tools> getAllEnabledInspectionTools(Project project) {
initInspectionTools(project);
final ArrayList<ToolsImpl> result = new ArrayList<ToolsImpl>();
List<Tools> result = new ArrayList<Tools>();
for (final ToolsImpl toolList : myTools.values()) {
if (toolList.isEnabled()) {
result.add(toolList);
@@ -522,20 +514,20 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
catch (ProcessCanceledException e) {
return false;
}
for (InspectionToolWrapper tool : tools) {
final String shortName = tool.getShortName();
for (InspectionToolWrapper toolWrapper : tools) {
final String shortName = toolWrapper.getShortName();
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
final InspectionEP extension = tool.getExtension();
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<String>(tool.getDisplayName()) : new Computable<String>() {
final InspectionEP extension = toolWrapper.getExtension();
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<String>(toolWrapper.getDisplayName()) : new Computable<String>() {
@Override
public String compute() {
return extension.getDisplayName();
}
};
if (tool instanceof LocalInspectionToolWrapper) {
key = HighlightDisplayKey.register(shortName, computable, ((LocalInspectionToolWrapper)tool).getID(),
((LocalInspectionToolWrapper)tool).getAlternativeID());
if (toolWrapper instanceof LocalInspectionToolWrapper) {
key = HighlightDisplayKey.register(shortName, computable, ((LocalInspectionToolWrapper)toolWrapper).getID(),
((LocalInspectionToolWrapper)toolWrapper).getAlternativeID());
}
else {
key = HighlightDisplayKey.register(shortName, computable);
@@ -543,19 +535,19 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
HighlightDisplayLevel level = myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : tool.getDefaultLevel();
boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : tool.isEnabledByDefault();
final ToolsImpl toolsList = new ToolsImpl(tool, level, !myLockedProfile && enabled, enabled);
final Element element = myDeinstalledInspectionsSettings.remove(tool.getShortName());
HighlightDisplayLevel level = myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : toolWrapper.getDefaultLevel();
boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : toolWrapper.isEnabledByDefault();
final ToolsImpl toolsList = new ToolsImpl(toolWrapper, level, !myLockedProfile && enabled, enabled);
final Element element = myDeinstalledInspectionsSettings.remove(toolWrapper.getShortName());
if (element != null) {
try {
toolsList.readExternal(element, this);
}
catch (InvalidDataException e) {
LOG.error("Can't read settings for " + tool, e);
LOG.error("Can't read settings for " + toolWrapper, e);
}
}
myTools.put(tool.getShortName(), toolsList);
myTools.put(toolWrapper.getShortName(), toolsList);
}
if (mySource != null) {
copyToolsConfigurations(mySource, project);
@@ -609,12 +601,13 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
final List<ScopeToolState> nonDefaultToolStates = toolList.getNonDefaultTools();
if (nonDefaultToolStates != null) {
for (ScopeToolState state : nonDefaultToolStates) {
final InspectionTool inspectionTool = copyToolSettings((InspectionToolWrapper)state.getTool());
final InspectionToolWrapper toolWrapper = copyToolSettings((InspectionToolWrapper)state.getTool());
final NamedScope scope = project != null ? state.getScope(project) : ScopeToolStateUtil.getScope(state);
if (scope != null) {
tools.addTool(scope, inspectionTool, state.isEnabled(), state.getLevel());
} else {
tools.addTool(state.getScopeName(), inspectionTool, state.isEnabled(), state.getLevel());
tools.addTool(scope, toolWrapper, state.isEnabled(), state.getLevel());
}
else {
tools.addTool(state.getScopeName(), toolWrapper, state.isEnabled(), state.getLevel());
}
}
}
@@ -629,9 +622,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@NotNull
private static InspectionTool copyToolSettings(@NotNull InspectionToolWrapper tool)
private static InspectionToolWrapper copyToolSettings(@NotNull InspectionToolWrapper tool)
throws WriteExternalException, InvalidDataException {
final InspectionTool inspectionTool = tool.createCopy();
final InspectionToolWrapper inspectionTool = tool.createCopy();
if (tool.isInitialized()) {
@NonNls String tempRoot = "config";
Element config = new Element(tempRoot);
@@ -642,18 +635,18 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@Override
public void cleanup(Project project) {
public void cleanup(@NotNull Project project) {
for (final ToolsImpl toolList : myTools.values()) {
if (toolList.isEnabled()) {
for (InspectionProfileEntry tool : toolList.getAllTools()) {
tool.projectClosed(project);
((InspectionTool)tool).cleanup();
for (InspectionToolWrapper toolWrapper : toolList.getAllTools()) {
toolWrapper.projectClosed(project);
toolWrapper.cleanup();
}
}
}
}
public void enableTool(String inspectionTool) {
public void enableTool(@NotNull String inspectionTool) {
final ToolsImpl tools = getTools(inspectionTool);
tools.setEnabled(true);
if (tools.getNonDefaultTools() == null) {
@@ -682,7 +675,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@Override
public void setErrorLevel(@NotNull HighlightDisplayKey key, HighlightDisplayLevel level) {
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level) {
getTools(key.toString()).setLevel(level);
}
@@ -703,7 +696,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
public boolean isExecutable() {
initInspectionTools(null);
for (ToolsImpl tools : myTools.values()) {
for (Tools tools : myTools.values()) {
if (tools.isEnabled()) return true;
}
return false;
@@ -755,6 +748,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@Override
public void convert(@NotNull Element element) {
initInspectionTools(null);
final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
@@ -770,12 +764,12 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
if (inspectionProfile != null) {
final NamedScope scope = getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
if (scope != null) {
for (InspectionProfileEntry entry : inspectionProfile.getInspectionTools(null)) {
final HighlightDisplayKey key = HighlightDisplayKey.find(entry.getShortName());
for (InspectionToolWrapper wrapper : inspectionProfile.getInspectionTools(null)) {
final HighlightDisplayKey key = HighlightDisplayKey.find(wrapper.getShortName());
try {
getTools(entry.getShortName())
.addTool(scope, copyToolSettings((InspectionToolWrapper)entry), inspectionProfile.isToolEnabled(key),
inspectionProfile.getErrorLevel(key, (NamedScope)null));
InspectionToolWrapper toolWrapper = copyToolSettings(wrapper);
getTools(wrapper.getShortName())
.addTool(scope, toolWrapper, inspectionProfile.isToolEnabled(key), inspectionProfile.getErrorLevel(key, (NamedScope)null));
}
catch (Exception e) {
LOG.error(e);
@@ -881,33 +875,33 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return myDisplayLevelMap;
}
@NotNull
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, NamedScope scope) {
final ToolsImpl tools = getTools(key.toString());
return tools != null ? tools.getLevel(scope) : HighlightDisplayLevel.WARNING;
}
public ScopeToolState addScope(@NotNull InspectionProfileEntry tool, NamedScope scope, HighlightDisplayLevel level, boolean enabled) {
return getTools(tool.getShortName()).prependTool(scope, tool, enabled, level);
public ScopeToolState addScope(@NotNull InspectionToolWrapper toolWrapper, NamedScope scope, @NotNull HighlightDisplayLevel level, boolean enabled) {
return getTools(toolWrapper.getShortName()).prependTool(scope, toolWrapper, enabled, level);
}
public void setErrorLevel(@NotNull HighlightDisplayKey key, HighlightDisplayLevel level, int scopeIdx) {
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, int scopeIdx) {
getTools(key.toString()).setLevel(level, scopeIdx);
}
private ToolsImpl getTools(String toolId) {
private ToolsImpl getTools(@NotNull String toolId) {
initInspectionTools(null);
return myTools.get(toolId);
}
public void enableAllTools() {
for (InspectionProfileEntry entry : getInspectionTools(null)) {
for (InspectionToolWrapper entry : getInspectionTools(null)) {
enableTool(entry.getShortName());
}
}
public void disableAllTools() {
for (InspectionProfileEntry entry : getInspectionTools(null)) {
for (InspectionToolWrapper entry : getInspectionTools(null)) {
disableTool(entry.getShortName());
}
}
@@ -64,14 +64,14 @@ public abstract class InspectionRVContentProvider {
boolean supportStructure();
}
public abstract boolean checkReportedProblems(@NotNull InspectionTool tool);
public abstract boolean checkReportedProblems(@NotNull InspectionToolWrapper toolWrapper);
@Nullable
public abstract QuickFixAction[] getQuickFixes(@NotNull InspectionTool tool, @NotNull InspectionTree tree);
public void appendToolNodeContent(@NotNull InspectionNode toolNode,
final InspectionTreeNode parentNode,
@NotNull InspectionTreeNode parentNode,
final boolean showStructure) {
final InspectionTool tool = toolNode.getTool();
final Map<String, Set<RefEntity>> content = tool.getContent();
@@ -86,9 +86,9 @@ public abstract class InspectionRVContentProvider {
final Map<RefEntity, CommonProblemDescriptor[]> problems,
@Nullable final DefaultTreeModel model);
protected abstract void appendDescriptor(final InspectionTool tool,
final UserObjectContainer container,
final InspectionPackageNode pNode,
protected abstract void appendDescriptor(@NotNull InspectionTool tool,
@NotNull UserObjectContainer container,
@NotNull InspectionPackageNode pNode,
final boolean canPackageRepeat);
public boolean isContentLoaded() {
@@ -211,6 +211,7 @@ public abstract class InspectionRVContentProvider {
return content;
}
@NotNull
protected static RefElementNode addNodeToParent(@NotNull UserObjectContainer container,
@NotNull InspectionTool tool,
final InspectionTreeNode parentNode) {
@@ -46,9 +46,9 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
}
@Override
public boolean checkReportedProblems(@NotNull final InspectionTool tool) {
tool.updateContent();
return tool.hasReportedProblems();
public boolean checkReportedProblems(@NotNull final InspectionToolWrapper toolWrapper) {
toolWrapper.updateContent();
return toolWrapper.hasReportedProblems();
}
@Override
@@ -64,7 +64,8 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
final InspectionTreeNode parentNode,
final boolean showStructure,
final Map<String, Set<RefEntity>> contents,
final Map<RefEntity, CommonProblemDescriptor[]> problems, DefaultTreeModel model) {
final Map<RefEntity, CommonProblemDescriptor[]> problems,
DefaultTreeModel model) {
final InspectionTool tool = toolNode.getTool();
Function<RefEntity, UserObjectContainer<RefEntity>> computeContainer = new Function<RefEntity, UserObjectContainer<RefEntity>>() {
@@ -110,9 +111,9 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
}
@Override
protected void appendDescriptor(final InspectionTool tool,
final UserObjectContainer container,
final InspectionPackageNode pNode,
protected void appendDescriptor(@NotNull final InspectionTool tool,
@NotNull final UserObjectContainer container,
@NotNull final InspectionPackageNode pNode,
final boolean canPackageRepeat) {
final GlobalInspectionContextImpl context = tool.getContext();
final RefElementContainer refElementDescriptor = (RefElementContainer)container;
@@ -26,7 +26,7 @@ import com.intellij.analysis.AnalysisScope;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInsight.daemon.impl.SeverityUtil;
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.reference.*;
@@ -37,6 +37,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManagerImpl;
import com.intellij.psi.PsiElement;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
@@ -108,6 +109,7 @@ public abstract class InspectionTool extends InspectionProfileEntry {
return getShortName();
}
@Override
public void cleanup() {
if (myContext != null) {
projectClosed(myContext.getProject());
@@ -182,7 +184,8 @@ public abstract class InspectionTool extends InspectionProfileEntry {
final Tools tools = myContext.getTools().get(getShortName());
if (tools != null) {
for (ScopeToolState state : tools.getTools()) {
if (state.getTool() == this) {
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
if (toolWrapper == this) {
return myContext.getCurrentProfile().getErrorLevel(HighlightDisplayKey.find(getShortName()), psiElement).getSeverity();
}
}
@@ -206,7 +209,8 @@ public abstract class InspectionTool extends InspectionProfileEntry {
if (highlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
return HighlightInfoType.UNUSED_SYMBOL.getAttributesKey().getExternalName();
}
return SeverityUtil.getSeverityRegistrar(project).getHighlightInfoTypeBySeverity(severity).getAttributesKey().getExternalName();
SeverityRegistrar registrar = InspectionProjectProfileManagerImpl.getInstanceImpl(project).getSeverityRegistrar();
return registrar.getHighlightInfoTypeBySeverity(severity).getAttributesKey().getExternalName();
}
public static void setOutputPath(final String output) {
@@ -219,14 +223,15 @@ public abstract class InspectionTool extends InspectionProfileEntry {
return null;
}
public InspectionNode createToolNode(final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showStructure) {
myToolNode = new InspectionNode(this);
provider.appendToolNodeContent(myToolNode, parentNode, showStructure);
return myToolNode;
}
@Nullable
public SuppressIntentionAction[] getSuppressActions() {
return null;
}
@NotNull
public InspectionNode createToolNode(@NotNull InspectionRVContentProvider provider, @NotNull InspectionTreeNode parentNode, final boolean showStructure) {
myToolNode = new InspectionNode(this);
provider.appendToolNodeContent(myToolNode, parentNode, showStructure);
return myToolNode;
}
}
@@ -97,6 +97,7 @@ public class InspectionToolRegistrar {
}
for (InspectionToolsFactory factory : Extensions.getExtensions(InspectionToolsFactory.EXTENSION_POINT_NAME)) {
for (final InspectionProfileEntry profileEntry : factory.createTools()) {
assert !(profileEntry instanceof InspectionToolWrapper) : profileEntry;
myInspectionToolFactories.add(new Factory<InspectionToolWrapper>() {
@Override
public InspectionToolWrapper create() {
@@ -110,9 +111,7 @@ public class InspectionToolRegistrar {
@NotNull
public static InspectionToolWrapper wrapTool(@NotNull InspectionProfileEntry profileEntry) {
if (profileEntry instanceof InspectionToolWrapper) {
return (InspectionToolWrapper)profileEntry;
}
assert !(profileEntry instanceof InspectionToolWrapper) : profileEntry;
if (profileEntry instanceof LocalInspectionTool) {
return new LocalInspectionToolWrapper((LocalInspectionTool)profileEntry);
}
@@ -19,10 +19,12 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInspection.*;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.util.Function;
import com.intellij.util.ResourceUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
@@ -36,6 +38,8 @@ import java.net.URL;
* Date: 9/28/11
*/
public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E extends InspectionEP> extends DescriptorProviderInspection {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolWrapper");
protected T myTool;
protected final E myEP;
@@ -90,14 +94,14 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
return myEP != null && myEP.applyToDialects;
}
@NotNull
@Override
@NotNull
public String getShortName() {
return myEP != null ? myEP.getShortName() : getTool().getShortName();
}
@NotNull
@Override
@NotNull
public String getDisplayName() {
if (myEP == null) {
return getTool().getDisplayName();
@@ -108,8 +112,8 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
}
}
@NotNull
@Override
@NotNull
public String getGroupDisplayName() {
if (myEP == null) {
return getTool().getGroupDisplayName();
@@ -125,14 +129,14 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
return myEP == null ? getTool().isEnabledByDefault() : myEP.enabledByDefault;
}
@NotNull
@Override
@NotNull
public HighlightDisplayLevel getDefaultLevel() {
return myEP == null ? getTool().getDefaultLevel() : myEP.getDefaultLevel();
}
@NotNull
@Override
@NotNull
public String[] getGroupPath() {
if (myEP == null) {
return getTool().getGroupPath();
@@ -181,12 +185,22 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
protected URL getDescriptionUrl() {
Application app = ApplicationManager.getApplication();
if (myEP == null || app.isUnitTestMode() || app.isHeadlessEnvironment()) {
return super.getDescriptionUrl();
return superGetDescriptionUrl();
}
String fileName = getDescriptionFileName();
return myEP.getLoaderForClass().getResource("/inspectionDescriptions/" + fileName);
}
@Nullable
protected URL superGetDescriptionUrl() {
final String fileName = getDescriptionFileName();
return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
}
//public String getDescriptionFileName() {
// return getShortName() + ".html";
//}
@Override
public SuppressIntentionAction[] getSuppressActions() {
T tool = getTool();
@@ -202,7 +216,7 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
}
});
}
return super.getSuppressActions();
return null;
}
@Override
@@ -223,4 +237,9 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
public String toString() {
return getShortName();
}
@Override
public void cleanup() {
getTool().cleanup();
}
}
@@ -22,6 +22,7 @@ import com.intellij.codeInspection.*;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.codeInspection.reference.RefManagerImpl;
import com.intellij.codeInspection.ui.InspectionNode;
import com.intellij.codeInspection.ui.InspectionResultsView;
import com.intellij.codeInspection.ui.InspectionTreeNode;
import com.intellij.lang.annotation.HighlightSeverity;
@@ -74,27 +75,8 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
}
public void processFile(@NotNull PsiFile file, final boolean filterSuppressed, @NotNull InspectionManager manager) {
processFile(file, filterSuppressed, manager, false);
}
public void processFile(@NotNull PsiFile file, final boolean filterSuppressed, @NotNull InspectionManager manager, final boolean isOnTheFly) {
final ProblemsHolder holder = new ProblemsHolder(manager, file, isOnTheFly);
LocalInspectionToolSession session = new LocalInspectionToolSession(file, 0, file.getTextLength());
final PsiElementVisitor customVisitor = getTool().buildVisitor(holder, isOnTheFly, session);
LOG.assertTrue(!(customVisitor instanceof PsiRecursiveElementVisitor), "The visitor returned from LocalInspectionTool.buildVisitor() must not be recursive");
getTool().inspectionStarted(session, isOnTheFly);
file.accept(new PsiRecursiveElementWalkingVisitor() {
@Override public void visitElement(PsiElement element) {
element.accept(customVisitor);
super.visitElement(element);
}
});
getTool().inspectionFinished(session, holder);
addProblemDescriptors(holder.getResults(), filterSuppressed);
List<ProblemDescriptor> results = getTool().processFile(file, manager);
addProblemDescriptors(results, this, filterSuppressed, getContext(), getTool());
}
@Override
@@ -103,20 +85,22 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
return context.getStdJobDescriptors().LOCAL_ANALYSIS_ARRAY;
}
public void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors, final boolean filterSuppressed) {
final GlobalInspectionContextImpl context = getContext();
if (context != null) { //can be already closed
addProblemDescriptors(descriptors, filterSuppressed, context, getTool(), CONVERT, this);
}
public static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors,
@NotNull DescriptorProviderInspection dpi,
boolean filterSuppressed,
@NotNull GlobalInspectionContext inspectionContext,
@NotNull LocalInspectionTool tool) {
addProblemDescriptors(descriptors, filterSuppressed, inspectionContext, tool, CONVERT, dpi);
}
private static final TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext,RefElement> CONVERT = new TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext,RefElement>() {
@Override
public RefElement fun(LocalInspectionTool tool, PsiElement elt, GlobalInspectionContext context) {
final PsiNamedElement problemElement = tool.getProblemElement(elt);
public RefElement fun(LocalInspectionTool tool, PsiElement element, GlobalInspectionContext context) {
final PsiNamedElement problemElement = tool.getProblemElement(element);
RefElement refElement = context.getRefManager().getReference(problemElement);
if (refElement == null && problemElement != null) { // no need to lose collected results
refElement = GlobalInspectionUtil.retrieveRefElement(elt, context);
refElement = GlobalInspectionUtil.retrieveRefElement(element, context);
}
return refElement;
}
@@ -128,67 +112,70 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
if (context == null) return;
super.addProblemElement(refElement, filterSuppressed, descriptions);
final InspectionResultsView view = context.getView();
if (view != null && refElement instanceof RefElement) {
if (myToolNode == null) {
final HighlightSeverity currentSeverity = getCurrentSeverity((RefElement)refElement);
view.addTool(this, HighlightDisplayLevel.find(currentSeverity), context.getUIOptions().GROUP_BY_SEVERITY);
} else if (myToolNode.isTooBigForOnlineRefresh()) {
return;
}
final HashMap<RefEntity, CommonProblemDescriptor[]> problems = new HashMap<RefEntity, CommonProblemDescriptor[]>();
problems.put(refElement, descriptions);
final HashMap<String, Set<RefEntity>> contents = new HashMap<String, Set<RefEntity>>();
final String groupName = refElement.getRefManager().getGroupName((RefElement)refElement);
Set<RefEntity> content = contents.get(groupName);
if (content == null) {
content = new HashSet<RefEntity>();
contents.put(groupName, content);
}
content.add(refElement);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
final GlobalInspectionContextImpl context = getContext();
if (context != null) {
view.getProvider().appendToolNodeContent(myToolNode,
(InspectionTreeNode)myToolNode.getParent(), context.getUIOptions().SHOW_STRUCTURE,
contents, problems, (DefaultTreeModel)view.getTree().getModel());
context.addView(view);
}
}
});
if (view == null || !(refElement instanceof RefElement)) {
return;
}
final InspectionNode toolNode = myToolNode;
if (toolNode == null) {
final HighlightSeverity currentSeverity = getCurrentSeverity((RefElement)refElement);
view.addTool(this, HighlightDisplayLevel.find(currentSeverity), context.getUIOptions().GROUP_BY_SEVERITY);
}
else if (toolNode.isTooBigForOnlineRefresh()) {
return;
}
final HashMap<RefEntity, CommonProblemDescriptor[]> problems = new HashMap<RefEntity, CommonProblemDescriptor[]>();
problems.put(refElement, descriptions);
final HashMap<String, Set<RefEntity>> contents = new HashMap<String, Set<RefEntity>>();
final String groupName = refElement.getRefManager().getGroupName((RefElement)refElement);
Set<RefEntity> content = contents.get(groupName);
if (content == null) {
content = new HashSet<RefEntity>();
contents.put(groupName, content);
}
content.add(refElement);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
final GlobalInspectionContextImpl context = getContext();
if (context != null) {
view.getProvider().appendToolNodeContent(myToolNode,
(InspectionTreeNode)myToolNode.getParent(), context.getUIOptions().SHOW_STRUCTURE,
contents, problems, (DefaultTreeModel)view.getTree().getModel());
context.addView(view);
}
}
});
}
public static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors,
boolean filterSuppressed,
@NotNull GlobalInspectionContextImpl context,
@Nullable LocalInspectionTool tool,
@NotNull TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext, RefElement> getProblemElementFunction,
@NotNull DescriptorProviderInspection dpi) {
static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors,
boolean filterSuppressed,
@NotNull GlobalInspectionContext context,
@Nullable LocalInspectionTool tool,
@NotNull TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext, RefElement> getProblemElementFunction,
@NotNull DescriptorProviderInspection dpi) {
if (descriptors.isEmpty()) return;
Map<RefElement, List<ProblemDescriptor>> problems = new HashMap<RefElement, List<ProblemDescriptor>>();
final RefManagerImpl refManager = (RefManagerImpl)context.getRefManager();
for (ProblemDescriptor descriptor : descriptors) {
final PsiElement elt = descriptor.getPsiElement();
if (elt == null) continue;
final PsiElement element = descriptor.getPsiElement();
if (element == null) continue;
if (filterSuppressed) {
String alternativeId;
String id;
if (refManager.isDeclarationsFound() &&
(context.isSuppressed(elt, id = tool.getID()) ||
(context.isSuppressed(element, id = tool.getID()) ||
(alternativeId = tool.getAlternativeID()) != null &&
!alternativeId.equals(id) &&
context.isSuppressed(elt, alternativeId))) {
context.isSuppressed(element, alternativeId))) {
continue;
}
if (InspectionManagerEx.inspectionResultSuppressed(elt, tool)) continue;
if (InspectionManagerEx.inspectionResultSuppressed(element, tool)) continue;
}
RefElement refElement = getProblemElementFunction.fun(tool, elt, context);
RefElement refElement = getProblemElementFunction.fun(tool, element, context);
List<ProblemDescriptor> elementProblems = problems.get(refElement);
if (elementProblems == null) {
@@ -200,9 +187,9 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
for (Map.Entry<RefElement, List<ProblemDescriptor>> entry : problems.entrySet()) {
final List<ProblemDescriptor> problemDescriptors = entry.getValue();
dpi.addProblemElement(entry.getKey(),
filterSuppressed,
problemDescriptors.toArray(new CommonProblemDescriptor[problemDescriptors.size()]));
RefElement refElement = entry.getKey();
CommonProblemDescriptor[] descriptions = problemDescriptors.toArray(new CommonProblemDescriptor[problemDescriptors.size()]);
dpi.addProblemElement(refElement, filterSuppressed, descriptions);
}
}
@@ -245,15 +232,15 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
}
};
public static InspectionProfileEntry findTool2RunInBatch(Project project, @Nullable PsiElement element, final String name) {
public static InspectionToolWrapper findTool2RunInBatch(@NotNull Project project, @Nullable PsiElement element, @NotNull String name) {
final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
final InspectionProfileEntry tool = element != null ? inspectionProfile.getInspectionTool(name, element) : inspectionProfile.getInspectionTool(name);
final InspectionToolWrapper tool = element != null ? (InspectionToolWrapper)inspectionProfile.getInspectionTool(name, element) : (InspectionToolWrapper)inspectionProfile.getInspectionTool(name);
if (tool instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)tool).isUnfair()) {
final LocalInspectionTool inspectionTool = ((LocalInspectionToolWrapper)tool).getTool();
if (inspectionTool instanceof PairedUnfairLocalInspectionTool) {
final String oppositeShortName = ((PairedUnfairLocalInspectionTool)inspectionTool).getInspectionForBatchShortName();
if (oppositeShortName != null) {
return element != null ? inspectionProfile.getInspectionTool(oppositeShortName, element) : inspectionProfile.getInspectionTool(oppositeShortName);
return element != null ? (InspectionToolWrapper)inspectionProfile.getInspectionTool(oppositeShortName, element) : (InspectionToolWrapper)inspectionProfile.getInspectionTool(oppositeShortName);
}
}
return null;
@@ -1,7 +1,6 @@
package com.intellij.codeInspection.ex;
import com.intellij.codeInspection.InspectionApplication;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsReportConverter;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -93,13 +92,13 @@ public class PlainTextFormatter implements InspectionsReportConverter {
continue;
}
final InspectionProfileEntry tool = tools.get(fileNameWithoutExt).getTool();
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)tools.get(fileNameWithoutExt).getTool();
// Tool name and group
w.append(getToolPresentableName(tool)).append("\n");
w.append(getToolPresentableName(toolWrapper)).append("\n");
// Description is HTML based, need to be converted in plain text
writeInspectionDescription(w, tool, transformer);
writeInspectionDescription(w, toolWrapper, transformer);
// separator before file list
w.append("\n");
@@ -114,7 +113,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
final List problems = root.getChildren(PROBLEM_ELEMENT);
// let's count max file path & line_number length to align problem descriptions
final int maxFileColonLineLength = getMaxFileColonLineNumLength(inspectionData, tool, problems);
final int maxFileColonLineLength = getMaxFileColonLineNumLength(inspectionData, toolWrapper, problems);
for (Object problem : problems) {
// Format:
@@ -124,7 +123,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
final String filePath = getPath(fileElement);
// skip suppressed results
if (resultsIgnored(inspectionData, tool)) {
if (resultsIgnored(inspectionData, toolWrapper)) {
continue;
}
@@ -165,7 +164,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
}
private int getMaxFileColonLineNumLength(@NotNull final File inspectionResultData,
@NotNull final InspectionProfileEntry tool,
@NotNull final InspectionToolWrapper toolWrapper,
@NotNull final List problems) {
int maxFileColonLineLength = 0;
for (Object problem : problems) {
@@ -174,7 +173,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
final String filePath = getPath(fileElement);
// skip suppressed results
if (resultsIgnored(inspectionResultData, tool)) {
if (resultsIgnored(inspectionResultData, toolWrapper)) {
continue;
}
@@ -188,7 +187,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
}
private boolean resultsIgnored(@NotNull final File file,
@NotNull final InspectionProfileEntry tool) {
@NotNull final InspectionToolWrapper toolWrapper) {
// TODO: check according to config
return false;
}
@@ -199,12 +198,12 @@ public class PlainTextFormatter implements InspectionsReportConverter {
}
protected void writeInspectionDescription(@NotNull final Writer w,
@NotNull final InspectionProfileEntry tool,
@NotNull final InspectionToolWrapper toolWrapper,
@NotNull final Transformer transformer)
throws IOException, ConversionException {
final StringWriter descrWriter = new StringWriter();
String descr = tool.loadDescription();
String descr = toolWrapper.loadDescription();
if (descr == null) {
return;
}
@@ -217,7 +216,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
}
catch (TransformerException e) {
// Not critical problem, just inspection error cannot be loaded
warn("ERROR: Cannot load description for inspection: " + getToolPresentableName(tool) + ".\n Error message: " + e.getMessage());
warn("ERROR: Cannot load description for inspection: " + getToolPresentableName(toolWrapper) + ".\n Error message: " + e.getMessage());
return;
}
@@ -231,14 +230,14 @@ public class PlainTextFormatter implements InspectionsReportConverter {
}
@NotNull
protected String getToolPresentableName(@NotNull final InspectionProfileEntry tool) throws IOException {
protected String getToolPresentableName(@NotNull final InspectionToolWrapper toolWrapper) throws IOException {
final StringBuilder buff = new StringBuilder();
// inspection name
buff.append(tool.getDisplayName()).append(" (");
buff.append(toolWrapper.getDisplayName()).append(" (");
// group name
final String[] groupPath = tool.getGroupPath();
final String[] groupPath = toolWrapper.getGroupPath();
for (int i = 0, groupPathLength = groupPath.length; i < groupPathLength; i++) {
if (i != 0) {
buff.append(" | ");
@@ -22,12 +22,13 @@ package com.intellij.codeInspection.ex;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.profile.ProfileEx;
import com.intellij.profile.ProfileManager;
import com.intellij.profile.codeInspection.SeverityProvider;
import com.intellij.psi.PsiElement;
@@ -56,45 +57,45 @@ public class ToolsImpl implements Tools {
private List<ScopeToolState> myTools;
private boolean myEnabled;
public ToolsImpl(@NotNull InspectionProfileEntry tool, HighlightDisplayLevel level, boolean enabled, boolean enabledByDefault) {
myShortName = tool.getShortName();
public ToolsImpl(@NotNull InspectionToolWrapper toolWrapper, @NotNull HighlightDisplayLevel level, boolean enabled, boolean enabledByDefault) {
myShortName = toolWrapper.getShortName();
myEnabled = enabled;
myDefaultState = new ScopeToolState(CustomScopesProviderEx.getAllScope(), tool, enabledByDefault, level);
myDefaultState = new ScopeToolState(CustomScopesProviderEx.getAllScope(), toolWrapper, enabledByDefault, level);
}
@TestOnly
public ToolsImpl(@NotNull InspectionProfileEntry tool, HighlightDisplayLevel level, boolean enabled) {
this(tool, level, enabled, enabled);
public ToolsImpl(@NotNull InspectionToolWrapper toolWrapper, @NotNull HighlightDisplayLevel level, boolean enabled) {
this(toolWrapper, level, enabled, enabled);
}
@NotNull
public ScopeToolState addTool(@NotNull NamedScope scope, @NotNull InspectionProfileEntry tool, boolean enabled, HighlightDisplayLevel level) {
return insertTool(scope, tool, enabled, level, myTools != null ? myTools.size() : 0);
public ScopeToolState addTool(@NotNull NamedScope scope, @NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {
return insertTool(scope, toolWrapper, enabled, level, myTools != null ? myTools.size() : 0);
}
@NotNull
public ScopeToolState prependTool(@NotNull NamedScope scope, @NotNull InspectionProfileEntry tool, boolean enabled, HighlightDisplayLevel level) {
return insertTool(scope, tool, enabled, level, 0);
public ScopeToolState prependTool(@NotNull NamedScope scope, @NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {
return insertTool(scope, toolWrapper, enabled, level, 0);
}
@NotNull
private ScopeToolState insertTool(@NotNull NamedScope scope, @NotNull InspectionProfileEntry tool, boolean enabled, HighlightDisplayLevel level, int idx) {
private ScopeToolState insertTool(@NotNull NamedScope scope, @NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level, int idx) {
if (myTools == null) {
myTools = new ArrayList<ScopeToolState>();
setEnabled(true);
}
final ScopeToolState scopeToolState = new ScopeToolState(scope, tool, enabled, level);
final ScopeToolState scopeToolState = new ScopeToolState(scope, toolWrapper, enabled, level);
myTools.add(idx, scopeToolState);
return scopeToolState;
}
@Override
public InspectionProfileEntry getInspectionTool(PsiElement element) {
public InspectionToolWrapper getInspectionTool(PsiElement element) {
if (myTools != null) {
final Project project = element != null ? element.getProject() : null;
for (ScopeToolState state : myTools) {
if (element == null) {
return state.getTool();
return (InspectionToolWrapper)state.getTool();
}
else {
final NamedScope scope = state.getScope(project);
@@ -103,7 +104,7 @@ public class ToolsImpl implements Tools {
if (packageSet != null) {
final PsiFile containingFile = element.getContainingFile();
if (containingFile != null && packageSet.contains(containingFile, DependencyValidationManager.getInstance(project))) {
return state.getTool();
return (InspectionToolWrapper)state.getTool();
}
}
}
@@ -112,11 +113,11 @@ public class ToolsImpl implements Tools {
for (ScopeToolState state : getTools()) {
if (state.getScope(project) == null) {
return state.getTool();
return (InspectionToolWrapper)state.getTool();
}
}
}
return myDefaultState.getTool();
return (InspectionToolWrapper)myDefaultState.getTool();
}
@NotNull
@@ -126,10 +127,11 @@ public class ToolsImpl implements Tools {
}
@NotNull
public List<InspectionProfileEntry> getAllTools() {
final List<InspectionProfileEntry> result = new ArrayList<InspectionProfileEntry>();
public List<InspectionToolWrapper> getAllTools() {
List<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
for (ScopeToolState state : getTools()) {
result.add(state.getTool());
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
result.add(toolWrapper);
}
return result;
}
@@ -141,18 +143,19 @@ public class ToolsImpl implements Tools {
scopeElement.setAttribute("name", state.getScopeName());
scopeElement.setAttribute(LEVEL_ATTRIBUTE, state.getLevel().toString());
scopeElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(state.isEnabled()));
InspectionProfileEntry InspectionProfileEntry = state.getTool();
InspectionProfileEntry.writeSettings(scopeElement);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
toolWrapper.writeSettings(scopeElement);
inspectionElement.addContent(scopeElement);
}
}
inspectionElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(isEnabled()));
inspectionElement.setAttribute(LEVEL_ATTRIBUTE, getLevel().toString());
inspectionElement.setAttribute(ENABLED_BY_DEFAULT_ATTRIBUTE, Boolean.toString(myDefaultState.isEnabled()));
myDefaultState.getTool().writeSettings(inspectionElement);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)myDefaultState.getTool();
toolWrapper.writeSettings(inspectionElement);
}
void readExternal(@NotNull Element toolElement, @NotNull InspectionProfileImpl profile) throws InvalidDataException {
void readExternal(@NotNull Element toolElement, @NotNull InspectionProfile profile) throws InvalidDataException {
final String levelName = toolElement.getAttributeValue(LEVEL_ATTRIBUTE);
final ProfileManager profileManager = profile.getProfileManager();
final SeverityRegistrar registrar = ((SeverityProvider)profileManager).getOwnSeverityRegistrar();
@@ -169,10 +172,10 @@ public class ToolsImpl implements Tools {
myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled);
final InspectionToolWrapper tool = (InspectionToolWrapper)myDefaultState.getTool();
final List scopeElements = toolElement.getChildren(InspectionProfileImpl.SCOPE);
final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
for (Object sO : scopeElements) {
final Element scopeElement = (Element)sO;
final String scopeName = scopeElement.getAttributeValue(InspectionProfileImpl.NAME);
final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
if (scopeName == null) {
continue;
}
@@ -183,10 +186,10 @@ public class ToolsImpl implements Tools {
}
final String errorLevel = scopeElement.getAttributeValue(LEVEL_ATTRIBUTE);
final String enabledInScope = scopeElement.getAttributeValue(ENABLED_ATTRIBUTE);
final InspectionProfileEntry copyTool = tool.createCopy();
final InspectionToolWrapper copyToolWrapper = tool.createCopy();
// check if unknown children exists
if (scopeElement.getAttributes().size() > 3 || scopeElement.getChildren().size() > 0) {
copyTool.readSettings(scopeElement);
if (scopeElement.getAttributes().size() > 3 || !scopeElement.getChildren().isEmpty()) {
copyToolWrapper.readSettings(scopeElement);
}
HighlightDisplayLevel scopeLevel = errorLevel != null ?
HighlightDisplayLevel.find(registrar.getSeverity(errorLevel)) : null;
@@ -194,10 +197,10 @@ public class ToolsImpl implements Tools {
scopeLevel = level;
}
if (namedScope != null) {
addTool(namedScope, copyTool, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
addTool(namedScope, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
}
else {
addTool(scopeName, copyTool, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
addTool(scopeName, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
}
}
@@ -207,21 +210,21 @@ public class ToolsImpl implements Tools {
}
}
public ScopeToolState addTool(@NotNull String scopeName, @NotNull InspectionProfileEntry tool, boolean enabled, HighlightDisplayLevel level) {
public ScopeToolState addTool(@NotNull String scopeName, @NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {
if (myTools == null) {
myTools = new ArrayList<ScopeToolState>();
setEnabled(true);
}
final ScopeToolState scopeToolState = new ScopeToolState(scopeName, tool, enabled, level);
final ScopeToolState scopeToolState = new ScopeToolState(scopeName, toolWrapper, enabled, level);
myTools.add(scopeToolState);
return scopeToolState;
}
@NotNull
@Override
public InspectionProfileEntry getTool() {
if (myTools == null) return myDefaultState.getTool();
return myTools.iterator().next().getTool();
public InspectionToolWrapper getTool() {
if (myTools == null) return (InspectionToolWrapper)myDefaultState.getTool();
return (InspectionToolWrapper)myTools.iterator().next().getTool();
}
@Override
@@ -256,9 +259,9 @@ public class ToolsImpl implements Tools {
public void setScope(int idx, NamedScope namedScope) {
if (myTools != null && myTools.size() > idx && idx >= 0) {
final ScopeToolState scopeToolState = myTools.get(idx);
final InspectionProfileEntry tool = scopeToolState.getTool();
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)scopeToolState.getTool();
myTools.remove(idx);
myTools.add(idx, new ScopeToolState(namedScope, tool, scopeToolState.isEnabled(), scopeToolState.getLevel()));
myTools.add(idx, new ScopeToolState(namedScope, toolWrapper, scopeToolState.isEnabled(), scopeToolState.getLevel()));
}
}
@@ -326,10 +329,10 @@ public class ToolsImpl implements Tools {
@Override
@Nullable
public InspectionTool getEnabledTool(PsiElement element) {
public InspectionToolWrapper getEnabledTool(PsiElement element) {
if (!myEnabled) return null;
if (myTools == null || element == null) {
return myDefaultState.isEnabled() ? (InspectionTool)myDefaultState.getTool() : null;
return myDefaultState.isEnabled() ? (InspectionToolWrapper)myDefaultState.getTool() : null;
}
final Project project = element.getProject();
final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
@@ -338,11 +341,11 @@ public class ToolsImpl implements Tools {
if (scope != null) {
final PackageSet set = scope.getValue();
if (set != null && set.contains(element.getContainingFile(), manager)) {
return state.isEnabled() ? (InspectionTool)state.getTool() : null;
return state.isEnabled() ? (InspectionToolWrapper)state.getTool() : null;
}
}
}
return myDefaultState.isEnabled() ? (InspectionTool)myDefaultState.getTool() : null;
return myDefaultState.isEnabled() ? (InspectionToolWrapper)myDefaultState.getTool() : null;
}
public void setEnabled(boolean enabled) {
@@ -397,6 +400,7 @@ public class ToolsImpl implements Tools {
}
}
@NotNull
public HighlightDisplayLevel getLevel(final NamedScope scope) {
if (myTools != null && scope != null){
for (ScopeToolState state : myTools) {
@@ -424,28 +428,31 @@ public class ToolsImpl implements Tools {
}
public void setLevel(HighlightDisplayLevel level, int idx) {
public void setLevel(@NotNull HighlightDisplayLevel level, int idx) {
if (myTools != null && myTools.size() > idx && idx >= 0) {
final ScopeToolState scopeToolState = myTools.get(idx);
myTools.remove(idx);
final NamedScope scope = ScopeToolStateUtil.getScope(scopeToolState);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)scopeToolState.getTool();
if (scope != null) {
myTools.add(idx, new ScopeToolState(scope, scopeToolState.getTool(), scopeToolState.isEnabled(), level));
} else {
myTools.add(idx, new ScopeToolState(scopeToolState.getScopeName(), scopeToolState.getTool(), scopeToolState.isEnabled(), level));
myTools.add(idx, new ScopeToolState(scope, toolWrapper, scopeToolState.isEnabled(), level));
}
} else if (idx == - 1) {
else {
myTools.add(idx, new ScopeToolState(scopeToolState.getScopeName(), toolWrapper, scopeToolState.isEnabled(), level));
}
}
else if (idx == -1) {
myDefaultState.setLevel(level);
}
}
public void setDefaultState(InspectionProfileEntry inspectionTool, boolean enabled, HighlightDisplayLevel level) {
myDefaultState.setTool(inspectionTool);
public void setDefaultState(@NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {
myDefaultState.setTool(toolWrapper);
myDefaultState.setLevel(level);
myDefaultState.setEnabled(enabled);
}
public void setLevel(HighlightDisplayLevel level) {
public void setLevel(@NotNull HighlightDisplayLevel level) {
myDefaultState.setLevel(level);
}
@@ -52,8 +52,8 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
}
@Override
public boolean checkReportedProblems(@NotNull final InspectionTool tool) {
final Map<String, Set<OfflineProblemDescriptor>> content = getFilteredContent(tool);
public boolean checkReportedProblems(@NotNull final InspectionToolWrapper toolWrapper) {
final Map<String, Set<OfflineProblemDescriptor>> content = getFilteredContent(toolWrapper);
return content != null && !content.values().isEmpty();
}
@@ -171,9 +171,9 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
}
@Override
protected void appendDescriptor(final InspectionTool tool,
final UserObjectContainer container,
final InspectionPackageNode packageNode,
protected void appendDescriptor(@NotNull final InspectionTool tool,
@NotNull final UserObjectContainer container,
@NotNull final InspectionPackageNode packageNode,
final boolean canPackageRepeat) {
final RefElementNode elemNode = addNodeToParent(container, tool, packageNode);
if (tool instanceof DescriptorProviderInspection && !(tool instanceof CommonInspectionToolWrapper)) {
@@ -41,6 +41,7 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.xml.util.XmlStringUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -359,7 +360,8 @@ class Browser extends JPanel {
PsiElement element = ((RefElement)refEntity).getElement();
if (element == null) return tool;
InspectionProfileWrapper profileWrapper = InspectionProjectProfileManagerImpl.getInstanceImpl(manager.getProject()).getProfileWrapper();
tool = (InspectionTool)profileWrapper.getInspectionTool(tool.getShortName(), element);
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profileWrapper.getInspectionTool(tool.getShortName(), element);
tool = toolWrapper;
}
return tool;
}
@@ -417,8 +419,8 @@ class Browser extends JPanel {
}
}
public void showDescription(InspectionTool tool){
if (tool.getShortName().length() == 0){
public void showDescription(@NotNull InspectionTool tool){
if (tool.getShortName().isEmpty()){
showEmpty();
return;
}
@@ -16,7 +16,7 @@
package com.intellij.internal;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
@@ -52,7 +52,7 @@ public class DumpInspectionDescriptionsAction extends AnAction implements DumbAw
@Override
public void actionPerformed(final AnActionEvent event) {
final InspectionProfile profile = (InspectionProfile)InspectionProfileManager.getInstance().getRootProfile();
final InspectionProfileEntry[] tools = profile.getInspectionTools(null);
final InspectionToolWrapper[] tools = (InspectionToolWrapper[])profile.getInspectionTools(null);
final Collection<String> classes = ContainerUtil.newTreeSet();
final Map<String, Collection<String>> groups = ContainerUtil.newTreeMap();
@@ -64,17 +64,17 @@ public class DumpInspectionDescriptionsAction extends AnAction implements DumbAw
return;
}
for (InspectionProfileEntry tool : tools) {
classes.add(getInspectionClass(tool).getName());
for (InspectionToolWrapper toolWrapper : tools) {
classes.add(getInspectionClass(toolWrapper).getName());
final String group = getGroupName(tool);
final String group = getGroupName(toolWrapper);
Collection<String> names = groups.get(group);
if (names == null) groups.put(group, (names = ContainerUtil.newTreeSet()));
names.add(tool.getShortName());
names.add(toolWrapper.getShortName());
final URL url = getDescriptionUrl(tool);
final URL url = getDescriptionUrl(toolWrapper);
if (url != null) {
doDump(new File(descDirectory, tool.getShortName() + ".html"), new Processor() {
doDump(new File(descDirectory, toolWrapper.getShortName() + ".html"), new Processor() {
@Override public void process(BufferedWriter writer) throws Exception {
writer.write(ResourceUtil.loadText(url));
}
@@ -116,18 +116,18 @@ public class DumpInspectionDescriptionsAction extends AnAction implements DumbAw
}
}
private static Class getInspectionClass(final InspectionProfileEntry tool) {
return tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getTool().getClass() : tool.getClass();
private static Class getInspectionClass(final InspectionToolWrapper toolWrapper) {
return toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getClass() : toolWrapper.getClass();
}
private static String getGroupName(final InspectionProfileEntry tool) {
final String name = tool.getGroupDisplayName();
private static String getGroupName(final InspectionToolWrapper toolWrapper) {
final String name = toolWrapper.getGroupDisplayName();
return StringUtil.isEmptyOrSpaces(name) ? "General" : name;
}
private static URL getDescriptionUrl(final InspectionProfileEntry tool) {
final Class aClass = getInspectionClass(tool);
return ResourceUtil.getResource(aClass, "/inspectionDescriptions", tool.getShortName() + ".html");
private static URL getDescriptionUrl(final InspectionToolWrapper toolWrapper) {
final Class aClass = getInspectionClass(toolWrapper);
return ResourceUtil.getResource(aClass, "/inspectionDescriptions", toolWrapper.getShortName() + ".html");
}
private interface Processor {
@@ -20,10 +20,10 @@
*/
package com.intellij.profile.codeInspection.ui;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.ex.Descriptor;
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.ide.ui.search.SearchUtil;
import com.intellij.ui.CheckboxTree;
@@ -97,12 +97,12 @@ abstract class InspectionsConfigTreeRenderer extends CheckboxTree.CheckboxTreeCe
@Nullable
private static String getHint(Descriptor descriptor) {
final InspectionProfileEntry tool = descriptor.getTool();
if (tool == null) {
final InspectionToolWrapper toolWrapper = descriptor.getTool();
if (toolWrapper == null) {
return InspectionsBundle.message("inspection.tool.availability.in.tree.node");
}
if (tool instanceof LocalInspectionToolWrapper ||
tool instanceof GlobalInspectionToolWrapper && !((GlobalInspectionToolWrapper)tool).worksInBatchModeOnly()) {
if (toolWrapper instanceof LocalInspectionToolWrapper ||
toolWrapper instanceof GlobalInspectionToolWrapper && !((GlobalInspectionToolWrapper)toolWrapper).worksInBatchModeOnly()) {
return null;
}
return InspectionsBundle.message("inspection.tool.availability.in.tree.node1");
@@ -24,7 +24,6 @@ import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
import com.intellij.codeInsight.daemon.impl.SeverityUtil;
import com.intellij.codeInsight.hint.HintUtil;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.ModifiableModel;
import com.intellij.codeInspection.ex.*;
@@ -196,13 +195,13 @@ public class SingleInspectionProfilePanel extends JPanel {
}
private boolean wereToolSettingsModified(Descriptor descriptor) {
InspectionProfileEntry tool = descriptor.getTool();
if (tool == null || !mySelectedProfile.isToolEnabled(descriptor.getKey())) {
InspectionToolWrapper toolWrapper = descriptor.getTool();
if (toolWrapper == null || !mySelectedProfile.isToolEnabled(descriptor.getKey())) {
return false;
}
Element oldConfig = descriptor.getConfig();
if (oldConfig == null) return false;
Element newConfig = Descriptor.createConfigElement(tool);
Element newConfig = Descriptor.createConfigElement(toolWrapper);
if (!JDOMUtil.areElementsEqual(oldConfig, newConfig)) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(new Runnable() {
@@ -250,7 +249,8 @@ public class SingleInspectionProfilePanel extends JPanel {
continue;
}
myDescriptors.put(new Descriptor(state, profile), descriptors);
final List<ScopeToolState> nonDefaultTools = profile.getNonDefaultTools(state.getTool().getShortName());
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
final List<ScopeToolState> nonDefaultTools = profile.getNonDefaultTools(toolWrapper.getShortName());
if (nonDefaultTools != null) {
for (ScopeToolState nonDefaultToolState : nonDefaultTools) {
descriptors.add(new Descriptor(nonDefaultToolState, profile));
@@ -290,9 +290,9 @@ public class SingleInspectionProfilePanel extends JPanel {
if (initValue == -1) {
inspectionProfile.initInspectionTools(null);
ModifiableModel profileModifiableModel = inspectionProfile.getModifiableModel();
final InspectionProfileEntry[] profileEntries = profileModifiableModel.getInspectionTools(null);
for (InspectionProfileEntry entry : profileEntries) {
profileModifiableModel.disableTool(entry.getShortName(), (NamedScope)null);
final InspectionToolWrapper[] profileEntries = (InspectionToolWrapper[])profileModifiableModel.getInspectionTools(null);
for (InspectionToolWrapper toolWrapper : profileEntries) {
profileModifiableModel.disableTool(toolWrapper.getShortName(), (NamedScope)null);
}
profileModifiableModel.setLocal(true);
profileModifiableModel.setModified(true);
@@ -20,9 +20,9 @@
*/
package com.intellij.profile.codeInspection.ui.actions;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.Descriptor;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.ScopeToolState;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diagnostic.Logger;
@@ -88,8 +88,8 @@ public abstract class AddScopeAction extends AnAction {
for (InspectionConfigTreeNode node : nodes) {
final Descriptor descriptor = node.getDescriptor();
if (node.getScopeName() != null || descriptor == null) continue;
final InspectionProfileEntry tool = descriptor.getTool(); //copy
final ScopeToolState scopeToolState = getSelectedProfile().addScope(tool, chosenScope,
final InspectionToolWrapper toolWrapper = descriptor.getTool(); //copy
final ScopeToolState scopeToolState = getSelectedProfile().addScope(toolWrapper, chosenScope,
getSelectedProfile().getErrorLevel(descriptor.getKey(), chosenScope),
getSelectedProfile().isToolEnabled(descriptor.getKey()));
final Descriptor addedDescriptor = new Descriptor(scopeToolState, getSelectedProfile());
@@ -4,8 +4,8 @@
package com.intellij.mock;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.ContainerUtil;
@@ -18,26 +18,27 @@ import java.util.Set;
* @author peter
*/
public class MockInspectionProfile extends InspectionProfileImpl {
private InspectionProfileEntry[] myInspectionTools = new InspectionProfileEntry[0];
private final Set<InspectionProfileEntry> myDisabledTools = new THashSet<InspectionProfileEntry>();
private InspectionToolWrapper[] myInspectionTools = new InspectionToolWrapper[0];
private final Set<InspectionToolWrapper> myDisabledTools = new THashSet<InspectionToolWrapper>();
public MockInspectionProfile() {
super("a");
}
public void setEnabled(InspectionProfileEntry tool, boolean enabled) {
public void setEnabled(@NotNull InspectionToolWrapper tool, boolean enabled) {
if (enabled) {
myDisabledTools.remove(tool);
} else {
}
else {
myDisabledTools.add(tool);
}
}
@Override
public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
final InspectionProfileEntry entry = ContainerUtil.find(myInspectionTools, new Condition<InspectionProfileEntry>() {
final InspectionToolWrapper entry = ContainerUtil.find(myInspectionTools, new Condition<InspectionToolWrapper>() {
@Override
public boolean value(final InspectionProfileEntry inspectionProfileEntry) {
public boolean value(final InspectionToolWrapper inspectionProfileEntry) {
return key.equals(HighlightDisplayKey.find(inspectionProfileEntry.getShortName()));
}
});
@@ -45,13 +46,13 @@ public class MockInspectionProfile extends InspectionProfileImpl {
return !myDisabledTools.contains(entry);
}
public void setInspectionTools(final InspectionProfileEntry... entries) {
public void setInspectionTools(final InspectionToolWrapper... entries) {
myInspectionTools = entries;
}
@Override
@NotNull
public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
return myInspectionTools;
}
}
@@ -19,7 +19,7 @@ import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
import com.intellij.codeInspection.ex.InspectionManagerEx;
import com.intellij.codeInspection.ex.InspectionTool;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
@@ -28,6 +28,7 @@ import com.intellij.openapi.util.JDOMUtil;
import junit.framework.Assert;
import org.jdom.Document;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import java.io.CharArrayReader;
import java.io.File;
@@ -57,13 +58,13 @@ expected:
}
}
Document missing = new Document((Element)expectedProblem.clone());
Document missing = new Document(expectedProblem.clone());
System.out.println("The following haven't been reported as expected: " + new String(JDOMUtil.printDocument(missing, "\n")));
failed = true;
}
for (Element reportedProblem : reportedProblems) {
Document extra = new Document((Element)reportedProblem.clone());
Document extra = new Document(reportedProblem.clone());
System.out.println("The following has been unexpectedly reported: " + new String(JDOMUtil.printDocument(extra, "\n")));
failed = true;
}
@@ -126,11 +127,11 @@ expected:
return Comparing.equal(reportedFile.getName(), expectedProblem.getChildText("file"));
}
public static void compareToolResults(InspectionTool tool, boolean checkRange, String testDir) {
public static void compareToolResults(InspectionToolWrapper toolWrapper, boolean checkRange, String testDir) {
final Element root = new Element("problems");
final Document doc = new Document(root);
tool.updateContent(); //e.g. dead code need check for reachables
tool.exportResults(root);
toolWrapper.updateContent(); //e.g. dead code need check for reachables
toolWrapper.exportResults(root);
File file = new File(testDir + "/expected.xml");
try {
@@ -143,8 +144,11 @@ expected:
}
}
public static void runTool(final InspectionTool tool, final AnalysisScope scope, final GlobalInspectionContextImpl globalContext, final InspectionManagerEx inspectionManager) {
final String shortName = tool.getShortName();
public static void runTool(@NotNull InspectionToolWrapper toolWrapper,
@NotNull final AnalysisScope scope,
@NotNull final GlobalInspectionContextImpl globalContext,
@NotNull final InspectionManagerEx inspectionManager) {
final String shortName = toolWrapper.getShortName();
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null){
HighlightDisplayKey.register(shortName);
@@ -122,7 +122,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
public static Thread ourTestThread;
private static LightProjectDescriptor ourProjectDescriptor;
@NonNls private static final String LIGHT_PROJECT_MARK = "Light project: ";
private final Map<String, InspectionTool> myAvailableInspectionTools = new THashMap<String, InspectionTool>();
private final Map<String, InspectionToolWrapper> myAvailableInspectionTools = new THashMap<String, InspectionToolWrapper>();
private static boolean ourHaveShutdownHook;
private ThreadTracker myThreadTracker;
@@ -339,7 +339,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
public static void doSetup(@NotNull LightProjectDescriptor descriptor,
@NotNull LocalInspectionTool[] localInspectionTools,
@NotNull final Map<String, InspectionTool> availableInspectionTools)
@NotNull final Map<String, InspectionToolWrapper> availableInspectionTools)
throws Exception {
assertNull("Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.", ourTestCase);
IdeaLogger.ourErrorsOccurred = null;
@@ -361,16 +361,17 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
final InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE) {
@Override
@NotNull
public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
final Collection<InspectionTool> tools = availableInspectionTools.values();
return tools.toArray(new InspectionTool[tools.size()]);
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
final Collection<InspectionToolWrapper> tools = availableInspectionTools.values();
return tools.toArray(new InspectionToolWrapper[tools.size()]);
}
@NotNull
@Override
public List<ToolsImpl> getAllEnabledInspectionTools(Project project) {
List<ToolsImpl> result = new ArrayList<ToolsImpl>();
for (InspectionProfileEntry entry : getInspectionTools(null)) {
result.add(new ToolsImpl(entry, entry.getDefaultLevel(), true));
public List<Tools> getAllEnabledInspectionTools(Project project) {
List<Tools> result = new ArrayList<Tools>();
for (InspectionToolWrapper toolWrapper : getInspectionTools(null)) {
result.add(new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true));
}
return result;
}
@@ -382,24 +383,18 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
@Override
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, PsiElement element) {
InspectionTool localInspectionTool = availableInspectionTools.get(key.toString());
return localInspectionTool != null ? localInspectionTool.getDefaultLevel() : HighlightDisplayLevel.WARNING;
InspectionToolWrapper toolWrapper = availableInspectionTools.get(key.toString());
return toolWrapper == null ? HighlightDisplayLevel.WARNING : toolWrapper.getDefaultLevel();
}
@Override
public InspectionTool getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
if (availableInspectionTools.containsKey(shortName)) {
return availableInspectionTools.get(shortName);
}
return null;
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
return availableInspectionTools.get(shortName);
}
@Override
public InspectionProfileEntry getToolById(@NotNull String id, @NotNull PsiElement element) {
if (availableInspectionTools.containsKey(id)) {
return availableInspectionTools.get(id);
}
return null;
public InspectionToolWrapper getToolById(@NotNull String id, @NotNull PsiElement element) {
return availableInspectionTools.get(id);
}
};
final InspectionProfileManager inspectionProfileManager = InspectionProfileManager.getInstance();
@@ -467,22 +462,15 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
}
protected void enableInspectionTool(@NotNull InspectionToolWrapper wrapper) {
enableInspectionTool(myAvailableInspectionTools, wrapper);
}
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
if (tool instanceof InspectionTool) {
enableInspectionTool(myAvailableInspectionTools, (InspectionTool)tool);
}
else if (tool instanceof LocalInspectionTool) {
enableInspectionTool(myAvailableInspectionTools, new LocalInspectionToolWrapper((LocalInspectionTool)tool));
}
else if (tool instanceof GlobalInspectionTool) {
enableInspectionTool(myAvailableInspectionTools, new GlobalInspectionToolWrapper((GlobalInspectionTool)tool));
}
else {
throw new IllegalArgumentException("Unexpected inspection type: " + tool);
}
assert !(tool instanceof InspectionToolWrapper) : tool;
enableInspectionTool(myAvailableInspectionTools, InspectionToolRegistrar.wrapTool(tool));
}
private static void enableInspectionTool(@NotNull Map<String, InspectionTool> availableLocalTools, @NotNull InspectionTool wrapper) {
private static void enableInspectionTool(@NotNull Map<String, InspectionToolWrapper> availableLocalTools, @NotNull InspectionToolWrapper wrapper) {
final String shortName = wrapper.getShortName();
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
@@ -147,7 +147,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
private boolean myEmptyLookup;
private InspectionProfileEntry[] myInspections;
private final Map<String, InspectionTool> myAvailableTools = new THashMap<String, InspectionTool>();
private final Map<String, InspectionToolWrapper> myAvailableTools = new THashMap<String, InspectionToolWrapper>();
private final TempDirTestFixture myTempDirFixture;
protected final IdeaProjectTestFixture myProjectFixture;
@@ -255,7 +255,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Override
public void enableInspections(InspectionProfileEntry... inspections) {
public void enableInspections(@NotNull InspectionProfileEntry... inspections) {
myInspections = inspections;
if (isInitialized()) {
configureInspections(myInspections);
@@ -267,7 +267,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Override
public void enableInspections(final Class<? extends LocalInspectionTool>... inspections) {
public void enableInspections(@NotNull final Class<? extends LocalInspectionTool>... inspections) {
enableInspections(Arrays.asList(inspections));
}
@@ -287,9 +287,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Override
public void disableInspections(InspectionProfileEntry... inspections) {
public void disableInspections(@NotNull InspectionProfileEntry... inspections) {
myAvailableTools.clear();
final ArrayList<InspectionProfileEntry> tools = new ArrayList<InspectionProfileEntry>(Arrays.asList(myInspections));
List<InspectionProfileEntry> tools = new ArrayList<InspectionProfileEntry>(Arrays.asList(myInspections));
for (Iterator<InspectionProfileEntry> i = tools.iterator(); i.hasNext();) {
final InspectionProfileEntry tool = i.next();
for (InspectionProfileEntry toRemove : inspections) {
@@ -448,7 +448,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Override
public void testInspection(String testDir, @NotNull InspectionToolWrapper toolWrapper) {
public void testInspection(@NotNull String testDir, @NotNull InspectionToolWrapper toolWrapper) {
VirtualFile sourceDir = copyDirectoryToProject(new File(testDir, "src").getPath(), "src");
AnalysisScope scope = new AnalysisScope(getPsiManager().findDirectory(sourceDir));
@@ -464,15 +464,15 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
public static GlobalInspectionContextImpl createGlobalContextForTool(AnalysisScope scope,
final Project project,
final InspectionManagerEx inspectionManager,
final InspectionTool... tools) {
final InspectionToolWrapper ... toolWrappers) {
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", tools);
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", toolWrappers);
GlobalInspectionContextImpl globalContext = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
@Override
protected List<ToolsImpl> getUsedTools() {
protected List<Tools> getUsedTools() {
try {
InspectionProfileImpl.INIT_INSPECTIONS = true;
for (InspectionTool tool : tools) {
for (InspectionToolWrapper tool : toolWrappers) {
profile.enableTool(tool.getShortName());
}
return profile.getAllEnabledInspectionTools(project);
@@ -1140,7 +1140,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
super.tearDown();
}
private void enableInspectionTool(InspectionProfileEntry tool) {
private void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
assert !(tool instanceof InspectionToolWrapper) : tool;
InspectionToolWrapper wrapper = InspectionToolRegistrar.wrapTool(tool);
final String shortName = tool.getShortName();
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
@@ -1152,7 +1153,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
myAvailableTools.put(shortName, wrapper);
}
private void configureInspections(final InspectionProfileEntry[] tools) {
private void configureInspections(@NotNull InspectionProfileEntry[] tools) {
for (InspectionProfileEntry tool : tools) {
enableInspectionTool(tool);
}
@@ -1167,13 +1168,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@Override
@NotNull
public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
final Collection<InspectionTool> tools = myAvailableTools.values();
return tools.toArray(new InspectionTool[tools.size()]);
public InspectionToolWrapper[] getInspectionTools(PsiElement element) {
final Collection<InspectionToolWrapper> tools = myAvailableTools.values();
return tools.toArray(new InspectionToolWrapper[tools.size()]);
}
@Override
public InspectionProfileEntry getToolById(@NotNull String id, @NotNull PsiElement element) {
public InspectionToolWrapper getToolById(@NotNull String id, @NotNull PsiElement element) {
if (myAvailableTools.containsKey(id)) {
return myAvailableTools.get(id);
}
@@ -1181,21 +1182,23 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return super.getToolById(id, element);
}
@NotNull
@Override
public List<ToolsImpl> getAllEnabledInspectionTools(Project project) {
List<ToolsImpl> result = new ArrayList<ToolsImpl>();
for (InspectionProfileEntry entry : getInspectionTools(null)) {
result.add(new ToolsImpl(entry, entry.getDefaultLevel(), true));
public List<Tools> getAllEnabledInspectionTools(Project project) {
List<Tools> result = new ArrayList<Tools>();
for (InspectionToolWrapper toolWrapper : getInspectionTools(null)) {
result.add(new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true));
}
return result;
}
@Override
public boolean isToolEnabled(HighlightDisplayKey key, PsiElement element) {
return key != null && key.toString() != null && myAvailableTools.containsKey(key.toString());
}
@Override
public InspectionProfileEntry getInspectionTool(@NotNull String shortName) {
public InspectionToolWrapper getInspectionTool(@NotNull String shortName) {
return myAvailableTools.get(shortName);
}
@@ -1206,7 +1209,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Override
public InspectionProfileEntry getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
return myAvailableTools.get(shortName);
}
};
@@ -1337,6 +1340,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
private PsiFile configureInner(@NotNull final VirtualFile copy, final SelectionAndCaretMarkupLoader loader) {
assertInitialized();
new WriteCommandAction.Simple(getProject()) {
@Override
public void run() {
try {
copy.setBinaryContent(loader.newFileText.getBytes(copy.getCharset()), 0, 0, null);
@@ -1813,6 +1817,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return myText;
}
@Override
public int compareTo(Border o) {
return getOffset() < o.getOffset() ? 1 : -1;
}
@@ -1862,10 +1867,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
assertEquals(expectedContent, actual);
}
@Override
public void testFoldingWithCollapseStatus(final String verificationFileName) {
testFoldingRegions(verificationFileName, true);
}
@Override
public void testFolding(final String verificationFileName) {
testFoldingRegions(verificationFileName, false);
}
@@ -1908,6 +1915,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
}
@Override
public LookupImpl getLookup() {
return (LookupImpl)LookupManager.getActiveLookup(myEditor);
}
@@ -17,7 +17,7 @@
package com.intellij.testFramework.fixtures.impl;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ex.InspectionTool;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.idea.IdeaTestApplication;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
@@ -49,7 +49,7 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe
super.setUp();
IdeaTestApplication application = LightPlatformTestCase.initApplication();
LightPlatformTestCase.doSetup(myProjectDescriptor, LocalInspectionTool.EMPTY_ARRAY, new THashMap<String, InspectionTool>());
LightPlatformTestCase.doSetup(myProjectDescriptor, LocalInspectionTool.EMPTY_ARRAY, new THashMap<String, InspectionToolWrapper>());
InjectedLanguageManagerImpl.pushInjectors(getProject());
storeSettings();
application.setDataProvider(new TestDataProvider(getProject()));
@@ -16,6 +16,7 @@
package com.intellij.spellchecker.ui;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.intention.IntentionManager;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
@@ -24,17 +25,15 @@ import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.spellchecker.inspections.SpellCheckingInspection;
import com.intellij.ui.SimpleEditorCustomization;
import com.intellij.util.Function;
import com.intellij.util.containers.WeakHashMap;
import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
/**
* Allows to enforce editors to use/don't use spell checking ignoring user-defined spelling inspection settings.
@@ -49,7 +48,7 @@ public class SpellCheckingEditorCustomization extends SimpleEditorCustomization
public static final SpellCheckingEditorCustomization ENABLED = new SpellCheckingEditorCustomization(true);
public static final SpellCheckingEditorCustomization DISABLED = new SpellCheckingEditorCustomization(false);
private static final Set<LocalInspectionToolWrapper> SPELL_CHECK_TOOLS = new HashSet<LocalInspectionToolWrapper>();
private static final Map<String, LocalInspectionToolWrapper> SPELL_CHECK_TOOLS = new HashMap<String, LocalInspectionToolWrapper>();
private static final boolean READY = init();
@NotNull
@@ -70,7 +69,7 @@ public class SpellCheckingEditorCustomization extends SimpleEditorCustomization
for (Class<LocalInspectionTool> inspectionClass : inspectionClasses) {
try {
LocalInspectionTool tool = inspectionClass.newInstance();
SPELL_CHECK_TOOLS.add(new LocalInspectionToolWrapper(tool));
SPELL_CHECK_TOOLS.put(tool.getShortName(), new LocalInspectionToolWrapper(tool));
}
catch (Throwable e) {
return false;
@@ -152,29 +151,9 @@ public class SpellCheckingEditorCustomization extends SimpleEditorCustomization
myDelegate = delegate;
}
@NotNull
@Override
public List<LocalInspectionToolWrapper> getHighlightingLocalInspectionTools(PsiElement element) {
Set<LocalInspectionToolWrapper> result = new THashSet<LocalInspectionToolWrapper>(myDelegate.getHighlightingLocalInspectionTools(element), new TObjectHashingStrategy<LocalInspectionToolWrapper>() {
@Override
public int computeHashCode(LocalInspectionToolWrapper object) {
return object.getShortName().hashCode();
}
@Override
public boolean equals(LocalInspectionToolWrapper o1, LocalInspectionToolWrapper o2) {
return o1.getShortName().equals(o2.getShortName());
}
});
if (myUseSpellCheck) {
result.removeAll(SPELL_CHECK_TOOLS);
result.addAll(SPELL_CHECK_TOOLS);
}
else {
result.removeAll(SPELL_CHECK_TOOLS);
}
return new ArrayList<LocalInspectionToolWrapper>(result);
public boolean isToolEnabled(HighlightDisplayKey key) {
return myDelegate.isToolEnabled(key) && SPELL_CHECK_TOOLS.containsKey(key.toString()) && myUseSpellCheck;
}
public void setUseSpellCheck(boolean useSpellCheck) {
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.Disposable;
@@ -62,21 +63,25 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
private final EventDispatcher<DomHighlightingListener> myDispatcher = EventDispatcher.create(DomHighlightingListener.class);
private static final DomElementsProblemsHolder EMPTY_PROBLEMS_HOLDER = new DomElementsProblemsHolder() {
@Override
@NotNull
public List<DomElementProblemDescriptor> getProblems(DomElement domElement) {
return Collections.emptyList();
}
@Override
public List<DomElementProblemDescriptor> getProblems(final DomElement domElement, boolean includeXmlProblems) {
return Collections.emptyList();
}
@Override
public List<DomElementProblemDescriptor> getProblems(final DomElement domElement,
final boolean includeXmlProblems,
final boolean withChildren) {
return Collections.emptyList();
}
@Override
public List<DomElementProblemDescriptor> getProblems(DomElement domElement,
final boolean includeXmlProblems,
final boolean withChildren,
@@ -84,18 +89,22 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
return Collections.emptyList();
}
@Override
public List<DomElementProblemDescriptor> getProblems(DomElement domElement, final boolean withChildren, HighlightSeverity minSeverity) {
return Collections.emptyList();
}
@Override
public List<DomElementProblemDescriptor> getAllProblems() {
return Collections.emptyList();
}
@Override
public List<DomElementProblemDescriptor> getAllProblems(@NotNull DomElementsInspection inspection) {
return Collections.emptyList();
}
@Override
public boolean isInspectionCompleted(@NotNull final DomElementsInspection inspectionClass) {
return false;
}
@@ -108,15 +117,18 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
public DomElementAnnotationsManagerImpl(Project project) {
myProject = project;
myModificationTracker = new ModificationTracker() {
@Override
public long getModificationCount() {
return myModificationCount;
}
};
final ProfileChangeAdapter profileChangeAdapter = new ProfileChangeAdapter() {
@Override
public void profileActivated(@NotNull Profile oldProfile, Profile profile) {
dropAnnotationsCache();
}
@Override
public void profileChanged(Profile profile) {
dropAnnotationsCache();
}
@@ -125,12 +137,14 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
final InspectionProfileManager inspectionProfileManager = InspectionProfileManager.getInstance();
inspectionProfileManager.addProfileChangeListener(profileChangeAdapter, project);
Disposer.register(project, new Disposable() {
@Override
public void dispose() {
inspectionProfileManager.removeProfileChangeListener(profileChangeAdapter);
}
});
}
@Override
public void dropAnnotationsCache() {
myModificationCount++;
}
@@ -156,6 +170,7 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
holder = new DomElementsProblemsHolderImpl(element);
rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(new CachedValueProvider<Boolean>() {
@Override
public Result<Boolean> compute() {
return new Result<Boolean>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myModificationTracker, ProjectRootManager.getInstance(myProject));
}
@@ -183,6 +198,7 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
return cachedValue == null || !cachedValue.hasUpToDateValue();
}
@Override
@NotNull
public DomElementsProblemsHolder getProblemHolder(DomElement element) {
if (element == null || !element.isValid()) return EMPTY_PROBLEMS_HOLDER;
@@ -200,6 +216,7 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
}
}
@Override
@NotNull
public DomElementsProblemsHolder getCachedProblemHolder(DomElement element) {
return getProblemHolder(element);
@@ -212,10 +229,12 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
}
}
@Override
public List<ProblemDescriptor> createProblemDescriptors(final InspectionManager manager, DomElementProblemDescriptor problemDescriptor) {
return ContainerUtil.createMaybeSingletonList(DomElementsHighlightingUtil.createProblemDescriptors(manager, problemDescriptor));
}
@Override
public boolean isHighlightingFinished(final DomElement[] domElements) {
for (final DomElement domElement : domElements) {
if (getHighlightStatus(domElement) != DomHighlightStatus.INSPECTIONS_FINISHED) {
@@ -225,14 +244,17 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
return true;
}
@Override
public void addHighlightingListener(DomHighlightingListener listener, Disposable parentDisposable) {
myDispatcher.addListener(listener, parentDisposable);
}
@Override
public DomHighlightingHelper getHighlightingHelper() {
return DomHighlightingHelperImpl.INSTANCE;
}
@Override
@NotNull
public <T extends DomElement> List<DomElementProblemDescriptor> checkFileElement(@NotNull final DomFileElement<T> domFileElement,
@NotNull final DomElementsInspection<T> inspection,
@@ -251,9 +273,9 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
Class rootType = fileElement.getRootElementClass();
final InspectionProfile profile = getInspectionProfile(fileElement);
final List<DomElementsInspection> inspections = new SmartList<DomElementsInspection>();
for (final InspectionProfileEntry profileEntry : profile.getInspectionTools(fileElement.getFile())) {
if (!enabledOnly || profile.isToolEnabled(HighlightDisplayKey.find(profileEntry.getShortName()), fileElement.getFile())) {
ContainerUtil.addIfNotNull(getSuitableInspection(profileEntry, rootType), inspections);
for (final InspectionToolWrapper toolWrapper : (InspectionToolWrapper[])profile.getInspectionTools(fileElement.getFile())) {
if (!enabledOnly || profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), fileElement.getFile())) {
ContainerUtil.addIfNotNull(getSuitableInspection(toolWrapper, rootType), inspections);
}
}
return inspections;
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionToolProvider;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.ide.ui.search.SearchableOptionsRegistrar;
import com.intellij.lang.annotation.Annotation;
import com.intellij.mock.MockInspectionProfile;
@@ -177,7 +178,7 @@ public class DomHighlightingLiteTest extends DomTestCase {
public void testNoMockInspection() throws Throwable {
myElement.setFileDescription(new MyNonHighlightingDomFileDescription());
myInspectionProfile.setInspectionTools(new MyDomElementsInspection());
myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(new MyDomElementsInspection()));
assertNull(myAnnotationsManager.getMockInspection(myElement));
}
@@ -238,7 +239,7 @@ public class DomHighlightingLiteTest extends DomTestCase {
}
};
HighlightDisplayKey.register(inspection.getShortName());
myInspectionProfile.setInspectionTools(inspection);
myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(inspection));
myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
assertEquals(DomHighlightStatus.ANNOTATORS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
@@ -263,8 +264,9 @@ public class DomHighlightingLiteTest extends DomTestCase {
}
};
HighlightDisplayKey.register(inspection.getShortName());
myInspectionProfile.setInspectionTools(inspection);
myInspectionProfile.setEnabled(inspection, false);
LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(inspection);
myInspectionProfile.setInspectionTools(toolWrapper);
myInspectionProfile.setEnabled(toolWrapper, false);
myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));