mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
a number of inspection tools refactorings:
to reduce confusion, InspectionToolWrapper no longer extends InspectionTool; InspectionToolWrapper and InspectionProfileManager moved to analysis; InspectionNode decoupled from InspectionTool - the former stored in the InspectionToolPresentation and the mapping InspectionToolWrapper->InspectionToolPresentation is stored in GlobalInspectionContext
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ public class JavaAwareInspectionProfileCoverter extends InspectionProfileConvert
|
||||
super.fillErrorLevels(profile);
|
||||
|
||||
//javadoc attributes
|
||||
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(JavaDocLocalInspection.SHORT_NAME, null);
|
||||
final InspectionToolWrapper toolWrapper = profile.getInspectionTool(JavaDocLocalInspection.SHORT_NAME, null);
|
||||
JavaDocLocalInspection inspection = (JavaDocLocalInspection)toolWrapper.getTool();
|
||||
inspection.myAdditionalJavadocTags = myAdditionalJavadocTags;
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.impl.RemoveSuppressWarningAction;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.RefClass;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefJavaVisitor;
|
||||
import com.intellij.codeInspection.reference.RefManagerImpl;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -116,7 +114,7 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
return checkElement(psiClass, manager, project);
|
||||
}
|
||||
|
||||
public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull InspectionManager manager, @NotNull Project project) {
|
||||
public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull final InspectionManager manager, @NotNull Project project) {
|
||||
final Map<PsiElement, Collection<String>> suppressedScopes = new THashMap<PsiElement, Collection<String>>();
|
||||
psiElement.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override public void visitModifierList(PsiModifierList list) {
|
||||
@@ -193,7 +191,7 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
|
||||
final AnalysisScope scope = new AnalysisScope(psiElement.getContainingFile());
|
||||
final InspectionManagerEx inspectionManagerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
|
||||
GlobalInspectionContextImpl globalContext = inspectionManagerEx.createNewGlobalContext(false);
|
||||
final GlobalInspectionContextImpl globalContext = inspectionManagerEx.createNewGlobalContext(false);
|
||||
globalContext.setCurrentScope(scope);
|
||||
final RefManagerImpl refManager = (RefManagerImpl)globalContext.getRefManager();
|
||||
refManager.inspectionReadActionStarted();
|
||||
@@ -204,19 +202,32 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
String toolId = toolWrapper instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)toolWrapper).getTool().getID() : toolWrapper.getShortName();
|
||||
toolWrapper.initialize(globalContext);
|
||||
Collection<CommonProblemDescriptor> descriptors;
|
||||
final InspectionToolPresentation presentation = globalContext.getPresentation(toolWrapper);
|
||||
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();
|
||||
List<ProblemDescriptor> results = local.getTool().processFile(psiElement.getContainingFile(), manager);
|
||||
InspectionToolPresentation toolPresentation = globalContext.getPresentation(local);
|
||||
LocalDescriptorsUtil.addProblemDescriptors(results, toolPresentation, false, globalContext, local.getTool());
|
||||
descriptors = presentation.getProblemDescriptors();
|
||||
}
|
||||
else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
|
||||
GlobalInspectionToolWrapper global = (GlobalInspectionToolWrapper)toolWrapper;
|
||||
if (global.getTool().isGraphNeeded()) {
|
||||
final GlobalInspectionToolWrapper global = (GlobalInspectionToolWrapper)toolWrapper;
|
||||
GlobalInspectionTool globalTool = global.getTool();
|
||||
if (globalTool.isGraphNeeded()) {
|
||||
refManager.findAllDeclarations();
|
||||
}
|
||||
global.processFile(scope, manager, globalContext, false);
|
||||
descriptors = global.getProblemDescriptors();
|
||||
final InspectionToolPresentation toolPresentation = globalContext.getPresentation(global);
|
||||
globalContext.getRefManager().iterate(new RefVisitor() {
|
||||
@Override public void visitElement(@NotNull RefEntity refEntity) {
|
||||
CommonProblemDescriptor[]
|
||||
descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, toolPresentation);
|
||||
if (descriptors1 != null) {
|
||||
toolPresentation.addProblemElement(refEntity, false, descriptors1);
|
||||
}
|
||||
}
|
||||
});
|
||||
descriptors = presentation.getProblemDescriptors();
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
@@ -285,12 +296,12 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
return result.toArray(new ProblemDescriptor[result.size()]);
|
||||
}
|
||||
|
||||
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
|
||||
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, @NotNull InspectionManager manager) {
|
||||
ModifiableModel model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel();
|
||||
InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile)model);
|
||||
profile.init(manager.getProject());
|
||||
|
||||
return (InspectionToolWrapper[])profile.getInspectionTools(psiElement);
|
||||
return profile.getInspectionTools(psiElement);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import com.intellij.codeInspection.HTMLJavaHTMLComposer;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.DescriptorComposer;
|
||||
import com.intellij.codeInspection.ex.HTMLComposerImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.codeInspection.ui.RefElementNode;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -41,11 +41,11 @@ import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class DeadHTMLComposer extends HTMLComposerImpl {
|
||||
private final InspectionTool myTool;
|
||||
private final InspectionToolPresentation myToolPresentation;
|
||||
private final HTMLJavaHTMLComposer myComposer;
|
||||
|
||||
public DeadHTMLComposer(@NotNull InspectionTool tool) {
|
||||
myTool = tool;
|
||||
public DeadHTMLComposer(@NotNull InspectionToolPresentation presentation) {
|
||||
myToolPresentation = presentation;
|
||||
myComposer = getExtension(HTMLJavaHTMLComposer.COMPOSER);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DeadHTMLComposer extends HTMLComposerImpl {
|
||||
|
||||
//noinspection HardCodedStringLiteral
|
||||
buf.append("<br><br>");
|
||||
appendResolution(buf, refElement, DescriptorComposer.quickFixTexts(refElement, myTool));
|
||||
appendResolution(buf, refElement, DescriptorComposer.quickFixTexts(refElement, myToolPresentation));
|
||||
refElement.accept(new RefJavaVisitor() {
|
||||
@Override public void visitClass(@NotNull RefClass aClass) {
|
||||
appendClassInstantiations(buf, aClass);
|
||||
@@ -339,7 +339,7 @@ public class DeadHTMLComposer extends HTMLComposerImpl {
|
||||
}
|
||||
|
||||
private void appendCallesList(RefElement element, StringBuffer buf, Set<RefElement> mentionedElements, boolean appendCallees){
|
||||
final Set<RefElement> possibleChildren = getPossibleChildren(new RefElementNode(element, myTool), element);
|
||||
final Set<RefElement> possibleChildren = getPossibleChildren(new RefElementNode(element, myToolPresentation), element);
|
||||
if (!possibleChildren.isEmpty()) {
|
||||
if (appendCallees){
|
||||
appendHeading(buf, InspectionsBundle.message("inspection.export.results.callees"));
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.deadCode;
|
||||
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionNode;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.codeInspection.util.RefFilter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DummyEntryPointsPresentation extends UnusedDeclarationPresentation {
|
||||
private static final RefEntryPointFilter myFilter = new RefEntryPointFilter();
|
||||
private QuickFixAction[] myQuickFixActions;
|
||||
|
||||
public DummyEntryPointsPresentation(UnusedDeclarationInspection inspection, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(toolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefFilter getFilter() {
|
||||
return myFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements) {
|
||||
if (myQuickFixActions == null) {
|
||||
myQuickFixActions = new QuickFixAction[]{new MoveEntriesToSuspicious(getToolWrapper())};
|
||||
}
|
||||
return myQuickFixActions;
|
||||
}
|
||||
|
||||
private class MoveEntriesToSuspicious extends QuickFixAction {
|
||||
private MoveEntriesToSuspicious(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(InspectionsBundle.message("inspection.dead.code.remove.from.entry.point.quickfix"), null, null, toolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(RefElement[] refElements) {
|
||||
final EntryPointsManager entryPointsManager =
|
||||
getContext().getExtension(GlobalJavaInspectionContextImpl.CONTEXT).getEntryPointsManager(getContext().getRefManager());
|
||||
for (RefElement refElement : refElements) {
|
||||
entryPointsManager.removeEntryPoint(refElement);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionNode createToolNode(@NotNull GlobalInspectionContextImpl context, @NotNull InspectionNode node,
|
||||
@NotNull InspectionRVContentProvider provider,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
boolean showStructure) {
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HTMLComposerImpl getComposer() {
|
||||
return new DeadHTMLComposer(this);
|
||||
}
|
||||
}
|
||||
@@ -19,36 +19,22 @@ import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.util.RefFilter;
|
||||
import org.jdom.Element;
|
||||
import com.intellij.codeInspection.ex.InspectionPresentationProvider;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.JobDescriptor;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class DummyEntryPointsTool extends FilteringInspectionTool {
|
||||
private static final RefEntryPointFilter myFilter = new RefEntryPointFilter();
|
||||
private QuickFixAction[] myQuickFixActions;
|
||||
|
||||
public DummyEntryPointsTool(@NotNull UnusedDeclarationInspection owner) {
|
||||
initialize(owner.getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefFilter getFilter() {
|
||||
return myFilter;
|
||||
public class DummyEntryPointsTool extends UnusedDeclarationInspection implements InspectionPresentationProvider {
|
||||
public DummyEntryPointsTool() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull AnalysisScope scope, @NotNull final InspectionManager manager) {}
|
||||
|
||||
@Override
|
||||
public void exportResults(@NotNull Element parentNode, @NotNull RefEntity refEntity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext globalInspectionContext) {
|
||||
@@ -73,34 +59,9 @@ public class DummyEntryPointsTool extends FilteringInspectionTool {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HTMLComposerImpl getComposer() {
|
||||
return new DeadHTMLComposer(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements) {
|
||||
if (myQuickFixActions == null) {
|
||||
myQuickFixActions = new QuickFixAction[]{new MoveEntriesToSuspicious()};
|
||||
}
|
||||
return myQuickFixActions;
|
||||
}
|
||||
|
||||
private class MoveEntriesToSuspicious extends QuickFixAction {
|
||||
private MoveEntriesToSuspicious() {
|
||||
super(InspectionsBundle.message("inspection.dead.code.remove.from.entry.point.quickfix"), null, null, DummyEntryPointsTool.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(RefElement[] refElements) {
|
||||
final EntryPointsManager entryPointsManager =
|
||||
getContext().getExtension(GlobalJavaInspectionContextImpl.CONTEXT).getEntryPointsManager(getContext().getRefManager());
|
||||
for (RefElement refElement : refElements) {
|
||||
entryPointsManager.removeEntryPoint(refElement);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public InspectionToolPresentation createPresentation(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
return new DummyEntryPointsPresentation(this, toolWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,19 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.deadCode;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.util.RefFilter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RefUnreachableFilter extends RefFilter {
|
||||
@NotNull
|
||||
protected InspectionTool myTool;
|
||||
protected UnusedDeclarationInspection myTool;
|
||||
@NotNull protected final GlobalInspectionContextImpl myContext;
|
||||
|
||||
public RefUnreachableFilter(@NotNull InspectionTool tool) {
|
||||
public RefUnreachableFilter(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContextImpl context) {
|
||||
myTool = tool;
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +44,7 @@ public class RefUnreachableFilter extends RefFilter {
|
||||
if (refElement instanceof RefParameter) return 0;
|
||||
if (refElement.isSyntheticJSP()) return 0;
|
||||
if (!(refElement instanceof RefMethod || refElement instanceof RefClass || refElement instanceof RefField)) return 0;
|
||||
if (!myTool.getContext().isToCheckMember(refElement, myTool)) return 0;
|
||||
if (!myContext.isToCheckMember(refElement, myTool)) return 0;
|
||||
return ((RefElementImpl)refElement).isSuspicious() ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.deadCode;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UnreferencedFilter extends RefUnreachableFilter {
|
||||
public UnreferencedFilter(@NotNull InspectionTool tool) {
|
||||
super(tool);
|
||||
public UnreferencedFilter(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContextImpl context) {
|
||||
super(tool, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +39,7 @@ public class UnreferencedFilter extends RefUnreachableFilter {
|
||||
if (refElement.isEntry() || !((RefElementImpl)refElement).isSuspicious() || refElement.isSyntheticJSP()) return 0;
|
||||
|
||||
if (!(refElement instanceof RefMethod || refElement instanceof RefClass || refElement instanceof RefField)) return 0;
|
||||
if (!myTool.getContext().isToCheckMember(refElement, myTool)) return 0;
|
||||
if (!myContext.isToCheckMember(refElement, myTool)) return 0;
|
||||
|
||||
if (refElement instanceof RefField) {
|
||||
RefField refField = (RefField) refElement;
|
||||
|
||||
+46
-354
@@ -31,27 +31,17 @@ import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtilBase;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.EntryPointsNode;
|
||||
import com.intellij.codeInspection.ui.InspectionNode;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.util.RefFilter;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiClassImplUtil;
|
||||
@@ -59,15 +49,9 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor;
|
||||
import com.intellij.psi.search.PsiSearchHelper;
|
||||
import com.intellij.psi.util.PsiMethodUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.refactoring.safeDelete.SafeDeleteHandler;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.SeparatorFactory;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -77,40 +61,26 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
public class UnusedDeclarationInspection extends InspectionTool implements InspectionPresentationProvider {
|
||||
public boolean ADD_MAINS_TO_ENTRIES = true;
|
||||
|
||||
public boolean ADD_APPLET_TO_ENTRIES = true;
|
||||
public boolean ADD_SERVLET_TO_ENTRIES = true;
|
||||
public boolean ADD_NONJAVA_TO_ENTRIES = true;
|
||||
|
||||
private HashSet<RefElement> myProcessedSuspicious = null;
|
||||
private Set<RefElement> myProcessedSuspicious = null;
|
||||
private int myPhase;
|
||||
private final QuickFixAction[] myQuickFixActions;
|
||||
public static final String DISPLAY_NAME = InspectionsBundle.message("inspection.dead.code.display.name");
|
||||
private WeakUnreferencedFilter myFilter;
|
||||
private DeadHTMLComposer myComposer;
|
||||
@NonNls public static final String SHORT_NAME = "UnusedDeclaration";
|
||||
@NonNls private static final String ALTERNATIVE_ID = "unused";
|
||||
|
||||
private static final String COMMENT_OUT_QUICK_FIX = InspectionsBundle.message("inspection.dead.code.comment.quickfix");
|
||||
private static final String DELETE_QUICK_FIX = InspectionsBundle.message("inspection.dead.code.safe.delete.quickfix");
|
||||
|
||||
@NonNls private static final String DELETE = "delete";
|
||||
@NonNls private static final String COMMENT = "comment";
|
||||
@NonNls private static final String [] HINTS = {COMMENT, DELETE};
|
||||
|
||||
public final EntryPoint[] myExtensions;
|
||||
private static final Logger LOG = Logger.getInstance("#" + UnusedDeclarationInspection.class.getName());
|
||||
|
||||
public UnusedDeclarationInspection() {
|
||||
|
||||
myQuickFixActions = new QuickFixAction[]{new PermanentDeleteAction(), new CommentOutBin(), new MoveToEntries()};
|
||||
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL);
|
||||
final EntryPoint[] deadCodeAddins = new EntryPoint[point.getExtensions().length];
|
||||
EntryPoint[] extensions = point.getExtensions();
|
||||
@@ -132,10 +102,8 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
myExtensions = deadCodeAddins;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull final GlobalInspectionContextImpl context) {
|
||||
super.initialize(context);
|
||||
((EntryPointsManagerImpl)getEntryPointsManager()).setAddNonJavaEntries(ADD_NONJAVA_TO_ENTRIES);
|
||||
private GlobalInspectionContextImpl getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
private class OptionsPanel extends JPanel {
|
||||
@@ -369,8 +337,9 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
|
||||
getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override public void visitElement(@NotNull final RefEntity refEntity) {
|
||||
getContext().getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override
|
||||
public void visitElement(@NotNull final RefEntity refEntity) {
|
||||
if (refEntity instanceof RefJavaElement) {
|
||||
final RefElementImpl refElement = (RefElementImpl)refEntity;
|
||||
if (!refElement.isSuspicious()) return;
|
||||
@@ -387,13 +356,15 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
}
|
||||
|
||||
refElement.accept(new RefJavaVisitor() {
|
||||
@Override public void visitMethod(@NotNull RefMethod method) {
|
||||
@Override
|
||||
public void visitMethod(@NotNull RefMethod method) {
|
||||
if (isAddMainsEnabled() && method.isAppMain()) {
|
||||
getEntryPointsManager().addEntryPoint(method, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitClass(@NotNull RefClass aClass) {
|
||||
@Override
|
||||
public void visitClass(@NotNull RefClass aClass) {
|
||||
if (isAddAppletEnabled() && aClass.isApplet() ||
|
||||
isAddServletEnabled() && aClass.isServlet()) {
|
||||
getEntryPointsManager().addEntryPoint(aClass, false);
|
||||
@@ -406,19 +377,20 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
|
||||
if (isAddNonJavaUsedEnabled()) {
|
||||
checkForReachables();
|
||||
final StrictUnreferencedFilter strictUnreferencedFilter = new StrictUnreferencedFilter(this, myContext);
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final RefFilter filter = new StrictUnreferencedFilter(UnusedDeclarationInspection.this);
|
||||
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(getRefManager().getProject());
|
||||
getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override public void visitElement(@NotNull final RefEntity refEntity) {
|
||||
if (refEntity instanceof RefClass && filter.accepts((RefClass)refEntity)) {
|
||||
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(getContext().getRefManager().getProject());
|
||||
getContext().getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override
|
||||
public void visitElement(@NotNull final RefEntity refEntity) {
|
||||
if (refEntity instanceof RefClass && strictUnreferencedFilter.accepts((RefClass)refEntity)) {
|
||||
findExternalClassReferences((RefClass)refEntity);
|
||||
}
|
||||
else if (refEntity instanceof RefMethod) {
|
||||
RefMethod refMethod = (RefMethod)refEntity;
|
||||
if (refMethod.isConstructor() && filter.accepts(refMethod)) {
|
||||
if (refMethod.isConstructor() && strictUnreferencedFilter.accepts(refMethod)) {
|
||||
findExternalClassReferences(refMethod.getOwnerClass());
|
||||
}
|
||||
}
|
||||
@@ -514,9 +486,10 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static class StrictUnreferencedFilter extends UnreferencedFilter {
|
||||
private StrictUnreferencedFilter(@NotNull InspectionTool tool) {
|
||||
super(tool);
|
||||
private StrictUnreferencedFilter(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContextImpl context) {
|
||||
super(tool, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -527,34 +500,22 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class WeakUnreferencedFilter extends UnreferencedFilter {
|
||||
private WeakUnreferencedFilter(@NotNull InspectionTool tool) {
|
||||
super(tool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementProblemCount(final RefJavaElement refElement) {
|
||||
final int problemCount = super.getElementProblemCount(refElement);
|
||||
if (problemCount > - 1) return problemCount;
|
||||
if (!((RefElementImpl)refElement).hasSuspiciousCallers() || ((RefJavaElementImpl)refElement).isSuspiciousRecursive()) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager) {
|
||||
checkForReachables();
|
||||
final RefFilter filter = myPhase == 1 ? new StrictUnreferencedFilter(this) : new RefUnreachableFilter(this);
|
||||
final RefFilter filter = myPhase == 1 ? new StrictUnreferencedFilter(this, getContext()) : new RefUnreachableFilter(this, getContext());
|
||||
final boolean[] requestAdded = {false};
|
||||
|
||||
getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override public void visitElement(@NotNull RefEntity refEntity) {
|
||||
getContext().getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override
|
||||
public void visitElement(@NotNull RefEntity refEntity) {
|
||||
if (!(refEntity instanceof RefJavaElement)) return;
|
||||
if (refEntity instanceof RefClass && ((RefClass)refEntity).isAnonymous()) return;
|
||||
RefJavaElement refElement= (RefJavaElement)refEntity;
|
||||
RefJavaElement refElement = (RefJavaElement)refEntity;
|
||||
if (filter.accepts(refElement) && !myProcessedSuspicious.contains(refElement)) {
|
||||
refEntity.accept(new RefJavaVisitor() {
|
||||
@Override public void visitField(@NotNull final RefField refField) {
|
||||
@Override
|
||||
public void visitField(@NotNull final RefField refField) {
|
||||
myProcessedSuspicious.add(refField);
|
||||
PsiField psiField = refField.getElement();
|
||||
if (isSerializationImplicitlyUsedField(psiField)) {
|
||||
@@ -572,7 +533,8 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitMethod(@NotNull final RefMethod refMethod) {
|
||||
@Override
|
||||
public void visitMethod(@NotNull final RefMethod refMethod) {
|
||||
myProcessedSuspicious.add(refMethod);
|
||||
if (refMethod instanceof RefImplicitConstructor) {
|
||||
visitClass(refMethod.getOwnerClass());
|
||||
@@ -593,7 +555,8 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitClass(@NotNull final RefClass refClass) {
|
||||
@Override
|
||||
public void visitClass(@NotNull final RefClass refClass) {
|
||||
myProcessedSuspicious.add(refClass);
|
||||
if (!refClass.isAnonymous()) {
|
||||
getJavaContext().enqueueDerivedClassesProcessor(refClass, new GlobalJavaInspectionContext.DerivedClassesProcessor() {
|
||||
@@ -654,69 +617,10 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalJavaInspectionContext getJavaContext() {
|
||||
private GlobalJavaInspectionContext getJavaContext() {
|
||||
return getContext().getExtension(GlobalJavaInspectionContext.CONTEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefFilter getFilter() {
|
||||
if (myFilter == null) {
|
||||
myFilter = new WeakUnreferencedFilter(this);
|
||||
}
|
||||
return myFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HTMLComposerImpl getComposer() {
|
||||
if (myComposer == null) {
|
||||
myComposer = new DeadHTMLComposer(this);
|
||||
}
|
||||
return myComposer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportResults(@NotNull final Element parentNode, @NotNull RefEntity refEntity) {
|
||||
if (!(refEntity instanceof RefJavaElement)) return;
|
||||
final WeakUnreferencedFilter filter = new WeakUnreferencedFilter(this);
|
||||
if (!getIgnoredRefElements().contains(refEntity) && filter.accepts((RefJavaElement)refEntity)) {
|
||||
if (refEntity instanceof RefImplicitConstructor) refEntity = ((RefImplicitConstructor)refEntity).getOwnerClass();
|
||||
Element element = refEntity.getRefManager().export(refEntity, parentNode, -1);
|
||||
if (element == null) return;
|
||||
@NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
|
||||
|
||||
final RefElement refElement = (RefElement)refEntity;
|
||||
final HighlightSeverity severity = getCurrentSeverity(refElement);
|
||||
final String attributeKey =
|
||||
getTextAttributeKey(refElement.getRefManager().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
|
||||
problemClassElement.setAttribute("severity", severity.myName);
|
||||
problemClassElement.setAttribute("attribute_key", attributeKey);
|
||||
|
||||
problemClassElement.addContent(InspectionsBundle.message("inspection.export.results.dead.code"));
|
||||
element.addContent(problemClassElement);
|
||||
|
||||
@NonNls Element hintsElement = new Element("hints");
|
||||
|
||||
for (String hint : HINTS) {
|
||||
@NonNls Element hintElement = new Element("hint");
|
||||
hintElement.setAttribute("value", hint);
|
||||
hintsElement.addContent(hintElement);
|
||||
}
|
||||
element.addContent(hintsElement);
|
||||
|
||||
|
||||
Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
DeadHTMLComposer.appendProblemSynopsis((RefElement)refEntity, buf);
|
||||
descriptionElement.addContent(buf.toString());
|
||||
element.addContent(descriptionElement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements) {
|
||||
return myQuickFixActions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -725,224 +629,14 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
context.getStdJobDescriptors().FIND_EXTERNAL_USAGES};
|
||||
}
|
||||
|
||||
private static void commentOutDead(PsiElement psiElement) {
|
||||
PsiFile psiFile = psiElement.getContainingFile();
|
||||
|
||||
if (psiFile != null) {
|
||||
Document doc = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(psiFile);
|
||||
if (doc != null) {
|
||||
TextRange textRange = psiElement.getTextRange();
|
||||
String date = DateFormatUtil.formatDateTime(new Date());
|
||||
|
||||
int startOffset = textRange.getStartOffset();
|
||||
CharSequence chars = doc.getCharsSequence();
|
||||
while (CharArrayUtil.regionMatches(chars, startOffset, InspectionsBundle.message("inspection.dead.code.comment"))) {
|
||||
int line = doc.getLineNumber(startOffset) + 1;
|
||||
if (line < doc.getLineCount()) {
|
||||
startOffset = doc.getLineStartOffset(line);
|
||||
startOffset = CharArrayUtil.shiftForward(chars, startOffset, " \t");
|
||||
}
|
||||
}
|
||||
|
||||
int endOffset = textRange.getEndOffset();
|
||||
|
||||
int line1 = doc.getLineNumber(startOffset);
|
||||
int line2 = doc.getLineNumber(endOffset - 1);
|
||||
|
||||
if (line1 == line2) {
|
||||
doc.insertString(startOffset, InspectionsBundle.message("inspection.dead.code.date.comment", date));
|
||||
}
|
||||
else {
|
||||
for (int i = line1; i <= line2; i++) {
|
||||
doc.insertString(doc.getLineStartOffset(i), "//");
|
||||
}
|
||||
|
||||
doc.insertString(doc.getLineStartOffset(Math.min(line2 + 1, doc.getLineCount() - 1)),
|
||||
InspectionsBundle.message("inspection.dead.code.stop.comment", date));
|
||||
doc.insertString(doc.getLineStartOffset(line1), InspectionsBundle.message("inspection.dead.code.start.comment", date));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IntentionAction findQuickFixes(final CommonProblemDescriptor descriptor, final String hint) {
|
||||
if (descriptor instanceof ProblemDescriptor) {
|
||||
if (DELETE.equals(hint)) {
|
||||
return new PermanentDeleteFix(((ProblemDescriptor)descriptor).getPsiElement());
|
||||
}
|
||||
if (COMMENT.equals(hint)) {
|
||||
return new CommentOutFix(((ProblemDescriptor)descriptor).getPsiElement());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class PermanentDeleteAction extends QuickFixAction {
|
||||
private PermanentDeleteAction() {
|
||||
super(DELETE_QUICK_FIX, AllIcons.Actions.Cancel, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), UnusedDeclarationInspection.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(final RefElement[] refElements) {
|
||||
if (!super.applyFix(refElements)) return false;
|
||||
final ArrayList<PsiElement> psiElements = new ArrayList<PsiElement>();
|
||||
for (RefElement refElement : refElements) {
|
||||
PsiElement psiElement = refElement.getElement();
|
||||
if (psiElement == null) continue;
|
||||
if (getFilter().getElementProblemCount((RefJavaElement)refElement) == 0) continue;
|
||||
psiElements.add(psiElement);
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Project project = getContext().getProject();
|
||||
SafeDeleteHandler.invoke(project, PsiUtilCore.toPsiElementArray(psiElements), false, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeElements(refElements, project, UnusedDeclarationInspection.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return false; //refresh after safe delete dialog is closed
|
||||
}
|
||||
}
|
||||
|
||||
private static class PermanentDeleteFix implements IntentionAction {
|
||||
private final PsiElement myElement;
|
||||
|
||||
private PermanentDeleteFix(final PsiElement element) {
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return DELETE_QUICK_FIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@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 {
|
||||
if (myElement != null && myElement.isValid()) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SafeDeleteHandler
|
||||
.invoke(myElement.getProject(), new PsiElement[]{PsiTreeUtil.getParentOfType(myElement, PsiModifierListOwner.class)}, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class CommentOutBin extends QuickFixAction {
|
||||
private CommentOutBin() {
|
||||
super(COMMENT_OUT_QUICK_FIX, null, KeyStroke.getKeyStroke(KeyEvent.VK_SLASH, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK),
|
||||
UnusedDeclarationInspection.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(RefElement[] refElements) {
|
||||
if (!super.applyFix(refElements)) return false;
|
||||
ArrayList<RefElement> deletedRefs = new ArrayList<RefElement>(1);
|
||||
for (RefElement refElement : refElements) {
|
||||
PsiElement psiElement = refElement.getElement();
|
||||
if (psiElement == null) continue;
|
||||
if (getFilter().getElementProblemCount((RefJavaElement)refElement) == 0) continue;
|
||||
commentOutDead(psiElement);
|
||||
refElement.getRefManager().removeRefElement(refElement, deletedRefs);
|
||||
}
|
||||
|
||||
EntryPointsManager entryPointsManager = getEntryPointsManager();
|
||||
for (RefElement refElement : deletedRefs) {
|
||||
entryPointsManager.removeEntryPoint(refElement);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CommentOutFix implements IntentionAction {
|
||||
private final PsiElement myElement;
|
||||
|
||||
private CommentOutFix(final PsiElement element) {
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return COMMENT_OUT_QUICK_FIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@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 {
|
||||
if (myElement != null && myElement.isValid()) {
|
||||
commentOutDead(PsiTreeUtil.getParentOfType(myElement, PsiModifierListOwner.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class MoveToEntries extends QuickFixAction {
|
||||
private MoveToEntries() {
|
||||
super(InspectionsBundle.message("inspection.dead.code.entry.point.quickfix"), null, KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0), UnusedDeclarationInspection.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(RefElement[] refElements) {
|
||||
final EntryPointsManager entryPointsManager = getEntryPointsManager();
|
||||
for (RefElement refElement : refElements) {
|
||||
entryPointsManager.addEntryPoint(refElement, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void checkForReachables() {
|
||||
void checkForReachables() {
|
||||
CodeScanner codeScanner = new CodeScanner();
|
||||
|
||||
// Cleanup previous reachability information.
|
||||
getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override public void visitElement(@NotNull RefEntity refEntity) {
|
||||
getContext().getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override
|
||||
public void visitElement(@NotNull RefEntity refEntity) {
|
||||
if (refEntity instanceof RefJavaElement) {
|
||||
final RefJavaElementImpl refElement = (RefJavaElementImpl)refEntity;
|
||||
if (!getContext().isToCheckMember(refElement, UnusedDeclarationInspection.this)) return;
|
||||
@@ -1094,18 +788,16 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContent() {
|
||||
checkForReachables();
|
||||
super.updateContent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionNode createToolNode(@NotNull final InspectionRVContentProvider provider, @NotNull final InspectionTreeNode parentNode, final boolean showStructure) {
|
||||
final InspectionNode toolNode = super.createToolNode(provider, parentNode, showStructure);
|
||||
final EntryPointsNode entryPointsNode = new EntryPointsNode(this);
|
||||
provider.appendToolNodeContent(entryPointsNode, toolNode, showStructure);
|
||||
return entryPointsNode;
|
||||
public InspectionToolPresentation createPresentation(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
myContext = (GlobalInspectionContextImpl)toolWrapper.getContext();
|
||||
return new UnusedDeclarationPresentation(toolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGraphNeeded() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+521
@@ -0,0 +1,521 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.deadCode;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.*;
|
||||
import com.intellij.codeInspection.util.RefFilter;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.refactoring.safeDelete.SafeDeleteHandler;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.*;
|
||||
|
||||
public class UnusedDeclarationPresentation extends DefaultInspectionToolPresentation {
|
||||
private Map<String, Set<RefEntity>> myPackageContents = new HashMap<String, Set<RefEntity>>();
|
||||
|
||||
private Map<String, Set<RefEntity>> myOldPackageContents = null;
|
||||
|
||||
private final Set<RefEntity> myIgnoreElements = new HashSet<RefEntity>();
|
||||
private WeakUnreferencedFilter myFilter;
|
||||
private DeadHTMLComposer myComposer;
|
||||
@NonNls private static final String DELETE = "delete";
|
||||
@NonNls private static final String COMMENT = "comment";
|
||||
@NonNls private static final String [] HINTS = {COMMENT, DELETE};
|
||||
|
||||
public UnusedDeclarationPresentation(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(toolWrapper);
|
||||
myQuickFixActions = createQuickFixes(toolWrapper);
|
||||
}
|
||||
|
||||
public RefFilter getFilter() {
|
||||
if (myFilter == null) {
|
||||
myFilter = new WeakUnreferencedFilter(getTool(), getContext());
|
||||
}
|
||||
return myFilter;
|
||||
}
|
||||
private static class WeakUnreferencedFilter extends UnreferencedFilter {
|
||||
private WeakUnreferencedFilter(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContextImpl context) {
|
||||
super(tool, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getElementProblemCount(final RefJavaElement refElement) {
|
||||
final int problemCount = super.getElementProblemCount(refElement);
|
||||
if (problemCount > - 1) return problemCount;
|
||||
if (!((RefElementImpl)refElement).hasSuspiciousCallers() || ((RefJavaElementImpl)refElement).isSuspiciousRecursive()) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
UnusedDeclarationInspection getTool() {
|
||||
return (UnusedDeclarationInspection)getToolWrapper().getTool();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HTMLComposerImpl getComposer() {
|
||||
if (myComposer == null) {
|
||||
myComposer = new DeadHTMLComposer(this);
|
||||
}
|
||||
return myComposer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportResults(@NotNull final Element parentNode, @NotNull RefEntity refEntity) {
|
||||
if (!(refEntity instanceof RefJavaElement)) return;
|
||||
final RefFilter filter = getFilter();
|
||||
if (!getIgnoredRefElements().contains(refEntity) && filter.accepts((RefJavaElement)refEntity)) {
|
||||
refEntity = getRefManager().getRefinedElement(refEntity);
|
||||
Element element = refEntity.getRefManager().export(refEntity, parentNode, -1);
|
||||
if (element == null) return;
|
||||
@NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
|
||||
|
||||
final RefElement refElement = (RefElement)refEntity;
|
||||
final HighlightSeverity severity = getSeverity(refElement, getContext(), getToolWrapper());
|
||||
final String attributeKey =
|
||||
getTextAttributeKey(refElement.getRefManager().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
|
||||
problemClassElement.setAttribute("severity", severity.myName);
|
||||
problemClassElement.setAttribute("attribute_key", attributeKey);
|
||||
|
||||
problemClassElement.addContent(InspectionsBundle.message("inspection.export.results.dead.code"));
|
||||
element.addContent(problemClassElement);
|
||||
|
||||
@NonNls Element hintsElement = new Element("hints");
|
||||
|
||||
for (String hint : HINTS) {
|
||||
@NonNls Element hintElement = new Element("hint");
|
||||
hintElement.setAttribute("value", hint);
|
||||
hintsElement.addContent(hintElement);
|
||||
}
|
||||
element.addContent(hintsElement);
|
||||
|
||||
|
||||
Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
|
||||
StringBuffer buf = new StringBuffer();
|
||||
DeadHTMLComposer.appendProblemSynopsis((RefElement)refEntity, buf);
|
||||
descriptionElement.addContent(buf.toString());
|
||||
element.addContent(descriptionElement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements) {
|
||||
return myQuickFixActions;
|
||||
}
|
||||
|
||||
final QuickFixAction[] myQuickFixActions;
|
||||
|
||||
@NotNull
|
||||
private QuickFixAction[] createQuickFixes(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
return new QuickFixAction[]{new PermanentDeleteAction(toolWrapper), new CommentOutBin(toolWrapper), new MoveToEntries(toolWrapper)};
|
||||
}
|
||||
private static final String DELETE_QUICK_FIX = InspectionsBundle.message("inspection.dead.code.safe.delete.quickfix");
|
||||
|
||||
class PermanentDeleteAction extends QuickFixAction {
|
||||
PermanentDeleteAction(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(DELETE_QUICK_FIX, AllIcons.Actions.Cancel, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), toolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(final RefElement[] refElements) {
|
||||
if (!super.applyFix(refElements)) return false;
|
||||
final ArrayList<PsiElement> psiElements = new ArrayList<PsiElement>();
|
||||
for (RefElement refElement : refElements) {
|
||||
PsiElement psiElement = refElement.getElement();
|
||||
if (psiElement == null) continue;
|
||||
if (getFilter().getElementProblemCount((RefJavaElement)refElement) == 0) continue;
|
||||
psiElements.add(psiElement);
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Project project = getContext().getProject();
|
||||
SafeDeleteHandler.invoke(project, PsiUtilCore.toPsiElementArray(psiElements), false, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeElements(refElements, project, myToolWrapper);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return false; //refresh after safe delete dialog is closed
|
||||
}
|
||||
}
|
||||
|
||||
private EntryPointsManager getEntryPointsManager() {
|
||||
return getContext().getExtension(GlobalJavaInspectionContext.CONTEXT).getEntryPointsManager(getContext().getRefManager());
|
||||
}
|
||||
|
||||
class MoveToEntries extends QuickFixAction {
|
||||
MoveToEntries(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(InspectionsBundle.message("inspection.dead.code.entry.point.quickfix"), null, KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0), toolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(RefElement[] refElements) {
|
||||
final EntryPointsManager entryPointsManager = getEntryPointsManager();
|
||||
for (RefElement refElement : refElements) {
|
||||
entryPointsManager.addEntryPoint(refElement, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class CommentOutBin extends QuickFixAction {
|
||||
CommentOutBin(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(COMMENT_OUT_QUICK_FIX, null, KeyStroke.getKeyStroke(KeyEvent.VK_SLASH, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK),
|
||||
toolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean applyFix(RefElement[] refElements) {
|
||||
if (!super.applyFix(refElements)) return false;
|
||||
ArrayList<RefElement> deletedRefs = new ArrayList<RefElement>(1);
|
||||
for (RefElement refElement : refElements) {
|
||||
PsiElement psiElement = refElement.getElement();
|
||||
if (psiElement == null) continue;
|
||||
if (getFilter().getElementProblemCount((RefJavaElement)refElement) == 0) continue;
|
||||
commentOutDead(psiElement);
|
||||
refElement.getRefManager().removeRefElement(refElement, deletedRefs);
|
||||
}
|
||||
|
||||
EntryPointsManager entryPointsManager = getEntryPointsManager();
|
||||
for (RefElement refElement : deletedRefs) {
|
||||
entryPointsManager.removeEntryPoint(refElement);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String COMMENT_OUT_QUICK_FIX = InspectionsBundle.message("inspection.dead.code.comment.quickfix");
|
||||
private static class CommentOutFix implements IntentionAction {
|
||||
private final PsiElement myElement;
|
||||
|
||||
private CommentOutFix(final PsiElement element) {
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return COMMENT_OUT_QUICK_FIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@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 {
|
||||
if (myElement != null && myElement.isValid()) {
|
||||
commentOutDead(PsiTreeUtil.getParentOfType(myElement, PsiModifierListOwner.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static void commentOutDead(PsiElement psiElement) {
|
||||
PsiFile psiFile = psiElement.getContainingFile();
|
||||
|
||||
if (psiFile != null) {
|
||||
Document doc = PsiDocumentManager.getInstance(psiElement.getProject()).getDocument(psiFile);
|
||||
if (doc != null) {
|
||||
TextRange textRange = psiElement.getTextRange();
|
||||
String date = DateFormatUtil.formatDateTime(new Date());
|
||||
|
||||
int startOffset = textRange.getStartOffset();
|
||||
CharSequence chars = doc.getCharsSequence();
|
||||
while (CharArrayUtil.regionMatches(chars, startOffset, InspectionsBundle.message("inspection.dead.code.comment"))) {
|
||||
int line = doc.getLineNumber(startOffset) + 1;
|
||||
if (line < doc.getLineCount()) {
|
||||
startOffset = doc.getLineStartOffset(line);
|
||||
startOffset = CharArrayUtil.shiftForward(chars, startOffset, " \t");
|
||||
}
|
||||
}
|
||||
|
||||
int endOffset = textRange.getEndOffset();
|
||||
|
||||
int line1 = doc.getLineNumber(startOffset);
|
||||
int line2 = doc.getLineNumber(endOffset - 1);
|
||||
|
||||
if (line1 == line2) {
|
||||
doc.insertString(startOffset, InspectionsBundle.message("inspection.dead.code.date.comment", date));
|
||||
}
|
||||
else {
|
||||
for (int i = line1; i <= line2; i++) {
|
||||
doc.insertString(doc.getLineStartOffset(i), "//");
|
||||
}
|
||||
|
||||
doc.insertString(doc.getLineStartOffset(Math.min(line2 + 1, doc.getLineCount() - 1)),
|
||||
InspectionsBundle.message("inspection.dead.code.stop.comment", date));
|
||||
doc.insertString(doc.getLineStartOffset(line1), InspectionsBundle.message("inspection.dead.code.start.comment", date));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionNode createToolNode(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull InspectionNode node,
|
||||
@NotNull InspectionRVContentProvider provider,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
boolean showStructure) {
|
||||
final EntryPointsNode entryPointsNode = new EntryPointsNode(getTool(), context);
|
||||
InspectionToolWrapper dummyToolWrapper = entryPointsNode.getToolWrapper();
|
||||
InspectionToolPresentation presentation = context.getPresentation(dummyToolWrapper);
|
||||
presentation.updateContent();
|
||||
provider.appendToolNodeContent(context, entryPointsNode, node, showStructure);
|
||||
return entryPointsNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull GlobalInspectionContextImpl context) {
|
||||
super.initialize(context);
|
||||
((EntryPointsManagerImpl)getEntryPointsManager()).setAddNonJavaEntries(getTool().ADD_NONJAVA_TO_ENTRIES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContent() {
|
||||
getTool().checkForReachables();
|
||||
myPackageContents = new HashMap<String, Set<RefEntity>>();
|
||||
getContext().getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override public void visitElement(@NotNull RefEntity refEntity) {
|
||||
if (!(refEntity instanceof RefJavaElement)) return;//dead code doesn't work with refModule | refPackage
|
||||
RefJavaElement refElement = (RefJavaElement)refEntity;
|
||||
if (!(getContext().getUIOptions().FILTER_RESOLVED_ITEMS && getIgnoredRefElements().contains(refElement)) && refElement.isValid() && getFilter().accepts(refElement)) {
|
||||
String packageName = RefJavaUtil.getInstance().getPackageName(refEntity);
|
||||
Set<RefEntity> content = myPackageContents.get(packageName);
|
||||
if (content == null) {
|
||||
content = new HashSet<RefEntity>();
|
||||
myPackageContents.put(packageName, content);
|
||||
}
|
||||
content.add(refEntity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReportedProblems() {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context != null && context.getUIOptions().SHOW_ONLY_DIFF){
|
||||
return containsOnlyDiff(myPackageContents) ||
|
||||
myOldPackageContents != null && containsOnlyDiff(myOldPackageContents);
|
||||
}
|
||||
if (!myPackageContents.isEmpty()) return true;
|
||||
return isOldProblemsIncluded() && !myOldPackageContents.isEmpty();
|
||||
}
|
||||
|
||||
private boolean containsOnlyDiff(@NotNull Map<String, Set<RefEntity>> packageContents) {
|
||||
for (String packageName : packageContents.keySet()) {
|
||||
final Set<RefEntity> refElements = packageContents.get(packageName);
|
||||
if (refElements != null){
|
||||
for (RefEntity refElement : refElements) {
|
||||
if (getElementStatus(refElement) != FileStatus.NOT_CHANGED){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<RefEntity>> getContent() {
|
||||
return myPackageContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<RefEntity>> getOldContent() {
|
||||
return myOldPackageContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreCurrentElement(RefEntity refEntity) {
|
||||
if (refEntity == null) return;
|
||||
myIgnoreElements.add(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amnesty(RefEntity refEntity) {
|
||||
myIgnoreElements.remove(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
super.cleanup();
|
||||
myOldPackageContents = null;
|
||||
myPackageContents.clear();
|
||||
myIgnoreElements.clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void finalCleanup() {
|
||||
super.finalCleanup();
|
||||
myOldPackageContents = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGraphNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isElementIgnored(final RefEntity element) {
|
||||
for (RefEntity entity : myIgnoreElements) {
|
||||
if (Comparing.equal(entity, element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileStatus getElementStatus(final RefEntity element) {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context != null && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN){
|
||||
if (myOldPackageContents != null){
|
||||
final boolean old = RefUtil.contains(element, collectRefElements(myOldPackageContents));
|
||||
final boolean current = RefUtil.contains(element, collectRefElements(myPackageContents));
|
||||
return calcStatus(old, current);
|
||||
}
|
||||
return FileStatus.ADDED;
|
||||
}
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<RefEntity> getIgnoredRefElements() {
|
||||
return myIgnoreElements;
|
||||
}
|
||||
|
||||
private static Set<RefEntity> collectRefElements(Map<String, Set<RefEntity>> packageContents) {
|
||||
Set<RefEntity> allAvailable = new HashSet<RefEntity>();
|
||||
for (Set<RefEntity> elements : packageContents.values()) {
|
||||
allAvailable.addAll(elements);
|
||||
}
|
||||
return allAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IntentionAction findQuickFixes(@NotNull final CommonProblemDescriptor descriptor, final String hint) {
|
||||
if (descriptor instanceof ProblemDescriptor) {
|
||||
if (DELETE.equals(hint)) {
|
||||
return new PermanentDeleteFix(((ProblemDescriptor)descriptor).getPsiElement());
|
||||
}
|
||||
if (COMMENT.equals(hint)) {
|
||||
return new CommentOutFix(((ProblemDescriptor)descriptor).getPsiElement());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static class PermanentDeleteFix implements IntentionAction {
|
||||
private final PsiElement myElement;
|
||||
|
||||
private PermanentDeleteFix(final PsiElement element) {
|
||||
myElement = element;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return DELETE_QUICK_FIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@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 {
|
||||
if (myElement != null && myElement.isValid()) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SafeDeleteHandler
|
||||
.invoke(myElement.getProject(), new PsiElement[]{PsiTreeUtil.getParentOfType(myElement, PsiModifierListOwner.class)}, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.SuppressIntentionAction;
|
||||
import com.intellij.codeInspection.SuppressManager;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefJavaElement;
|
||||
import com.intellij.codeInspection.reference.RefJavaUtil;
|
||||
import com.intellij.codeInspection.reference.RefJavaVisitor;
|
||||
import com.intellij.codeInspection.util.RefFilter;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public abstract class FilteringInspectionTool extends InspectionTool {
|
||||
public abstract RefFilter getFilter();
|
||||
private Map<String, Set<RefEntity>> myPackageContents = new HashMap<String, Set<RefEntity>>();
|
||||
|
||||
private Map<String, Set<RefEntity>> myOldPackageContents = null;
|
||||
|
||||
private final Set<RefEntity> myIgnoreElements = new HashSet<RefEntity>();
|
||||
|
||||
@Override
|
||||
public void updateContent() {
|
||||
myPackageContents = new HashMap<String, Set<RefEntity>>();
|
||||
getContext().getRefManager().iterate(new RefJavaVisitor() {
|
||||
@Override public void visitElement(@NotNull RefEntity refEntity) {
|
||||
if (!(refEntity instanceof RefJavaElement)) return;//dead code doesn't work with refModule | refPackage
|
||||
RefJavaElement refElement = (RefJavaElement)refEntity;
|
||||
if (!(getContext().getUIOptions().FILTER_RESOLVED_ITEMS && myIgnoreElements.contains(refElement)) && refElement.isValid() && getFilter().accepts(refElement)) {
|
||||
String packageName = RefJavaUtil.getInstance().getPackageName(refEntity);
|
||||
Set<RefEntity> content = myPackageContents.get(packageName);
|
||||
if (content == null) {
|
||||
content = new HashSet<RefEntity>();
|
||||
myPackageContents.put(packageName, content);
|
||||
}
|
||||
content.add(refEntity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReportedProblems() {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context != null && context.getUIOptions().SHOW_ONLY_DIFF){
|
||||
return containsOnlyDiff(myPackageContents) ||
|
||||
myOldPackageContents != null && containsOnlyDiff(myOldPackageContents);
|
||||
}
|
||||
if (!myPackageContents.isEmpty()) return true;
|
||||
return isOldProblemsIncluded() && !myOldPackageContents.isEmpty();
|
||||
}
|
||||
|
||||
private boolean containsOnlyDiff(@NotNull Map<String, Set<RefEntity>> packageContents) {
|
||||
for (String packageName : packageContents.keySet()) {
|
||||
final Set<RefEntity> refElements = packageContents.get(packageName);
|
||||
if (refElements != null){
|
||||
for (RefEntity refElement : refElements) {
|
||||
if (getElementStatus(refElement) != FileStatus.NOT_CHANGED){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<RefEntity>> getContent() {
|
||||
return myPackageContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<RefEntity>> getOldContent() {
|
||||
return myOldPackageContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreCurrentElement(RefEntity refEntity) {
|
||||
if (refEntity == null) return;
|
||||
myIgnoreElements.add(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amnesty(RefEntity refEntity) {
|
||||
myIgnoreElements.remove(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
super.cleanup();
|
||||
myOldPackageContents = null;
|
||||
myPackageContents.clear();
|
||||
myIgnoreElements.clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void finalCleanup() {
|
||||
super.finalCleanup();
|
||||
myOldPackageContents = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGraphNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isElementIgnored(final RefEntity element) {
|
||||
for (RefEntity entity : myIgnoreElements) {
|
||||
if (Comparing.equal(entity, element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileStatus getElementStatus(final RefEntity element) {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context != null && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN){
|
||||
if (myOldPackageContents != null){
|
||||
final boolean old = contains(element, collectRefElements(myOldPackageContents));
|
||||
final boolean current = contains(element, collectRefElements(myPackageContents));
|
||||
return calcStatus(old, current);
|
||||
}
|
||||
return FileStatus.ADDED;
|
||||
}
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<RefEntity> getIgnoredRefElements() {
|
||||
return myIgnoreElements;
|
||||
}
|
||||
|
||||
private static Set<RefEntity> collectRefElements(Map<String, Set<RefEntity>> packageContents) {
|
||||
Set<RefEntity> allAvailable = new HashSet<RefEntity>();
|
||||
for (Set<RefEntity> elements : packageContents.values()) {
|
||||
allAvailable.addAll(elements);
|
||||
}
|
||||
return allAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public SuppressIntentionAction[] getSuppressActions() {
|
||||
return SuppressManager.getInstance().createSuppressActions(HighlightDisplayKey.find(getShortName()));
|
||||
}
|
||||
}
|
||||
+15
-6
@@ -24,6 +24,7 @@ import com.intellij.CommonBundle;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -67,8 +68,8 @@ public class GlobalJavaInspectionContextImpl extends GlobalJavaInspectionContext
|
||||
public void enqueueClassUsagesProcessor(RefClass refClass, UsagesProcessor p) {
|
||||
if (myClassUsagesRequests == null) myClassUsagesRequests = new THashMap<SmartPsiElementPointer, List<UsagesProcessor>>();
|
||||
enqueueRequestImpl(refClass, myClassUsagesRequests, p);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void enqueueDerivedClassesProcessor(RefClass refClass, DerivedClassesProcessor p) {
|
||||
if (myDerivedClassesRequests == null) myDerivedClassesRequests = new THashMap<SmartPsiElementPointer, List<DerivedClassesProcessor>>();
|
||||
@@ -421,17 +422,25 @@ public class GlobalJavaInspectionContextImpl extends GlobalJavaInspectionContext
|
||||
|
||||
|
||||
@Override
|
||||
public void performPostRunActivities(@NotNull List<InspectionProfileEntry> needRepeatSearchRequest, @NotNull final GlobalInspectionContext context) {
|
||||
public void performPostRunActivities(@NotNull List<InspectionToolWrapper> needRepeatSearchRequest, @NotNull final GlobalInspectionContext context) {
|
||||
JobDescriptor progress = context.getStdJobDescriptors().FIND_EXTERNAL_USAGES;
|
||||
progress.setTotalAmount(getRequestCount());
|
||||
|
||||
do {
|
||||
processSearchRequests(context);
|
||||
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);
|
||||
InspectionManager inspectionManager = InspectionManager.getInstance(context.getProject());
|
||||
for (InspectionToolWrapper toolWrapper : requestors) {
|
||||
boolean result = false;
|
||||
if (toolWrapper instanceof GlobalInspectionToolWrapper) {
|
||||
InspectionToolPresentation presentation = ((GlobalInspectionContextImpl)context).getPresentation(toolWrapper);
|
||||
result = ((GlobalInspectionToolWrapper)toolWrapper).getTool().queryExternalUsagesRequests(inspectionManager, context, presentation);
|
||||
}
|
||||
else if (toolWrapper instanceof CommonInspectionToolWrapper) {
|
||||
result = ((CommonInspectionToolWrapper)toolWrapper).getTool().queryExternalUsagesRequests(inspectionManager);
|
||||
}
|
||||
if (!result) {
|
||||
needRepeatSearchRequest.remove(toolWrapper);
|
||||
}
|
||||
}
|
||||
int oldSearchRequestCount = progress.getTotalAmount();
|
||||
|
||||
@@ -110,7 +110,7 @@ public class RefJavaManagerImpl extends RefJavaManager {
|
||||
@Override
|
||||
protected Ref<UnusedDeclarationInspection> compute(PsiFile file, RefManagerImpl refManager) {
|
||||
Tools tools = ((GlobalInspectionContextImpl)refManager.getContext()).getTools().get(UnusedDeclarationInspection.SHORT_NAME);
|
||||
InspectionToolWrapper toolWrapper = tools != null ? (InspectionToolWrapper)tools.getEnabledTool(file) : null;
|
||||
InspectionToolWrapper toolWrapper = tools == null ? null : tools.getEnabledTool(file);
|
||||
InspectionProfileEntry tool = toolWrapper == null ? null : toolWrapper.getTool();
|
||||
return Ref.create(tool instanceof UnusedDeclarationInspection ? (UnusedDeclarationInspection)tool : null);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.deadCode.DummyEntryPointsTool;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.codeInspection.ex.CommonInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -26,9 +28,14 @@ import javax.swing.*;
|
||||
* @author max
|
||||
*/
|
||||
public class EntryPointsNode extends InspectionNode {
|
||||
public EntryPointsNode(@NotNull UnusedDeclarationInspection tool) {
|
||||
super(new DummyEntryPointsTool(tool));
|
||||
getTool().updateContent();
|
||||
public EntryPointsNode(@NotNull UnusedDeclarationInspection tool, @NotNull GlobalInspectionContextImpl context) {
|
||||
super(createDummyWrapper(tool, context));
|
||||
}
|
||||
|
||||
private static CommonInspectionToolWrapper createDummyWrapper(UnusedDeclarationInspection tool, GlobalInspectionContextImpl context) {
|
||||
CommonInspectionToolWrapper wrapper = new CommonInspectionToolWrapper(new DummyEntryPointsTool());
|
||||
wrapper.initialize(context);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-2
@@ -23,11 +23,12 @@ package com.intellij.profile.codeInspection;
|
||||
import com.intellij.codeInsight.daemon.InspectionProfileConvertor;
|
||||
import com.intellij.codeInsight.daemon.JavaAwareInspectionProfileCoverter;
|
||||
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
|
||||
import com.intellij.codeInspection.ex.SpecialToolsManager;
|
||||
import com.intellij.openapi.options.SchemesManagerFactory;
|
||||
|
||||
public class JavaAwareInspectionProfileManager extends InspectionProfileManagerImpl {
|
||||
public JavaAwareInspectionProfileManager(InspectionToolRegistrar registrar, SchemesManagerFactory schemesManagerFactory) {
|
||||
super(registrar, schemesManagerFactory);
|
||||
public JavaAwareInspectionProfileManager(InspectionToolRegistrar registrar, SchemesManagerFactory schemesManagerFactory, SpecialToolsManager specialToolsManager) {
|
||||
super(registrar, schemesManagerFactory,specialToolsManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-7
@@ -20,6 +20,7 @@ import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.codeInspection.actions.RunInspectionIntention;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.visibility.VisibilityInspection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -34,8 +35,8 @@ public class GlobalInspectionContextTest extends CodeInsightTestCase {
|
||||
public void testProblemDuplication() throws Exception {
|
||||
String shortName = new VisibilityInspection().getShortName();
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl("Foo");
|
||||
profile.disableAllTools();
|
||||
profile.enableTool(shortName);
|
||||
profile.disableAllTools(getProject());
|
||||
profile.enableTool(shortName, getProject());
|
||||
|
||||
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
|
||||
context.setExternalProfile(profile);
|
||||
@@ -45,18 +46,20 @@ public class GlobalInspectionContextTest extends CodeInsightTestCase {
|
||||
context.doInspections(scope, InspectionManager.getInstance(getProject()));
|
||||
|
||||
Tools tools = context.getTools().get(shortName);
|
||||
GlobalInspectionToolWrapper tool = (GlobalInspectionToolWrapper)tools.getTool();
|
||||
assertEquals(1, tool.getProblemDescriptors().size());
|
||||
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
assertEquals(1, presentation.getProblemDescriptors().size());
|
||||
|
||||
context.doInspections(scope, InspectionManager.getInstance(getProject()));
|
||||
tools = context.getTools().get(shortName);
|
||||
tool = (GlobalInspectionToolWrapper)tools.getTool();
|
||||
assertEquals(1, tool.getProblemDescriptors().size());
|
||||
toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
|
||||
presentation = context.getPresentation(toolWrapper);
|
||||
assertEquals(1, presentation.getProblemDescriptors().size());
|
||||
}
|
||||
|
||||
public void testRunInspectionContext() throws Exception {
|
||||
InspectionProfile profile = new InspectionProfileImpl("foo");
|
||||
InspectionToolWrapper[] tools = (InspectionToolWrapper[])profile.getInspectionTools(null);
|
||||
InspectionToolWrapper[] tools = profile.getInspectionTools(null);
|
||||
for (InspectionToolWrapper toolWrapper : tools) {
|
||||
if (!toolWrapper.isEnabledByDefault()) {
|
||||
InspectionManagerEx instance = (InspectionManagerEx)InspectionManager.getInstance(myProject);
|
||||
|
||||
@@ -186,11 +186,10 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
}
|
||||
|
||||
public void testLockProfile() throws Exception {
|
||||
|
||||
final List<InspectionToolWrapper> list = new ArrayList<InspectionToolWrapper>();
|
||||
list.add(createTool("foo", true));
|
||||
|
||||
InspectionToolRegistrar registrar = new InspectionToolRegistrar(null) {
|
||||
InspectionToolRegistrar registrar = new InspectionToolRegistrar() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
@@ -200,10 +199,10 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
|
||||
InspectionProfileImpl profile = createProfile(registrar);
|
||||
|
||||
List<ScopeToolState> tools = profile.getAllTools();
|
||||
List<ScopeToolState> tools = profile.getAllTools(getProject());
|
||||
assertEquals(1, tools.size());
|
||||
assertTrue(profile.isToolEnabled(HighlightDisplayKey.find("foo")));
|
||||
assertTrue(profile.getToolDefaultState("foo").isEnabled());
|
||||
assertTrue(profile.getToolDefaultState("foo", getProject()).isEnabled());
|
||||
|
||||
InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
|
||||
model.lockProfile(true);
|
||||
@@ -226,15 +225,15 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
profile = createProfile(registrar);
|
||||
profile.readExternal(element);
|
||||
|
||||
tools = profile.getAllTools();
|
||||
tools = profile.getAllTools(getProject());
|
||||
assertEquals(3, tools.size());
|
||||
|
||||
assertTrue(profile.isProfileLocked());
|
||||
assertFalse(profile.isToolEnabled(HighlightDisplayKey.find("bar")));
|
||||
assertFalse(profile.isToolEnabled(HighlightDisplayKey.find("disabled")));
|
||||
|
||||
assertTrue(profile.getToolDefaultState("bar").isEnabled());
|
||||
assertFalse(profile.getToolDefaultState("disabled").isEnabled());
|
||||
assertTrue(profile.getToolDefaultState("bar", getProject()).isEnabled());
|
||||
assertFalse(profile.getToolDefaultState("disabled", getProject()).isEnabled());
|
||||
|
||||
assertEquals("<profile version=\"1.0\" is_locked=\"true\">\n" +
|
||||
" <option name=\"myName\" value=\"Foo\" />\n" +
|
||||
@@ -262,8 +261,8 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
|
||||
public void testGlobalInspectionContext() throws Exception {
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl("Foo");
|
||||
profile.disableAllTools();
|
||||
profile.enableTool(new UnusedDeclarationInspection().getShortName());
|
||||
profile.disableAllTools(getProject());
|
||||
profile.enableTool(new UnusedDeclarationInspection().getShortName(), getProject());
|
||||
|
||||
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
|
||||
context.setExternalProfile(profile);
|
||||
@@ -285,7 +284,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
|
||||
model = foo.getModifiableModel();
|
||||
assertEquals(0, countInitializedTools(model));
|
||||
List<ScopeToolState> tools = ((InspectionProfileImpl)model).getAllTools();
|
||||
List<ScopeToolState> tools = ((InspectionProfileImpl)model).getAllTools(getProject());
|
||||
for (ScopeToolState tool : tools) {
|
||||
if (!tool.isEnabled()) {
|
||||
tool.setEnabled(true);
|
||||
@@ -301,15 +300,15 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
assertEquals(0, countInitializedTools(profile));
|
||||
InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(null);
|
||||
assertTrue(toolWrappers.length > 0);
|
||||
InspectionToolWrapper toolWrapper = profile.getInspectionTool(new DataFlowInspection().getShortName());
|
||||
InspectionToolWrapper toolWrapper = profile.getInspectionTool(new DataFlowInspection().getShortName(), getProject());
|
||||
assertNotNull(toolWrapper);
|
||||
String id = toolWrapper.getShortName();
|
||||
System.out.println(id);
|
||||
if (profile.isToolEnabled(HighlightDisplayKey.findById(id))) {
|
||||
profile.disableTool(id);
|
||||
profile.disableTool(id, getProject());
|
||||
}
|
||||
else {
|
||||
profile.enableTool(id);
|
||||
profile.enableTool(id, getProject());
|
||||
}
|
||||
assertEquals(0, countInitializedTools(profile));
|
||||
profile.writeExternal(new Element("profile"));
|
||||
@@ -343,9 +342,9 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
@NotNull
|
||||
public static List<InspectionToolWrapper> getInitializedTools(@NotNull Profile foo) {
|
||||
List<InspectionToolWrapper> initialized = new ArrayList<InspectionToolWrapper>();
|
||||
List<ScopeToolState> tools = ((InspectionProfileImpl)foo).getAllTools();
|
||||
List<ScopeToolState> tools = ((InspectionProfileImpl)foo).getAllTools(getProject());
|
||||
for (ScopeToolState tool : tools) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)tool.getTool();
|
||||
InspectionToolWrapper toolWrapper = tool.getTool();
|
||||
if (toolWrapper.isInitialized()) {
|
||||
initialized.add(toolWrapper);
|
||||
}
|
||||
@@ -360,11 +359,11 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
foo.groupDisplayName = s;
|
||||
foo.level = "ERROR";
|
||||
foo.enabledByDefault = enabled;
|
||||
foo.implementationClass = "com.intellij.codeInspection.InspectionProfileTest$TestTool";
|
||||
foo.implementationClass = TestTool.class.getName();
|
||||
return new LocalInspectionToolWrapper(foo);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration", "InspectionDescriptionNotFoundInspection"})
|
||||
@SuppressWarnings("InspectionDescriptionNotFoundInspection")
|
||||
public static class TestTool extends LocalInspectionTool {
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class SingleInspectionProfilePanelTest extends LightIdeaTestCase {
|
||||
}
|
||||
|
||||
private JavaDocLocalInspection getInspection(InspectionProfileImpl profile) {
|
||||
LocalInspectionToolWrapper original = (LocalInspectionToolWrapper)profile.getInspectionTool(myInspection.getShortName());
|
||||
LocalInspectionToolWrapper original = (LocalInspectionToolWrapper)profile.getInspectionTool(myInspection.getShortName(), getProject());
|
||||
assert original != null;
|
||||
return (JavaDocLocalInspection)original.getTool();
|
||||
}
|
||||
|
||||
@@ -194,14 +194,13 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool){
|
||||
//assert !(tool instanceof InspectionToolWrapper) : tool;
|
||||
InspectionToolWrapper wrapper = InspectionToolRegistrar.wrapTool(tool);
|
||||
final String shortName = wrapper.getShortName();
|
||||
InspectionToolWrapper toolWrapper = tool instanceof InspectionTool ? new CommonInspectionToolWrapper((InspectionTool)tool) : InspectionToolRegistrar.wrapTool(tool);
|
||||
final String shortName = toolWrapper.getShortName();
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
|
||||
if (key == null) {
|
||||
HighlightDisplayKey.register(shortName, wrapper.getDisplayName(), ((LocalInspectionToolWrapper)wrapper).getID());
|
||||
HighlightDisplayKey.register(shortName, toolWrapper.getDisplayName(), ((LocalInspectionToolWrapper)toolWrapper).getID());
|
||||
}
|
||||
myAvailableTools.put(shortName, wrapper);
|
||||
myAvailableTools.put(shortName, toolWrapper);
|
||||
}
|
||||
|
||||
protected void enableInspectionToolsFromProvider(InspectionToolProvider toolProvider){
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.Tools;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -40,11 +41,10 @@ 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);
|
||||
InspectionToolWrapper getInspectionTool(@NotNull String shortName, @NotNull PsiElement element);
|
||||
|
||||
@Nullable
|
||||
InspectionProfileEntry getInspectionTool(@NotNull String shortName);
|
||||
InspectionToolWrapper getInspectionTool(@NotNull String shortName, Project project);
|
||||
|
||||
/** Returns (unwrapped) inspection */
|
||||
InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element);
|
||||
@@ -72,7 +72,7 @@ public interface InspectionProfile extends Profile {
|
||||
* @return all (both enabled and disabled) tools
|
||||
*/
|
||||
@NotNull
|
||||
InspectionProfileEntry[] getInspectionTools(@Nullable PsiElement element);
|
||||
InspectionToolWrapper[] getInspectionTools(@Nullable PsiElement element);
|
||||
|
||||
void cleanup(@NotNull Project project);
|
||||
|
||||
@@ -86,7 +86,7 @@ public interface InspectionProfile extends Profile {
|
||||
|
||||
boolean isToolEnabled(HighlightDisplayKey key);
|
||||
|
||||
boolean isExecutable();
|
||||
boolean isExecutable(Project project);
|
||||
|
||||
boolean isEditable();
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.intellij.codeInspection;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.Profile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
@@ -39,11 +41,11 @@ public interface ModifiableModel extends Profile {
|
||||
|
||||
void setBaseProfile(InspectionProfile profile);
|
||||
|
||||
void enableTool(String inspectionTool, NamedScope namedScope);
|
||||
void enableTool(String inspectionTool, NamedScope namedScope, Project project);
|
||||
|
||||
void disableTool(String inspectionTool, NamedScope namedScope);
|
||||
void disableTool(String inspectionTool, NamedScope namedScope, @NotNull Project project);
|
||||
|
||||
void setErrorLevel(HighlightDisplayKey key, @NotNull HighlightDisplayLevel level);
|
||||
void setErrorLevel(HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project);
|
||||
|
||||
HighlightDisplayLevel getErrorLevel(HighlightDisplayKey inspectionToolKey, PsiElement element);
|
||||
|
||||
@@ -57,24 +59,21 @@ public interface ModifiableModel extends Profile {
|
||||
|
||||
void setModified(final boolean toolsSettingsChanged);
|
||||
|
||||
@Deprecated
|
||||
boolean isProperSetting(HighlightDisplayKey key);
|
||||
boolean isProperSetting(@NotNull String toolId);
|
||||
|
||||
boolean isProperSetting(String toolId);
|
||||
void resetToBase(Project project);
|
||||
|
||||
void resetToBase();
|
||||
|
||||
void resetToEmpty();
|
||||
void resetToEmpty(Project project);
|
||||
|
||||
/**
|
||||
* @return {@link com.intellij.codeInspection.ex.InspectionToolWrapper}
|
||||
* @see #getUnwrappedTool(String, com.intellij.psi.PsiElement)
|
||||
*/
|
||||
InspectionProfileEntry getInspectionTool(String shortName, PsiElement element);
|
||||
InspectionToolWrapper getInspectionTool(String shortName, PsiElement element);
|
||||
|
||||
InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element);
|
||||
|
||||
InspectionProfileEntry[] getInspectionTools(PsiElement element);
|
||||
InspectionToolWrapper[] getInspectionTools(PsiElement element);
|
||||
|
||||
void copyFrom(InspectionProfile profile);
|
||||
|
||||
@@ -86,7 +85,7 @@ public interface ModifiableModel extends Profile {
|
||||
|
||||
void lockProfile(boolean isLocked);
|
||||
|
||||
void disableTool(String toolId, PsiElement element);
|
||||
void disableTool(@NotNull String toolId, @NotNull PsiElement element);
|
||||
|
||||
void disableTool(String inspectionTool);
|
||||
void disableTool(String inspectionTool, Project project);
|
||||
}
|
||||
|
||||
+46
-60
@@ -16,32 +16,30 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 9/28/11
|
||||
*/
|
||||
public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E extends InspectionEP> extends DescriptorProviderInspection {
|
||||
public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E extends InspectionEP> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolWrapper");
|
||||
|
||||
protected T myTool;
|
||||
protected final E myEP;
|
||||
private GlobalInspectionContext myContext;
|
||||
|
||||
protected InspectionToolWrapper(@NotNull E ep) {
|
||||
this(null, ep);
|
||||
@@ -62,7 +60,17 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
myEP = other.myEP;
|
||||
// we need to create a copy for buffering
|
||||
//noinspection unchecked
|
||||
myTool = other.myTool == null ? null : (T)InspectionToolRegistrar.instantiateTool(other.myTool.getClass());
|
||||
myTool = other.myTool == null ? null : (T)InspectionToolsRegistrarCore.instantiateTool(other.myTool.getClass());
|
||||
}
|
||||
|
||||
public void initialize(@NotNull GlobalInspectionContext context) {
|
||||
myContext = context;
|
||||
projectOpened(context.getProject());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GlobalInspectionContext getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -80,7 +88,6 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
return myTool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return myTool != null;
|
||||
}
|
||||
@@ -94,13 +101,11 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
return myEP != null && myEP.applyToDialects;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getShortName() {
|
||||
return myEP != null ? myEP.getShortName() : getTool().getShortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
if (myEP == null) {
|
||||
@@ -112,7 +117,6 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getGroupDisplayName() {
|
||||
if (myEP == null) {
|
||||
@@ -124,18 +128,15 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
return myEP == null ? getTool().isEnabledByDefault() : myEP.enabledByDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HighlightDisplayLevel getDefaultLevel() {
|
||||
return myEP == null ? getTool().getDefaultLevel() : myEP.getDefaultLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[] getGroupPath() {
|
||||
if (myEP == null) {
|
||||
@@ -147,41 +148,35 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSettings(@NotNull Element element) throws InvalidDataException {
|
||||
getTool().readSettings(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSettings(@NotNull Element element) throws WriteExternalException {
|
||||
getTool().writeSettings(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return getTool().createOptionsPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectOpened(Project project) {
|
||||
public void projectOpened(@NotNull Project project) {
|
||||
if (myEP == null) {
|
||||
getTool().projectOpened(project);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed(Project project) {
|
||||
public void projectClosed(@NotNull Project project) {
|
||||
if (myEP == null) {
|
||||
getTool().projectClosed(project);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStaticDescription() {
|
||||
return myEP == null || myEP.hasStaticDescription ? getTool().getStaticDescription() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loadDescription() {
|
||||
final String description = getStaticDescription();
|
||||
if (description != null) return description;
|
||||
try {
|
||||
URL descriptionUrl = getDescriptionUrl();
|
||||
if (descriptionUrl == null) return null;
|
||||
return ResourceUtil.loadText(descriptionUrl);
|
||||
}
|
||||
catch (IOException ignored) { }
|
||||
|
||||
return getTool().loadDescription();
|
||||
}
|
||||
|
||||
protected URL getDescriptionUrl() {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (myEP == null || app.isUnitTestMode() || app.isHeadlessEnvironment()) {
|
||||
@@ -197,34 +192,21 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
return ResourceUtil.getResource(getDescriptionContextClass(), "/inspectionDescriptions", fileName);
|
||||
}
|
||||
|
||||
//public String getDescriptionFileName() {
|
||||
// return getShortName() + ".html";
|
||||
//}
|
||||
|
||||
@Override
|
||||
public SuppressIntentionAction[] getSuppressActions() {
|
||||
T tool = getTool();
|
||||
if (tool instanceof CustomSuppressableInspectionTool) {
|
||||
return ((CustomSuppressableInspectionTool)tool).getSuppressActions(null);
|
||||
}
|
||||
if (tool instanceof BatchSuppressableTool) {
|
||||
LocalQuickFix[] actions = ((BatchSuppressableTool)tool).getBatchSuppressActions(null);
|
||||
return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function<LocalQuickFix, SuppressIntentionAction>() {
|
||||
@Override
|
||||
public SuppressIntentionAction fun(final LocalQuickFix fix) {
|
||||
return InspectionManagerEx.convertBatchToSuppressIntentionAction((SuppressQuickFix)fix);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
@NotNull
|
||||
public String getDescriptionFileName() {
|
||||
return getShortName() + ".html";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final String getFolderName() {
|
||||
return getShortName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Class<? extends InspectionProfileEntry> getDescriptionContextClass() {
|
||||
return getTool().getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMainToolId() {
|
||||
return getTool().getMainToolId();
|
||||
}
|
||||
@@ -238,8 +220,12 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
return getShortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
myContext = null;
|
||||
getTool().cleanup();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context);
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class InspectionToolsRegistrarCore {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolsRegistrarCore");
|
||||
static Object instantiateTool(@NotNull Class<?> toolClass) {
|
||||
try {
|
||||
Constructor<?> constructor = toolClass.getDeclaredConstructor(ArrayUtil.EMPTY_CLASS_ARRAY);
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY);
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
@@ -39,21 +38,21 @@ public class ScopeToolState {
|
||||
private NamedScope myScope;
|
||||
@NotNull
|
||||
private final String myScopeName;
|
||||
private /*InspectionToolWrapper*/InspectionProfileEntry myTool;
|
||||
private InspectionToolWrapper myToolWrapper;
|
||||
private boolean myEnabled;
|
||||
private HighlightDisplayLevel myLevel;
|
||||
|
||||
private JComponent myAdditionalConfigPanel;
|
||||
private static final Logger LOG = Logger.getInstance("#" + ScopeToolState.class.getName());
|
||||
|
||||
public ScopeToolState(@NotNull NamedScope scope, @NotNull InspectionProfileEntry tool, boolean enabled, @NotNull HighlightDisplayLevel level) {
|
||||
this(scope.getName(), tool, enabled, level);
|
||||
public ScopeToolState(@NotNull NamedScope scope, @NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {
|
||||
this(scope.getName(), toolWrapper, enabled, level);
|
||||
myScope = scope;
|
||||
}
|
||||
|
||||
public ScopeToolState(@NotNull String scopeName, @NotNull InspectionProfileEntry tool, boolean enabled, @NotNull HighlightDisplayLevel level) {
|
||||
public ScopeToolState(@NotNull String scopeName, @NotNull InspectionToolWrapper toolWrapper, boolean enabled, @NotNull HighlightDisplayLevel level) {
|
||||
myScopeName = scopeName;
|
||||
myTool = tool;
|
||||
myToolWrapper = toolWrapper;
|
||||
myEnabled = enabled;
|
||||
myLevel = level;
|
||||
}
|
||||
@@ -73,10 +72,9 @@ public class ScopeToolState {
|
||||
return myScopeName;
|
||||
}
|
||||
|
||||
// InspectionToolWrapper
|
||||
@NotNull
|
||||
public InspectionProfileEntry getTool() {
|
||||
return myTool;
|
||||
public InspectionToolWrapper getTool() {
|
||||
return myToolWrapper;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
@@ -96,40 +94,37 @@ public class ScopeToolState {
|
||||
myLevel = level;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public JComponent getAdditionalConfigPanel() {
|
||||
if (myAdditionalConfigPanel == null){
|
||||
myAdditionalConfigPanel = myTool.createOptionsPanel();
|
||||
if (myAdditionalConfigPanel == null) {
|
||||
myAdditionalConfigPanel = myToolWrapper.getTool().createOptionsPanel();
|
||||
if (myAdditionalConfigPanel == null){
|
||||
myAdditionalConfigPanel = new JPanel();
|
||||
}
|
||||
return myAdditionalConfigPanel;
|
||||
}
|
||||
return myAdditionalConfigPanel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void resetConfigPanel(){
|
||||
myAdditionalConfigPanel = null;
|
||||
}
|
||||
|
||||
public void setTool(@NotNull InspectionProfileEntry tool) {
|
||||
myTool = tool;
|
||||
public void setTool(@NotNull InspectionToolWrapper tool) {
|
||||
myToolWrapper = tool;
|
||||
}
|
||||
|
||||
public boolean equalTo(ScopeToolState state2) {
|
||||
public boolean equalTo(@NotNull ScopeToolState state2) {
|
||||
if (isEnabled() != state2.isEnabled()) return false;
|
||||
if (getLevel() != state2.getLevel()) return false;
|
||||
InspectionProfileEntry tool = getTool();
|
||||
InspectionProfileEntry tool2 = state2.getTool();
|
||||
if (!tool.isInitialized() && !tool2.isInitialized()) return true;
|
||||
InspectionToolWrapper toolWrapper = getTool();
|
||||
InspectionToolWrapper toolWrapper2 = state2.getTool();
|
||||
if (!toolWrapper.isInitialized() && !toolWrapper2.isInitialized()) return true;
|
||||
try {
|
||||
@NonNls String tempRoot = "root";
|
||||
Element oldToolSettings = new Element(tempRoot);
|
||||
tool.writeSettings(oldToolSettings);
|
||||
toolWrapper.getTool().writeSettings(oldToolSettings);
|
||||
Element newToolSettings = new Element(tempRoot);
|
||||
tool2.writeSettings(newToolSettings);
|
||||
toolWrapper2.getTool().writeSettings(newToolSettings);
|
||||
return JDOMUtil.areElementsEqual(oldToolSettings, newToolSettings);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,13 +27,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public interface Tools {
|
||||
InspectionProfileEntry getInspectionTool(PsiElement element);
|
||||
@NotNull
|
||||
InspectionToolWrapper getInspectionTool(PsiElement element);
|
||||
|
||||
@NotNull
|
||||
String getShortName();
|
||||
|
||||
@NotNull
|
||||
InspectionProfileEntry getTool();
|
||||
InspectionToolWrapper getTool();
|
||||
|
||||
@NotNull
|
||||
List<ScopeToolState> getTools();
|
||||
@@ -47,5 +47,5 @@ public interface Tools {
|
||||
boolean isEnabled(@Nullable PsiElement element);
|
||||
|
||||
@Nullable
|
||||
InspectionProfileEntry getEnabledTool(@Nullable PsiElement element);
|
||||
InspectionToolWrapper getEnabledTool(@Nullable PsiElement element);
|
||||
}
|
||||
+2
-3
@@ -21,7 +21,7 @@
|
||||
package com.intellij.codeInspection.lang;
|
||||
|
||||
import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.Tools;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,8 +35,7 @@ public interface GlobalInspectionContextExtension<T> {
|
||||
void performPreRunActivities(@NotNull List<Tools> globalTools,
|
||||
@NotNull List<Tools> localTools,
|
||||
@NotNull GlobalInspectionContext context);
|
||||
//InspectionToolWrapper
|
||||
void performPostRunActivities(@NotNull List<InspectionProfileEntry> inspections, @NotNull GlobalInspectionContext context);
|
||||
void performPostRunActivities(@NotNull List<InspectionToolWrapper> inspections, @NotNull GlobalInspectionContext context);
|
||||
|
||||
void cleanup();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,11 @@ package com.intellij.codeInspection.reference;
|
||||
|
||||
import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Application component which provides utility methods for working with the reference
|
||||
@@ -36,4 +40,13 @@ public class RefUtil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean contains(RefEntity element, @NotNull Collection<RefEntity> entities){
|
||||
for (RefEntity refEntity : entities) {
|
||||
if (Comparing.equal(refEntity, element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public interface Profile extends JDOMExternalizable, Comparable, Scheme {
|
||||
boolean isLocal();
|
||||
|
||||
void setName(@NotNull String name);
|
||||
@NotNull
|
||||
String getName();
|
||||
|
||||
void setProfileManager(@NotNull ProfileManager profileManager);
|
||||
@NotNull
|
||||
|
||||
+9
-10
@@ -19,18 +19,18 @@ package com.intellij.codeInsight.daemon;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
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;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManagerImpl;
|
||||
import com.intellij.profile.codeInspection.SeverityProvider;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -68,7 +68,7 @@ public class InspectionProfileConvertor {
|
||||
renameOldDefaultsProfile();
|
||||
}
|
||||
|
||||
private boolean retrieveOldSettings(Element element) {
|
||||
private boolean retrieveOldSettings(@NotNull Element element) {
|
||||
boolean hasOldSettings = false;
|
||||
for (final Object obj : element.getChildren(OPTION_TAG)) {
|
||||
Element option = (Element)obj;
|
||||
@@ -87,7 +87,7 @@ public class InspectionProfileConvertor {
|
||||
Element e = (Element)o;
|
||||
String key = e.getName();
|
||||
String levelName = e.getAttributeValue(LEVEL_ATT);
|
||||
HighlightSeverity severity = ((InspectionProfileManagerImpl)myManager).getSeverityRegistrar().getSeverity(levelName);
|
||||
HighlightSeverity severity = ((SeverityProvider)myManager).getSeverityRegistrar().getSeverity(levelName);
|
||||
HighlightDisplayLevel level = severity == null ? null : HighlightDisplayLevel.find(severity);
|
||||
if (level == null) continue;
|
||||
myDisplayLevelMap.put(key, level);
|
||||
@@ -97,9 +97,8 @@ public class InspectionProfileConvertor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void storeEditorHighlightingProfile(Element element) {
|
||||
public void storeEditorHighlightingProfile(@NotNull Element element, @NotNull InspectionProfile editorProfile) {
|
||||
if (retrieveOldSettings(element)) {
|
||||
final InspectionProfileImpl editorProfile = new InspectionProfileImpl(OLD_HIGHTLIGHTING_SETTINGS_PROFILE);
|
||||
|
||||
final ModifiableModel editorProfileModel = editorProfile.getModifiableModel();
|
||||
|
||||
@@ -116,7 +115,7 @@ 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 InspectionToolWrapper[] tools = (InspectionToolWrapper[])profile.getInspectionTools(null);
|
||||
final InspectionToolWrapper[] tools = profile.getInspectionTools(null);
|
||||
for (final Object o : profileFile.getChildren(INSP_TOOL_TAG)) {
|
||||
Element toolElement = ((Element)o).clone();
|
||||
String toolClassName = toolElement.getAttributeValue(CLASS_ATT);
|
||||
@@ -162,7 +161,7 @@ public class InspectionProfileConvertor {
|
||||
}
|
||||
|
||||
protected void fillErrorLevels(final ModifiableModel profile) {
|
||||
InspectionToolWrapper[] toolWrappers = (InspectionToolWrapper[])profile.getInspectionTools(null);
|
||||
InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(null);
|
||||
LOG.assertTrue(toolWrappers != null, "Profile was not correctly init");
|
||||
//fill error levels
|
||||
for (final String shortName : myDisplayLevelMap.keySet()) {
|
||||
@@ -175,13 +174,13 @@ public class InspectionProfileConvertor {
|
||||
|
||||
//set up tools for default profile
|
||||
if (level != HighlightDisplayLevel.DO_NOT_SHOW) {
|
||||
profile.enableTool(shortName, null);
|
||||
profile.enableTool(shortName, null, null);
|
||||
}
|
||||
|
||||
if (level == null || level == HighlightDisplayLevel.DO_NOT_SHOW) {
|
||||
level = HighlightDisplayLevel.WARNING;
|
||||
}
|
||||
profile.setErrorLevel(key, level);
|
||||
profile.setErrorLevel(key, level, null);
|
||||
}
|
||||
}
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.GlobalInspectionTool;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.reference.RefGraphAnnotator;
|
||||
import com.intellij.codeInspection.reference.RefManagerImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 28-Dec-2005
|
||||
*/
|
||||
public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalInspectionTool, InspectionEP> {
|
||||
public GlobalInspectionToolWrapper(@NotNull GlobalInspectionTool globalInspectionTool) {
|
||||
super(globalInspectionTool);
|
||||
}
|
||||
|
||||
public GlobalInspectionToolWrapper(@NotNull InspectionEP ep) {
|
||||
super(ep);
|
||||
}
|
||||
|
||||
private GlobalInspectionToolWrapper(@NotNull GlobalInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalInspectionToolWrapper createCopy() {
|
||||
return new GlobalInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull GlobalInspectionContext context) {
|
||||
super.initialize(context);
|
||||
RefManagerImpl refManager = (RefManagerImpl)context.getRefManager();
|
||||
final RefGraphAnnotator annotator = getTool().getAnnotator(refManager);
|
||||
if (annotator != null) {
|
||||
refManager.registerGraphAnnotator(annotator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context) {
|
||||
final JobDescriptor[] additionalJobs = getTool().getAdditionalJobs();
|
||||
if (additionalJobs == null) {
|
||||
return getTool().isGraphNeeded() ? context.getStdJobDescriptors().BUILD_GRAPH_ONLY : JobDescriptor.EMPTY_ARRAY;
|
||||
}
|
||||
else {
|
||||
return getTool().isGraphNeeded() ? ArrayUtil.append(additionalJobs, context.getStdJobDescriptors().BUILD_GRAPH) : additionalJobs;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean worksInBatchModeOnly() {
|
||||
return getTool().worksInBatchModeOnly();
|
||||
}
|
||||
}
|
||||
+110
-122
@@ -19,17 +19,18 @@ package com.intellij.codeInspection.ex;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.InspectionProfileConvertor;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ModifiableModel;
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.options.ExternalInfo;
|
||||
import com.intellij.openapi.options.ExternalizableScheme;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.profile.DefaultProjectProfileManager;
|
||||
import com.intellij.profile.ProfileEx;
|
||||
@@ -123,24 +124,27 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InspectionProfileImpl createSimple(@NotNull String name, @NotNull final InspectionToolWrapper ... toolWrappers) {
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar(null) {
|
||||
public static InspectionProfileImpl createSimple(@NotNull String name,
|
||||
@NotNull Project project,
|
||||
@NotNull final InspectionToolWrapper... toolWrappers) {
|
||||
InspectionToolRegistrar registrar = new InspectionToolRegistrar() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
return Arrays.asList(toolWrappers);
|
||||
}
|
||||
}, InspectionProfileManager.getInstance());
|
||||
};
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl(name, registrar, InspectionProfileManager.getInstance());
|
||||
boolean init = INIT_INSPECTIONS;
|
||||
try {
|
||||
INIT_INSPECTIONS = true;
|
||||
profile.initialize(null);
|
||||
profile.initialize(project);
|
||||
}
|
||||
finally {
|
||||
INIT_INSPECTIONS = init;
|
||||
}
|
||||
for (InspectionToolWrapper toolWrapper : toolWrappers) {
|
||||
profile.enableTool(toolWrapper.getShortName());
|
||||
profile.enableTool(toolWrapper.getShortName(), project);
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
@@ -176,14 +180,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProperSetting(@NotNull HighlightDisplayKey key) {
|
||||
return isProperSetting(key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProperSetting(String toolId) {
|
||||
public boolean isProperSetting(@NotNull String toolId) {
|
||||
if (myBaseProfile != null) {
|
||||
final Tools tools = myBaseProfile.getTools(toolId);
|
||||
final Tools tools = myBaseProfile.getTools(toolId, null);
|
||||
final Tools currentTools = myTools.get(toolId);
|
||||
return !Comparing.equal(tools, currentTools);
|
||||
}
|
||||
@@ -191,28 +190,30 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetToBase() {
|
||||
initInspectionTools(null);
|
||||
public void resetToBase(Project project) {
|
||||
initInspectionTools(project);
|
||||
|
||||
copyToolsConfigurations(myBaseProfile, null);
|
||||
copyToolsConfigurations(myBaseProfile, project);
|
||||
myDisplayLevelMap = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetToEmpty() {
|
||||
public void resetToEmpty(Project project) {
|
||||
initInspectionTools(project);
|
||||
final InspectionToolWrapper[] profileEntries = getInspectionTools(null);
|
||||
for (InspectionToolWrapper toolWrapper : profileEntries) {
|
||||
disableTool(toolWrapper.getShortName());
|
||||
disableTool(toolWrapper.getShortName(), project);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) {
|
||||
final ToolsImpl tools = getTools(inspectionToolKey.toString());
|
||||
Project project = element == null ? null : element.getProject();
|
||||
final ToolsImpl tools = getTools(inspectionToolKey.toString(), project);
|
||||
HighlightDisplayLevel level = tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
|
||||
if (!((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().isSeverityValid(level.getSeverity().toString())) {
|
||||
level = HighlightDisplayLevel.WARNING;
|
||||
setErrorLevel(inspectionToolKey, level);
|
||||
setErrorLevel(inspectionToolKey, level, project);
|
||||
}
|
||||
return level;
|
||||
}
|
||||
@@ -312,15 +313,17 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
}
|
||||
|
||||
public void collectDependentInspections(@NotNull InspectionToolWrapper toolWrapper, @NotNull Set<InspectionToolWrapper> dependentEntries) {
|
||||
public void collectDependentInspections(@NotNull InspectionToolWrapper toolWrapper,
|
||||
@NotNull Set<InspectionToolWrapper> dependentEntries,
|
||||
Project project) {
|
||||
String mainToolId = toolWrapper.getMainToolId();
|
||||
|
||||
if (mainToolId != null) {
|
||||
InspectionToolWrapper dependentEntryWrapper = getInspectionTool(mainToolId);
|
||||
InspectionToolWrapper dependentEntryWrapper = getInspectionTool(mainToolId, project);
|
||||
|
||||
if (dependentEntryWrapper != null) {
|
||||
if (!dependentEntries.add(dependentEntryWrapper)) {
|
||||
collectDependentInspections(dependentEntryWrapper, dependentEntries);
|
||||
collectDependentInspections(dependentEntryWrapper, dependentEntries, project);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -332,15 +335,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
@Override
|
||||
@Nullable
|
||||
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
|
||||
final Tools toolList = getTools(shortName);
|
||||
return toolList != null ? (InspectionToolWrapper)toolList.getInspectionTool(element) : null;
|
||||
final Tools toolList = getTools(shortName, element.getProject());
|
||||
return toolList == null ? null : toolList.getInspectionTool(element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element) {
|
||||
InspectionToolWrapper tool = getInspectionTool(shortName, element);
|
||||
return tool == null ? tool : tool.getTool();
|
||||
return tool == null ? null : tool.getTool();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -377,15 +380,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public InspectionToolWrapper getInspectionTool(@NotNull String shortName) {
|
||||
final ToolsImpl tools = getTools(shortName);
|
||||
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, Project project) {
|
||||
final ToolsImpl tools = getTools(shortName, project);
|
||||
return tools != null? tools.getTool() : null;
|
||||
}
|
||||
|
||||
public InspectionToolWrapper getToolById(@NotNull String id, @NotNull PsiElement element) {
|
||||
initInspectionTools(element.getProject());
|
||||
for (Tools toolList : myTools.values()) {
|
||||
final InspectionToolWrapper tool = (InspectionToolWrapper)toolList.getInspectionTool(element);
|
||||
final InspectionToolWrapper tool = toolList.getInspectionTool(element);
|
||||
String toolId =
|
||||
tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getID() : tool.getShortName();
|
||||
if (id.equals(toolId)) return tool;
|
||||
@@ -411,7 +414,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
|
||||
@Override
|
||||
public void scopesChanged() {
|
||||
for (ScopeToolState toolState : getAllTools()) {
|
||||
for (ScopeToolState toolState : getAllTools(null)) {
|
||||
toolState.scopesChanged();
|
||||
}
|
||||
InspectionProfileManager.getInstance().fireProfileChanged(this);
|
||||
@@ -422,21 +425,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
myEnabledTool = displayName;
|
||||
}
|
||||
|
||||
public void load(@NotNull Element element) {
|
||||
try {
|
||||
readExternal(element);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Messages.showErrorDialog(InspectionsBundle.message("inspection.error.loading.message", 0, getName()),
|
||||
InspectionsBundle.message("inspection.errors.occurred.dialog.title"));
|
||||
}
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileLocked() {
|
||||
return myLockedProfile;
|
||||
@@ -450,10 +438,10 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
@Override
|
||||
@NotNull
|
||||
public InspectionToolWrapper[] getInspectionTools(@Nullable PsiElement element) {
|
||||
initInspectionTools(element != null ? element.getProject() : null);
|
||||
initInspectionTools(element == null ? null : element.getProject());
|
||||
List<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
|
||||
for (Tools toolList : myTools.values()) {
|
||||
result.add((InspectionToolWrapper)toolList.getInspectionTool(element));
|
||||
result.add(toolList.getInspectionTool(element));
|
||||
}
|
||||
return result.toArray(new InspectionToolWrapper[result.size()]);
|
||||
}
|
||||
@@ -472,21 +460,21 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableTool(String toolId, PsiElement element) {
|
||||
getTools(toolId).disableTool(element);
|
||||
public void disableTool(@NotNull String toolId, @NotNull PsiElement element) {
|
||||
getTools(toolId, element.getProject()).disableTool(element);
|
||||
}
|
||||
|
||||
public void disableToolByDefault(String toolId) {
|
||||
getToolDefaultState(toolId).setEnabled(false);
|
||||
public void disableToolByDefault(String toolId, Project project) {
|
||||
getToolDefaultState(toolId, project).setEnabled(false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ScopeToolState getToolDefaultState(String toolId) {
|
||||
return getTools(toolId).getDefaultState();
|
||||
public ScopeToolState getToolDefaultState(String toolId, Project project) {
|
||||
return getTools(toolId, project).getDefaultState();
|
||||
}
|
||||
|
||||
public void enableToolByDefault(String toolId) {
|
||||
getToolDefaultState(toolId).setEnabled(true);
|
||||
public void enableToolByDefault(String toolId, Project project) {
|
||||
getToolDefaultState(toolId, project).setEnabled(true);
|
||||
}
|
||||
|
||||
public boolean wasInitialized() {
|
||||
@@ -509,7 +497,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
|
||||
final List<InspectionToolWrapper> tools;
|
||||
try {
|
||||
tools = createTools();
|
||||
tools = createTools(project);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
return false;
|
||||
@@ -535,7 +523,7 @@ 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) : toolWrapper.getDefaultLevel();
|
||||
HighlightDisplayLevel level = myBaseProfile != null ? myBaseProfile.getErrorLevel(key, project) : 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());
|
||||
@@ -556,21 +544,21 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<InspectionToolWrapper> createTools() {
|
||||
private List<InspectionToolWrapper> createTools(Project project) {
|
||||
if (mySource != null) {
|
||||
return ContainerUtil.map(mySource.getAllTools(), new Function<ScopeToolState, InspectionToolWrapper>() {
|
||||
return ContainerUtil.map(mySource.getAllTools(project), new Function<ScopeToolState, InspectionToolWrapper>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionToolWrapper fun(@NotNull ScopeToolState state) {
|
||||
return (InspectionToolWrapper)state.getTool();
|
||||
return state.getTool();
|
||||
}
|
||||
});
|
||||
}
|
||||
return myRegistrar.createTools();
|
||||
}
|
||||
|
||||
private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key) {
|
||||
final ToolsImpl tools = getTools(key.toString());
|
||||
private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, Project project) {
|
||||
final ToolsImpl tools = getTools(key.toString(), project);
|
||||
LOG.assertTrue(tools != null, "profile name: " + myName + " base profile: " + (myBaseProfile != null ? myBaseProfile.getName() : "-") + " key: " + key);
|
||||
return tools.getLevel();
|
||||
}
|
||||
@@ -595,14 +583,14 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
for (ToolsImpl toolList : profile.myTools.values()) {
|
||||
final ToolsImpl tools = myTools.get(toolList.getShortName());
|
||||
final ScopeToolState defaultState = toolList.getDefaultState();
|
||||
tools.setDefaultState(copyToolSettings((InspectionToolWrapper)defaultState.getTool()), defaultState.isEnabled(), defaultState.getLevel());
|
||||
tools.setDefaultState(copyToolSettings(defaultState.getTool()), defaultState.isEnabled(), defaultState.getLevel());
|
||||
tools.removeAllScopes();
|
||||
tools.setEnabled(toolList.isEnabled());
|
||||
final List<ScopeToolState> nonDefaultToolStates = toolList.getNonDefaultTools();
|
||||
if (nonDefaultToolStates != null) {
|
||||
for (ScopeToolState state : nonDefaultToolStates) {
|
||||
final InspectionToolWrapper toolWrapper = copyToolSettings((InspectionToolWrapper)state.getTool());
|
||||
final NamedScope scope = project != null ? state.getScope(project) : ScopeToolStateUtil.getScope(state);
|
||||
final InspectionToolWrapper toolWrapper = copyToolSettings(state.getTool());
|
||||
final NamedScope scope = state.getScope(project);
|
||||
if (scope != null) {
|
||||
tools.addTool(scope, toolWrapper, state.isEnabled(), state.getLevel());
|
||||
}
|
||||
@@ -622,14 +610,14 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static InspectionToolWrapper copyToolSettings(@NotNull InspectionToolWrapper tool)
|
||||
private static InspectionToolWrapper copyToolSettings(@NotNull InspectionToolWrapper toolWrapper)
|
||||
throws WriteExternalException, InvalidDataException {
|
||||
final InspectionToolWrapper inspectionTool = tool.createCopy();
|
||||
if (tool.isInitialized()) {
|
||||
final InspectionToolWrapper inspectionTool = toolWrapper.createCopy();
|
||||
if (toolWrapper.isInitialized()) {
|
||||
@NonNls String tempRoot = "config";
|
||||
Element config = new Element(tempRoot);
|
||||
tool.writeSettings(config);
|
||||
inspectionTool.readSettings(config);
|
||||
toolWrapper.getTool().writeSettings(config);
|
||||
inspectionTool.getTool().readSettings(config);
|
||||
}
|
||||
return inspectionTool;
|
||||
}
|
||||
@@ -646,8 +634,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
}
|
||||
|
||||
public void enableTool(@NotNull String inspectionTool) {
|
||||
final ToolsImpl tools = getTools(inspectionTool);
|
||||
public void enableTool(@NotNull String inspectionTool, Project project) {
|
||||
final ToolsImpl tools = getTools(inspectionTool, project);
|
||||
tools.setEnabled(true);
|
||||
if (tools.getNonDefaultTools() == null) {
|
||||
tools.getDefaultState().setEnabled(true);
|
||||
@@ -655,19 +643,19 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableTool(String inspectionTool, NamedScope namedScope) {
|
||||
getTools(inspectionTool).enableTool(namedScope);
|
||||
public void enableTool(String inspectionTool, NamedScope namedScope, Project project) {
|
||||
getTools(inspectionTool, project).enableTool(namedScope, project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableTool(String inspectionTool, NamedScope namedScope) {
|
||||
getTools(inspectionTool).disableTool(namedScope);
|
||||
public void disableTool(String inspectionTool, NamedScope namedScope, @NotNull Project project) {
|
||||
getTools(inspectionTool, project).disableTool(namedScope, project);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void disableTool(String inspectionTool) {
|
||||
final ToolsImpl tools = getTools(inspectionTool);
|
||||
public void disableTool(String inspectionTool, Project project) {
|
||||
final ToolsImpl tools = getTools(inspectionTool, project);
|
||||
tools.setEnabled(false);
|
||||
if (tools.getNonDefaultTools() == null) {
|
||||
tools.getDefaultState().setEnabled(false);
|
||||
@@ -675,8 +663,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level) {
|
||||
getTools(key.toString()).setLevel(level);
|
||||
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, Project project) {
|
||||
getTools(key.toString(), project).setLevel(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -684,18 +672,18 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
if (key == null) {
|
||||
return false;
|
||||
}
|
||||
final Tools toolState = getTools(key.toString());
|
||||
final Tools toolState = getTools(key.toString(), element == null ? null : element.getProject());
|
||||
return toolState != null && toolState.isEnabled(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToolEnabled(HighlightDisplayKey key) {
|
||||
return isToolEnabled(key, (PsiElement)null);
|
||||
return isToolEnabled(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExecutable() {
|
||||
initInspectionTools(null);
|
||||
public boolean isExecutable(Project project) {
|
||||
initInspectionTools(project);
|
||||
for (Tools tools : myTools.values()) {
|
||||
if (tools.isEnabled()) return true;
|
||||
}
|
||||
@@ -712,7 +700,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
private void commit(@NotNull InspectionProfileImpl inspectionProfile) {
|
||||
myName = inspectionProfile.myName;
|
||||
setName(inspectionProfile.getName());
|
||||
myLocal = inspectionProfile.myLocal;
|
||||
myLockedProfile = inspectionProfile.myLockedProfile;
|
||||
myDisplayLevelMap = inspectionProfile.myDisplayLevelMap;
|
||||
@@ -749,8 +737,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(@NotNull Element element) {
|
||||
initInspectionTools(null);
|
||||
public void convert(@NotNull Element element, @NotNull Project project) {
|
||||
initInspectionTools(project);
|
||||
final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
|
||||
if (scopes == null) {
|
||||
return;
|
||||
@@ -768,8 +756,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(wrapper.getShortName());
|
||||
try {
|
||||
InspectionToolWrapper toolWrapper = copyToolSettings(wrapper);
|
||||
getTools(wrapper.getShortName())
|
||||
.addTool(scope, toolWrapper, inspectionProfile.isToolEnabled(key), inspectionProfile.getErrorLevel(key, (NamedScope)null));
|
||||
HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project);
|
||||
getTools(wrapper.getShortName(), project).addTool(scope, toolWrapper, inspectionProfile.isToolEnabled(key), errorLevel);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
@@ -810,8 +798,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ScopeToolState> getAllTools() {
|
||||
initInspectionTools(null);
|
||||
public List<ScopeToolState> getAllTools(Project project) {
|
||||
initInspectionTools(project);
|
||||
final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
|
||||
for (Tools tools : myTools.values()) {
|
||||
result.addAll(tools.getTools());
|
||||
@@ -820,8 +808,8 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ScopeToolState> getDefaultStates() {
|
||||
initInspectionTools(null);
|
||||
public List<ScopeToolState> getDefaultStates(Project project) {
|
||||
initInspectionTools(project);
|
||||
final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
|
||||
for (Tools tools : myTools.values()) {
|
||||
result.add(tools.getDefaultState());
|
||||
@@ -830,33 +818,29 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ScopeToolState> getNonDefaultTools(String shortName) {
|
||||
public List<ScopeToolState> getNonDefaultTools(String shortName, Project project) {
|
||||
final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
|
||||
final List<ScopeToolState> nonDefaultTools = getTools(shortName).getNonDefaultTools();
|
||||
final List<ScopeToolState> nonDefaultTools = getTools(shortName, project).getNonDefaultTools();
|
||||
if (nonDefaultTools != null) {
|
||||
result.addAll(nonDefaultTools);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isToolEnabled(@NotNull HighlightDisplayKey key, NamedScope namedScope) {
|
||||
return getTools(key.toString()).isEnabled(namedScope);
|
||||
public boolean isToolEnabled(@NotNull HighlightDisplayKey key, NamedScope namedScope, Project project) {
|
||||
return getTools(key.toString(), project).isEnabled(namedScope,project);
|
||||
}
|
||||
|
||||
public void removeScope(String toolId, int scopeIdx) {
|
||||
getTools(toolId).removeScope(scopeIdx);
|
||||
public void removeScope(String toolId, int scopeIdx, Project project) {
|
||||
getTools(toolId, project).removeScope(scopeIdx);
|
||||
}
|
||||
|
||||
public void removeAllScopes(String toolId) {
|
||||
getTools(toolId).removeAllScopes();
|
||||
public void removeAllScopes(String toolId, Project project) {
|
||||
getTools(toolId, project).removeAllScopes();
|
||||
}
|
||||
|
||||
public void setScope(String toolId, int idx, NamedScope namedScope) {
|
||||
getTools(toolId).setScope(idx, namedScope);
|
||||
}
|
||||
|
||||
public void moveScope(String toolId, int idx, int dir) {
|
||||
getTools(toolId).moveScope(idx, dir);
|
||||
public void moveScope(String toolId, int idx, int dir, Project project) {
|
||||
getTools(toolId, project).moveScope(idx, dir);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -876,33 +860,37 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, NamedScope scope) {
|
||||
final ToolsImpl tools = getTools(key.toString());
|
||||
return tools != null ? tools.getLevel(scope) : HighlightDisplayLevel.WARNING;
|
||||
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, NamedScope scope, Project project) {
|
||||
final ToolsImpl tools = getTools(key.toString(), project);
|
||||
return tools != null ? tools.getLevel(scope, project) : HighlightDisplayLevel.WARNING;
|
||||
}
|
||||
|
||||
public ScopeToolState addScope(@NotNull InspectionToolWrapper toolWrapper, NamedScope scope, @NotNull HighlightDisplayLevel level, boolean enabled) {
|
||||
return getTools(toolWrapper.getShortName()).prependTool(scope, toolWrapper, enabled, level);
|
||||
public ScopeToolState addScope(@NotNull InspectionToolWrapper toolWrapper,
|
||||
NamedScope scope,
|
||||
@NotNull HighlightDisplayLevel level,
|
||||
boolean enabled,
|
||||
Project project) {
|
||||
return getTools(toolWrapper.getShortName(), project).prependTool(scope, toolWrapper, enabled, level);
|
||||
}
|
||||
|
||||
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, int scopeIdx) {
|
||||
getTools(key.toString()).setLevel(level, scopeIdx);
|
||||
public void setErrorLevel(@NotNull HighlightDisplayKey key, @NotNull HighlightDisplayLevel level, int scopeIdx, Project project) {
|
||||
getTools(key.toString(), project).setLevel(level, scopeIdx, project);
|
||||
}
|
||||
|
||||
private ToolsImpl getTools(@NotNull String toolId) {
|
||||
initInspectionTools(null);
|
||||
private ToolsImpl getTools(String toolId, Project project) {
|
||||
initInspectionTools(project);
|
||||
return myTools.get(toolId);
|
||||
}
|
||||
|
||||
public void enableAllTools() {
|
||||
public void enableAllTools(Project project) {
|
||||
for (InspectionToolWrapper entry : getInspectionTools(null)) {
|
||||
enableTool(entry.getShortName());
|
||||
enableTool(entry.getShortName(), project);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableAllTools() {
|
||||
public void disableAllTools(Project project) {
|
||||
for (InspectionToolWrapper entry : getInspectionTools(null)) {
|
||||
disableTool(entry.getShortName());
|
||||
disableTool(entry.getShortName(), project);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-9
@@ -52,19 +52,19 @@ public class InspectionProfileWrapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionProfileEntry[] getInspectionTools(PsiElement element){
|
||||
public InspectionToolWrapper[] getInspectionTools(PsiElement element){
|
||||
return myProfile.getInspectionTools(element);
|
||||
}
|
||||
|
||||
// check whether some inspection got registered twice by accident. 've bit once.
|
||||
private static boolean alreadyChecked;
|
||||
public static void checkInspectionsDuplicates(@NotNull InspectionProfileEntry[] tools) {
|
||||
public static void checkInspectionsDuplicates(@NotNull InspectionToolWrapper[] toolWrappers) {
|
||||
if (alreadyChecked) return;
|
||||
alreadyChecked = true;
|
||||
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");
|
||||
Set<InspectionProfileEntry> uniqTools = new THashSet<InspectionProfileEntry>(toolWrappers.length);
|
||||
for (InspectionToolWrapper toolWrapper : toolWrappers) {
|
||||
if (!uniqTools.add(toolWrapper.getTool())) {
|
||||
LOG.error("Inspection " + toolWrapper.getDisplayName() + " (" + toolWrapper.getTool().getClass() + ") already registered");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,12 +81,11 @@ public class InspectionProfileWrapper {
|
||||
return myProfile.isToolEnabled(key);
|
||||
}
|
||||
|
||||
// InspectionToolWrapper
|
||||
public InspectionProfileEntry getInspectionTool(final String shortName, PsiElement element) {
|
||||
public InspectionToolWrapper getInspectionTool(final String shortName, PsiElement element) {
|
||||
return myProfile.getInspectionTool(shortName, element);
|
||||
}
|
||||
|
||||
public void init(final Project project) {
|
||||
public void init(@NotNull Project project) {
|
||||
final List<Tools> profileEntries = myProfile.getAllEnabledInspectionTools(project);
|
||||
for (Tools profileEntry : profileEntries) {
|
||||
for (ScopeToolState toolState : profileEntry.getTools()) {
|
||||
|
||||
+27
-134
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,32 +17,21 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.ui.search.SearchableOptionsRegistrar;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.profile.codeInspection.ui.InspectionToolsConfigurable;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -52,19 +41,8 @@ public class InspectionToolRegistrar {
|
||||
|
||||
private final List<Factory<InspectionToolWrapper>> myInspectionToolFactories = new ArrayList<Factory<InspectionToolWrapper>>();
|
||||
|
||||
private final AtomicBoolean myToolsAreInitialized = new AtomicBoolean(false);
|
||||
private final AtomicBoolean myInspectionComponentsLoaded = new AtomicBoolean(false);
|
||||
|
||||
private static final Pattern HTML_PATTERN = Pattern.compile("<[^<>]*>");
|
||||
public final SearchableOptionsRegistrar myOptionsRegistrar;
|
||||
|
||||
private static final ExtensionPointName<InspectionEP> SPECIAL_TOOL = ExtensionPointName.create("com.intellij.specialTool");
|
||||
|
||||
|
||||
public InspectionToolRegistrar(SearchableOptionsRegistrar registrar) {
|
||||
myOptionsRegistrar = registrar;
|
||||
}
|
||||
|
||||
public void ensureInitialized() {
|
||||
if (!myInspectionComponentsLoaded.getAndSet(true)) {
|
||||
Set<InspectionToolProvider> providers = new THashSet<InspectionToolProvider>();
|
||||
@@ -87,17 +65,8 @@ public class InspectionToolRegistrar {
|
||||
}
|
||||
});
|
||||
}
|
||||
for (final InspectionEP ep : Extensions.getExtensions(SPECIAL_TOOL)) {
|
||||
myInspectionToolFactories.add(new Factory<InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper create() {
|
||||
return new CommonInspectionToolWrapper(ep);
|
||||
}
|
||||
});
|
||||
}
|
||||
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() {
|
||||
@@ -111,40 +80,33 @@ public class InspectionToolRegistrar {
|
||||
|
||||
@NotNull
|
||||
public static InspectionToolWrapper wrapTool(@NotNull InspectionProfileEntry profileEntry) {
|
||||
assert !(profileEntry instanceof InspectionToolWrapper) : profileEntry;
|
||||
if (profileEntry instanceof LocalInspectionTool) {
|
||||
return new LocalInspectionToolWrapper((LocalInspectionTool)profileEntry);
|
||||
}
|
||||
if (profileEntry instanceof GlobalInspectionTool) {
|
||||
return new GlobalInspectionToolWrapper((GlobalInspectionTool)profileEntry);
|
||||
}
|
||||
return new CommonInspectionToolWrapper((InspectionTool)profileEntry);
|
||||
throw new RuntimeException("unknown inspection class: " + profileEntry + "; "+profileEntry.getClass());
|
||||
}
|
||||
|
||||
public void registerTools(@NotNull InspectionToolProvider[] providers) {
|
||||
for (InspectionToolProvider provider : providers) {
|
||||
Class[] classes = provider.getInspectionClasses();
|
||||
for (Class aClass : classes) {
|
||||
registerInspectionTool(aClass, true);
|
||||
registerInspectionTool(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Factory<InspectionToolWrapper> registerInspectionTool(@NotNull final Class aClass, boolean store) {
|
||||
private Factory<InspectionToolWrapper> registerInspectionTool(@NotNull final Class aClass) {
|
||||
if (LocalInspectionTool.class.isAssignableFrom(aClass)) {
|
||||
return registerLocalInspection(aClass, store);
|
||||
return registerLocalInspection(aClass, true);
|
||||
}
|
||||
if (GlobalInspectionTool.class.isAssignableFrom(aClass)) {
|
||||
return registerGlobalInspection(aClass, store);
|
||||
return registerGlobalInspection(aClass, true);
|
||||
}
|
||||
ensureInitialized();
|
||||
return registerInspectionToolFactory(new Factory<InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper create() {
|
||||
return new CommonInspectionToolWrapper((InspectionTool)instantiateTool(aClass));
|
||||
}
|
||||
}, store);
|
||||
throw new RuntimeException("unknown inspection class: " + aClass);
|
||||
}
|
||||
|
||||
public static InspectionToolRegistrar getInstance() {
|
||||
@@ -167,7 +129,7 @@ public class InspectionToolRegistrar {
|
||||
return registerInspectionToolFactory(new Factory<InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper create() {
|
||||
return new LocalInspectionToolWrapper((LocalInspectionTool)instantiateTool(toolClass));
|
||||
return new LocalInspectionToolWrapper((LocalInspectionTool)InspectionToolsRegistrarCore.instantiateTool(toolClass));
|
||||
}
|
||||
}, store);
|
||||
}
|
||||
@@ -177,12 +139,13 @@ public class InspectionToolRegistrar {
|
||||
return registerInspectionToolFactory(new Factory<InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper create() {
|
||||
return new GlobalInspectionToolWrapper((GlobalInspectionTool) instantiateTool(aClass));
|
||||
return new GlobalInspectionToolWrapper((GlobalInspectionTool) InspectionToolsRegistrarCore.instantiateTool(aClass));
|
||||
}
|
||||
}, store);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@TestOnly
|
||||
public List<InspectionToolWrapper> createTools() {
|
||||
ensureInitialized();
|
||||
|
||||
@@ -191,7 +154,7 @@ public class InspectionToolRegistrar {
|
||||
for (final Factory<InspectionToolWrapper> factory : myInspectionToolFactories) {
|
||||
ProgressManager.checkCanceled();
|
||||
final InspectionToolWrapper toolWrapper = factory.create();
|
||||
if (toolWrapper != null && checkTool(toolWrapper)) {
|
||||
if (toolWrapper != null && checkTool(toolWrapper) == null) {
|
||||
tools.add(toolWrapper);
|
||||
}
|
||||
else {
|
||||
@@ -203,93 +166,23 @@ public class InspectionToolRegistrar {
|
||||
return tools;
|
||||
}
|
||||
|
||||
static Object instantiateTool(@NotNull Class<?> toolClass) {
|
||||
private static String checkTool(@NotNull final InspectionToolWrapper toolWrapper) {
|
||||
if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
|
||||
return null;
|
||||
}
|
||||
String message = null;
|
||||
try {
|
||||
Constructor<?> constructor = toolClass.getDeclaredConstructor(ArrayUtil.EMPTY_CLASS_ARRAY);
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY);
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildInspectionSearchIndexIfNecessary() {
|
||||
if (!myToolsAreInitialized.getAndSet(true)) {
|
||||
final Application app = ApplicationManager.getApplication();
|
||||
if (app.isUnitTestMode() || app.isHeadlessEnvironment()) return;
|
||||
|
||||
app.executeOnPooledThread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
List<InspectionToolWrapper> tools = createTools();
|
||||
for (InspectionToolWrapper tool : tools) {
|
||||
processText(tool.getDisplayName().toLowerCase(), tool);
|
||||
|
||||
final String description = tool.loadDescription();
|
||||
if (description != null) {
|
||||
@NonNls String descriptionText = HTML_PATTERN.matcher(description).replaceAll(" ");
|
||||
processText(descriptionText, tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void processText(@NotNull @NonNls String descriptionText, @NotNull InspectionToolWrapper tool) {
|
||||
if (ApplicationManager.getApplication().isDisposed()) return;
|
||||
LOG.assertTrue(myOptionsRegistrar != null);
|
||||
final Set<String> words = myOptionsRegistrar.getProcessedWordsWithoutStemming(descriptionText);
|
||||
for (String word : words) {
|
||||
myOptionsRegistrar.addOption(word, tool.getShortName(), tool.getDisplayName(), InspectionToolsConfigurable.ID, InspectionToolsConfigurable.DISPLAY_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkTool(@NotNull final InspectionToolWrapper toolWrapper) {
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
String message = null;
|
||||
try {
|
||||
final String id = ((LocalInspectionToolWrapper)toolWrapper).getID();
|
||||
if (id == null || !LocalInspectionTool.isValidID(id)) {
|
||||
message = InspectionsBundle.message("inspection.disabled.wrong.id", toolWrapper.getShortName(), id, LocalInspectionTool.VALID_ID_PATTERN);
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
message = InspectionsBundle.message("inspection.disabled.error", toolWrapper.getShortName(), t.getMessage());
|
||||
}
|
||||
if (message != null) {
|
||||
showNotification(message);
|
||||
return false;
|
||||
final String id = ((LocalInspectionToolWrapper)toolWrapper).getID();
|
||||
if (id == null || !LocalInspectionTool.isValidID(id)) {
|
||||
message = InspectionsBundle.message("inspection.disabled.wrong.id", toolWrapper.getShortName(), id, LocalInspectionTool.VALID_ID_PATTERN);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void showNotification(@NotNull final String message) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Notifications.Bus.notify(new Notification(InspectionManager.INSPECTION_GROUP_ID, InspectionsBundle.message("inspection.disabled.title"),
|
||||
message, NotificationType.ERROR));
|
||||
}
|
||||
});
|
||||
catch (Throwable t) {
|
||||
message = InspectionsBundle.message("inspection.disabled.error", toolWrapper.getShortName(), t.getMessage());
|
||||
}
|
||||
if (message != null) {
|
||||
LOG.error(message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspectionTool, LocalInspectionEP> {
|
||||
/** This should be used in tests primarily */
|
||||
@TestOnly
|
||||
public LocalInspectionToolWrapper(@NotNull LocalInspectionTool tool) {
|
||||
super(tool, ourEPMap.getValue().get(tool.getShortName()));
|
||||
}
|
||||
|
||||
public LocalInspectionToolWrapper(@NotNull LocalInspectionEP ep) {
|
||||
super(ep);
|
||||
}
|
||||
|
||||
private LocalInspectionToolWrapper(@NotNull LocalInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LocalInspectionToolWrapper createCopy() {
|
||||
return new LocalInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context) {
|
||||
return context.getStdJobDescriptors().LOCAL_ANALYSIS_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
public boolean isUnfair() {
|
||||
return myEP == null ? getTool() instanceof UnfairLocalInspectionTool : myEP.unfair;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return myEP == null ? getTool().getID() : myEP.id == null ? myEP.getShortName() : myEP.id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAlternativeID() {
|
||||
return myEP == null ? getTool().getAlternativeID() : myEP.alternativeId;
|
||||
}
|
||||
|
||||
public boolean runForWholeFile() {
|
||||
return myEP == null ? getTool().runForWholeFile() : myEP.runForWholeFile;
|
||||
}
|
||||
|
||||
private static final NotNullLazyValue<Map<String, LocalInspectionEP>> ourEPMap = new NotNullLazyValue<Map<String, LocalInspectionEP>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, LocalInspectionEP> compute() {
|
||||
HashMap<String, LocalInspectionEP> map = new HashMap<String, LocalInspectionEP>();
|
||||
for (LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
|
||||
map.put(ep.getShortName(), ep);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
|
||||
public static InspectionToolWrapper findTool2RunInBatch(@NotNull Project project, @Nullable PsiElement element, @NotNull String name) {
|
||||
final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
final InspectionToolWrapper toolWrapper = element == null
|
||||
? inspectionProfile.getInspectionTool(name, project)
|
||||
: inspectionProfile.getInspectionTool(name, element);
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)toolWrapper).isUnfair()) {
|
||||
final LocalInspectionTool inspectionTool = ((LocalInspectionToolWrapper)toolWrapper).getTool();
|
||||
if (inspectionTool instanceof PairedUnfairLocalInspectionTool) {
|
||||
final String oppositeShortName = ((PairedUnfairLocalInspectionTool)inspectionTool).getInspectionForBatchShortName();
|
||||
if (oppositeShortName != null) {
|
||||
return element == null
|
||||
? inspectionProfile.getInspectionTool(oppositeShortName, project)
|
||||
: inspectionProfile.getInspectionTool(oppositeShortName, element);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return toolWrapper;
|
||||
}
|
||||
}
|
||||
+34
-37
@@ -89,13 +89,14 @@ public class ToolsImpl implements Tools {
|
||||
return scopeToolState;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionToolWrapper getInspectionTool(PsiElement element) {
|
||||
if (myTools != null) {
|
||||
final Project project = element != null ? element.getProject() : null;
|
||||
for (ScopeToolState state : myTools) {
|
||||
if (element == null) {
|
||||
return (InspectionToolWrapper)state.getTool();
|
||||
return state.getTool();
|
||||
}
|
||||
else {
|
||||
final NamedScope scope = state.getScope(project);
|
||||
@@ -104,7 +105,7 @@ public class ToolsImpl implements Tools {
|
||||
if (packageSet != null) {
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile != null && packageSet.contains(containingFile, DependencyValidationManager.getInstance(project))) {
|
||||
return (InspectionToolWrapper)state.getTool();
|
||||
return state.getTool();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,11 +114,11 @@ public class ToolsImpl implements Tools {
|
||||
|
||||
for (ScopeToolState state : getTools()) {
|
||||
if (state.getScope(project) == null) {
|
||||
return (InspectionToolWrapper)state.getTool();
|
||||
return state.getTool();
|
||||
}
|
||||
}
|
||||
}
|
||||
return (InspectionToolWrapper)myDefaultState.getTool();
|
||||
return myDefaultState.getTool();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -130,7 +131,7 @@ public class ToolsImpl implements Tools {
|
||||
public List<InspectionToolWrapper> getAllTools() {
|
||||
List<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
|
||||
for (ScopeToolState state : getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
result.add(toolWrapper);
|
||||
}
|
||||
return result;
|
||||
@@ -143,16 +144,16 @@ 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()));
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
toolWrapper.writeSettings(scopeElement);
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
toolWrapper.getTool().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()));
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)myDefaultState.getTool();
|
||||
toolWrapper.writeSettings(inspectionElement);
|
||||
InspectionToolWrapper toolWrapper = myDefaultState.getTool();
|
||||
toolWrapper.getTool().writeSettings(inspectionElement);
|
||||
}
|
||||
|
||||
void readExternal(@NotNull Element toolElement, @NotNull InspectionProfile profile) throws InvalidDataException {
|
||||
@@ -170,7 +171,7 @@ public class ToolsImpl implements Tools {
|
||||
|
||||
final String enabledTool = toolElement.getAttributeValue(ENABLED_BY_DEFAULT_ATTRIBUTE);
|
||||
myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled);
|
||||
final InspectionToolWrapper tool = (InspectionToolWrapper)myDefaultState.getTool();
|
||||
final InspectionToolWrapper toolWrapper = myDefaultState.getTool();
|
||||
|
||||
final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
|
||||
for (Object sO : scopeElements) {
|
||||
@@ -186,10 +187,10 @@ public class ToolsImpl implements Tools {
|
||||
}
|
||||
final String errorLevel = scopeElement.getAttributeValue(LEVEL_ATTRIBUTE);
|
||||
final String enabledInScope = scopeElement.getAttributeValue(ENABLED_ATTRIBUTE);
|
||||
final InspectionToolWrapper copyToolWrapper = tool.createCopy();
|
||||
final InspectionToolWrapper copyToolWrapper = toolWrapper.createCopy();
|
||||
// check if unknown children exists
|
||||
if (scopeElement.getAttributes().size() > 3 || !scopeElement.getChildren().isEmpty()) {
|
||||
copyToolWrapper.readSettings(scopeElement);
|
||||
copyToolWrapper.getTool().readSettings(scopeElement);
|
||||
}
|
||||
HighlightDisplayLevel scopeLevel = errorLevel != null ?
|
||||
HighlightDisplayLevel.find(registrar.getSeverity(errorLevel)) : null;
|
||||
@@ -206,7 +207,7 @@ public class ToolsImpl implements Tools {
|
||||
|
||||
// check if unknown children exists
|
||||
if (toolElement.getAttributes().size() > 4 || toolElement.getChildren().size() > scopeElements.size()) {
|
||||
tool.readSettings(toolElement);
|
||||
toolWrapper.getTool().readSettings(toolElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,8 +224,8 @@ public class ToolsImpl implements Tools {
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionToolWrapper getTool() {
|
||||
if (myTools == null) return (InspectionToolWrapper)myDefaultState.getTool();
|
||||
return (InspectionToolWrapper)myTools.iterator().next().getTool();
|
||||
if (myTools == null) return myDefaultState.getTool();
|
||||
return myTools.iterator().next().getTool();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,7 +260,7 @@ 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);
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)scopeToolState.getTool();
|
||||
InspectionToolWrapper toolWrapper = scopeToolState.getTool();
|
||||
myTools.remove(idx);
|
||||
myTools.add(idx, new ScopeToolState(namedScope, toolWrapper, scopeToolState.isEnabled(), scopeToolState.getLevel()));
|
||||
}
|
||||
@@ -273,11 +274,11 @@ public class ToolsImpl implements Tools {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled(NamedScope namedScope) {
|
||||
public boolean isEnabled(NamedScope namedScope, Project project) {
|
||||
if (!myEnabled) return false;
|
||||
if (namedScope != null && myTools != null) {
|
||||
for (ScopeToolState state : myTools) {
|
||||
if (Comparing.equal(namedScope, ScopeToolStateUtil.getScope(state))) return state.isEnabled();
|
||||
if (Comparing.equal(namedScope, state.getScope(project))) return state.isEnabled();
|
||||
}
|
||||
}
|
||||
return myDefaultState.isEnabled();
|
||||
@@ -332,7 +333,7 @@ public class ToolsImpl implements Tools {
|
||||
public InspectionToolWrapper getEnabledTool(PsiElement element) {
|
||||
if (!myEnabled) return null;
|
||||
if (myTools == null || element == null) {
|
||||
return myDefaultState.isEnabled() ? (InspectionToolWrapper)myDefaultState.getTool() : null;
|
||||
return myDefaultState.isEnabled() ? myDefaultState.getTool() : null;
|
||||
}
|
||||
final Project project = element.getProject();
|
||||
final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
|
||||
@@ -341,21 +342,21 @@ public class ToolsImpl implements Tools {
|
||||
if (scope != null) {
|
||||
final PackageSet set = scope.getValue();
|
||||
if (set != null && set.contains(element.getContainingFile(), manager)) {
|
||||
return state.isEnabled() ? (InspectionToolWrapper)state.getTool() : null;
|
||||
return state.isEnabled() ? state.getTool() : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return myDefaultState.isEnabled() ? (InspectionToolWrapper)myDefaultState.getTool() : null;
|
||||
return myDefaultState.isEnabled() ? myDefaultState.getTool() : null;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
myEnabled = enabled;
|
||||
}
|
||||
|
||||
public void enableTool(NamedScope namedScope) {
|
||||
public void enableTool(NamedScope namedScope, Project project) {
|
||||
if (myTools != null) {
|
||||
for (ScopeToolState state : myTools) {
|
||||
if (Comparing.equal(ScopeToolStateUtil.getScope(state), namedScope)) {
|
||||
if (Comparing.equal(state.getScope(project), namedScope)) {
|
||||
state.setEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -363,10 +364,10 @@ public class ToolsImpl implements Tools {
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
public void disableTool(NamedScope namedScope) {
|
||||
public void disableTool(NamedScope namedScope, Project project) {
|
||||
if (myTools != null) {
|
||||
for (ScopeToolState state : myTools) {
|
||||
if (Comparing.equal(ScopeToolStateUtil.getScope(state), namedScope)) {
|
||||
if (Comparing.equal(state.getScope(project), namedScope)) {
|
||||
state.setEnabled(false);
|
||||
}
|
||||
}
|
||||
@@ -374,12 +375,7 @@ public class ToolsImpl implements Tools {
|
||||
}
|
||||
|
||||
|
||||
public void disableTool(PsiElement element) {
|
||||
if (element == null){
|
||||
myDefaultState.setEnabled(false);
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
public void disableTool(@NotNull PsiElement element) {
|
||||
final Project project = element.getProject();
|
||||
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(project);
|
||||
if (myTools != null) {
|
||||
@@ -394,17 +390,18 @@ public class ToolsImpl implements Tools {
|
||||
}
|
||||
}
|
||||
myDefaultState.setEnabled(false);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
myDefaultState.setEnabled(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HighlightDisplayLevel getLevel(final NamedScope scope) {
|
||||
public HighlightDisplayLevel getLevel(final NamedScope scope, Project project) {
|
||||
if (myTools != null && scope != null){
|
||||
for (ScopeToolState state : myTools) {
|
||||
if (Comparing.equal(ScopeToolStateUtil.getScope(state), scope)) {
|
||||
if (Comparing.equal(state.getScope(project), scope)) {
|
||||
return state.getLevel();
|
||||
}
|
||||
}
|
||||
@@ -428,12 +425,12 @@ public class ToolsImpl implements Tools {
|
||||
|
||||
}
|
||||
|
||||
public void setLevel(@NotNull HighlightDisplayLevel level, int idx) {
|
||||
public void setLevel(@NotNull HighlightDisplayLevel level, int idx, Project project) {
|
||||
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();
|
||||
final NamedScope scope = scopeToolState.getScope(project);
|
||||
InspectionToolWrapper toolWrapper = scopeToolState.getTool();
|
||||
if (scope != null) {
|
||||
myTools.add(idx, new ScopeToolState(scope, toolWrapper, scopeToolState.isEnabled(), level));
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.profile;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
@@ -28,6 +29,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Date: 01-Dec-2005
|
||||
*/
|
||||
public abstract class ProfileEx implements Profile {
|
||||
// public for JDOMExternalizable
|
||||
@NotNull
|
||||
public String myName;
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.profile.ProfileEx");
|
||||
public boolean myLocal = true;
|
||||
@@ -36,10 +39,11 @@ public abstract class ProfileEx implements Profile {
|
||||
public static final String NAME = "name";
|
||||
|
||||
public ProfileEx(@NotNull String name) {
|
||||
myName = name;
|
||||
setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
@@ -118,5 +122,5 @@ public abstract class ProfileEx implements Profile {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void convert(@NotNull Element element) {}
|
||||
public void convert(@NotNull Element element, @NotNull Project project) {}
|
||||
}
|
||||
|
||||
+1
-1
@@ -238,7 +238,7 @@ public class InspectionProjectProfileManagerImpl extends InspectionProjectProfil
|
||||
public void convert(Element element) throws InvalidDataException {
|
||||
super.convert(element);
|
||||
if (PROJECT_PROFILE != null) {
|
||||
((ProfileEx)getProjectProfileImpl()).convert(element);
|
||||
((ProfileEx)getProjectProfileImpl()).convert(element, getProject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -110,13 +111,15 @@ public class DaemonCodeAnalyzerSettingsImpl extends DaemonCodeAnalyzerSettings i
|
||||
}
|
||||
}
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
private void readExternal(Element element) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
myManager.getConverter().storeEditorHighlightingProfile(element);
|
||||
myManager.getConverter().storeEditorHighlightingProfile(element,
|
||||
new InspectionProfileImpl(
|
||||
InspectionProfileConvertor.OLD_HIGHTLIGHTING_SETTINGS_PROFILE));
|
||||
myManager.setRootProfile(element.getAttributeValue(PROFILE_ATT));
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
private void writeExternal(Element element) throws WriteExternalException {
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
element.setAttribute(PROFILE_ATT, myManager.getRootProfile().getName());
|
||||
}
|
||||
|
||||
@@ -776,11 +776,11 @@ public class HighlightInfo implements Segment {
|
||||
}
|
||||
List<IntentionAction> newOptions = IntentionManager.getInstance().getStandardIntentionOptions(key, element);
|
||||
InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(key.toString(), element);
|
||||
InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
|
||||
if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
|
||||
HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
|
||||
if (idkey != null) {
|
||||
toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(idkey.toString(), element);
|
||||
toolWrapper = profile.getInspectionTool(idkey.toString(), element);
|
||||
}
|
||||
}
|
||||
if (toolWrapper != null) {
|
||||
|
||||
+14
-8
@@ -24,6 +24,7 @@ import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
|
||||
import com.intellij.codeInsight.intention.EmptyIntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.concurrency.JobLauncher;
|
||||
import com.intellij.injected.editor.DocumentWindow;
|
||||
import com.intellij.lang.Language;
|
||||
@@ -159,13 +160,19 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
for (InspectionResult inspectionResult : resultList) {
|
||||
LocalInspectionToolWrapper toolWrapper = inspectionResult.tool;
|
||||
for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
|
||||
LocalInspectionToolWrapper.addProblemDescriptors(Collections.singletonList(descriptor), toolWrapper, myIgnoreSuppressed,
|
||||
toolWrapper.getContext(),
|
||||
toolWrapper.getTool());
|
||||
addDescriptors(toolWrapper, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addDescriptors(@NotNull LocalInspectionToolWrapper toolWrapper, @NotNull ProblemDescriptor descriptor) {
|
||||
GlobalInspectionContextImpl context = (GlobalInspectionContextImpl)toolWrapper.getContext();
|
||||
InspectionToolPresentation toolPresentation = context.getPresentation(toolWrapper);
|
||||
LocalDescriptorsUtil.addProblemDescriptors(Collections.singletonList(descriptor), toolPresentation, myIgnoreSuppressed,
|
||||
context,
|
||||
toolWrapper.getTool());
|
||||
}
|
||||
|
||||
private void addDescriptorsFromInjectedResults(@NotNull InspectionManagerEx iManager) {
|
||||
InjectedLanguageManager ilManager = InjectedLanguageManager.getInstance(myProject);
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
|
||||
@@ -176,12 +183,12 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
DocumentWindow documentRange = (DocumentWindow)documentManager.getDocument(file);
|
||||
List<InspectionResult> resultList = entry.getValue();
|
||||
for (InspectionResult inspectionResult : resultList) {
|
||||
LocalInspectionToolWrapper tool = inspectionResult.tool;
|
||||
LocalInspectionToolWrapper toolWrapper = inspectionResult.tool;
|
||||
for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
|
||||
|
||||
PsiElement psiElement = descriptor.getPsiElement();
|
||||
if (psiElement == null) continue;
|
||||
if (InspectionManagerEx.inspectionResultSuppressed(psiElement, tool.getTool())) continue;
|
||||
if (InspectionManagerEx.inspectionResultSuppressed(psiElement, toolWrapper.getTool())) continue;
|
||||
List<TextRange> editables = ilManager.intersectWithAllEditableFragments(file, ((ProblemDescriptorBase)descriptor).getTextRange());
|
||||
for (TextRange editable : editables) {
|
||||
TextRange hostRange = documentRange.injectedToHost(editable);
|
||||
@@ -196,8 +203,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
}
|
||||
ProblemDescriptor patchedDescriptor = iManager.createProblemDescriptor(myFile, hostRange, descriptor.getDescriptionTemplate(),
|
||||
descriptor.getHighlightType(), true, localFixes);
|
||||
LocalInspectionToolWrapper.addProblemDescriptors(Collections.singletonList(patchedDescriptor), tool, true, tool.getContext(),
|
||||
tool.getTool());
|
||||
addDescriptors(toolWrapper, patchedDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -718,7 +724,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
|
||||
@NotNull
|
||||
private List<LocalInspectionToolWrapper> getHighlightingLocalInspectionTools(@NotNull InspectionProfileWrapper profile, PsiElement element) {
|
||||
List<LocalInspectionToolWrapper> enabled = new ArrayList<LocalInspectionToolWrapper>();
|
||||
final InspectionToolWrapper[] toolWrappers = (InspectionToolWrapper[])profile.getInspectionTools(element);
|
||||
final InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(element);
|
||||
InspectionProfileWrapper.checkInspectionsDuplicates(toolWrappers);
|
||||
for (InspectionToolWrapper toolWrapper : toolWrappers) {
|
||||
if (!profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), element)) continue;
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class InspectionDescriptionLinkHandler extends TooltipLinkHandler {
|
||||
}
|
||||
|
||||
final InspectionProfile profile = (InspectionProfile)InspectionProfileManager.getInstance().getRootProfile();
|
||||
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profile.getInspectionTool(refSuffix, file);
|
||||
final InspectionToolWrapper toolWrapper = profile.getInspectionTool(refSuffix, file);
|
||||
if (toolWrapper == null) return null;
|
||||
|
||||
String description = toolWrapper.loadDescription();
|
||||
|
||||
@@ -20,6 +20,7 @@ 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.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -39,26 +40,27 @@ public class InspectionRunningUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<CommonProblemDescriptor> runInspectionOnFile(@NotNull PsiFile file, @NotNull InspectionToolWrapper tool) {
|
||||
public static List<CommonProblemDescriptor> runInspectionOnFile(@NotNull PsiFile file, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
final InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(file.getProject());
|
||||
final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
|
||||
tool.initialize(context);
|
||||
toolWrapper.initialize(context);
|
||||
RefManagerImpl refManager = (RefManagerImpl)context.getRefManager();
|
||||
refManager.inspectionReadActionStarted();
|
||||
try {
|
||||
if (tool instanceof LocalInspectionToolWrapper) {
|
||||
LocalInspectionTool localTool = ((LocalInspectionToolWrapper)tool).getTool();
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
LocalInspectionTool localTool = ((LocalInspectionToolWrapper)toolWrapper).getTool();
|
||||
List<ProblemDescriptor> descriptors =
|
||||
InspectionEngine.inspect(Collections.singletonList(localTool), file, managerEx, false, false, new DaemonProgressIndicator());
|
||||
return new ArrayList<CommonProblemDescriptor>(descriptors);
|
||||
}
|
||||
if (tool instanceof GlobalInspectionToolWrapper) {
|
||||
final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper)tool).getTool();
|
||||
if (toolWrapper instanceof GlobalInspectionToolWrapper) {
|
||||
final GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper)toolWrapper).getTool();
|
||||
if (globalTool instanceof GlobalSimpleInspectionTool) {
|
||||
GlobalSimpleInspectionTool simpleTool = (GlobalSimpleInspectionTool)globalTool;
|
||||
ProblemsHolder problemsHolder = new ProblemsHolder(managerEx, file, false);
|
||||
simpleTool.checkFile(file, managerEx, problemsHolder, context, tool);
|
||||
return new ArrayList<CommonProblemDescriptor>(tool.getProblemDescriptors());
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
simpleTool.checkFile(file, managerEx, problemsHolder, context, presentation);
|
||||
return new ArrayList<CommonProblemDescriptor>(presentation.getProblemDescriptors());
|
||||
}
|
||||
RefElement fileRef = refManager.getReference(file);
|
||||
CommonProblemDescriptor[] descriptors = globalTool.checkElement(fileRef, new AnalysisScope(file), managerEx, context);
|
||||
@@ -70,7 +72,7 @@ public class InspectionRunningUtil {
|
||||
}
|
||||
finally {
|
||||
refManager.inspectionReadActionFinished();
|
||||
tool.cleanup();
|
||||
toolWrapper.cleanup();
|
||||
context.cleanup(managerEx);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -91,7 +91,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent getAdditionalActionSettings(final Project project, final BaseAnalysisActionDialog dialog) {
|
||||
protected JComponent getAdditionalActionSettings(@NotNull final Project project, final BaseAnalysisActionDialog dialog) {
|
||||
final AdditionalPanel panel = new AdditionalPanel();
|
||||
final InspectionManagerEx manager = (InspectionManagerEx)InspectionManager.getInstance(project);
|
||||
final JComboBox profiles = panel.myBrowseProfilesCombo.getComboBox();
|
||||
@@ -121,7 +121,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
else {
|
||||
//if profile was disabled and cancel after apply was pressed
|
||||
final InspectionProfile profile = (InspectionProfile)profiles.getSelectedItem();
|
||||
final boolean canExecute = profile != null && profile.isExecutable();
|
||||
final boolean canExecute = profile != null && profile.isExecutable(project);
|
||||
dialog.setOKActionEnabled(canExecute);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myExternalProfile = (InspectionProfile)profiles.getSelectedItem();
|
||||
final boolean canExecute = myExternalProfile != null && myExternalProfile.isExecutable();
|
||||
final boolean canExecute = myExternalProfile != null && myExternalProfile.isExecutable(project);
|
||||
dialog.setOKActionEnabled(canExecute);
|
||||
if (canExecute) {
|
||||
manager.setProfile(myExternalProfile.getName());
|
||||
@@ -138,7 +138,7 @@ public class CodeInspectionAction extends BaseAnalysisAction {
|
||||
}
|
||||
});
|
||||
final InspectionProfile profile = (InspectionProfile)profiles.getSelectedItem();
|
||||
dialog.setOKActionEnabled(profile != null && profile.isExecutable());
|
||||
dialog.setOKActionEnabled(profile != null && profile.isExecutable(project));
|
||||
return panel.myAdditionalPanel;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ public class GotoInspectionModel extends SimpleChooseByNameModel {
|
||||
public GotoInspectionModel(Project project) {
|
||||
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()) {
|
||||
InspectionToolWrapper tool = (InspectionToolWrapper)state.getTool();
|
||||
for (ScopeToolState state : rootProfile.getAllTools(project)) {
|
||||
InspectionToolWrapper tool = state.getTool();
|
||||
InspectionToolWrapper workingTool = tool;
|
||||
if (tool instanceof LocalInspectionToolWrapper) {
|
||||
workingTool = LocalInspectionToolWrapper.findTool2RunInBatch(project, null, tool.getShortName());
|
||||
|
||||
+6
-6
@@ -46,8 +46,8 @@ import java.util.LinkedHashSet;
|
||||
public class RunInspectionIntention implements IntentionAction, HighPriorityAction {
|
||||
private final String myShortName;
|
||||
|
||||
public RunInspectionIntention(final InspectionProfileEntry tool) {
|
||||
myShortName = tool.getShortName();
|
||||
public RunInspectionIntention(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
myShortName = toolWrapper.getShortName();
|
||||
}
|
||||
|
||||
public RunInspectionIntention(final HighlightDisplayKey key) {
|
||||
@@ -104,15 +104,15 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
|
||||
final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile();
|
||||
LinkedHashSet<InspectionToolWrapper> allWrappers = new LinkedHashSet<InspectionToolWrapper>();
|
||||
allWrappers.add(toolWrapper);
|
||||
rootProfile.collectDependentInspections(toolWrapper, allWrappers);
|
||||
rootProfile.collectDependentInspections(toolWrapper, allWrappers, managerEx.getProject());
|
||||
InspectionToolWrapper[] toolWrappers = allWrappers.toArray(new InspectionToolWrapper[allWrappers.size()]);
|
||||
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(toolWrapper.getDisplayName(), toolWrappers);
|
||||
final InspectionProfileImpl model = InspectionProfileImpl.createSimple(toolWrapper.getDisplayName(), managerEx.getProject(), toolWrappers);
|
||||
try {
|
||||
Element element = new Element("toCopy");
|
||||
|
||||
for (InspectionToolWrapper wrapper : allWrappers) {
|
||||
wrapper.writeSettings(element);
|
||||
model.getInspectionTool(wrapper.getShortName(), psiElement).readSettings(element);
|
||||
wrapper.getTool().writeSettings(element);
|
||||
model.getInspectionTool(wrapper.getShortName(), psiElement).getTool().readSettings(element);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
+6
-165
@@ -15,24 +15,9 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefManager;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.ui.InspectionNode;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import org.jdom.Element;
|
||||
import com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommonInspectionToolWrapper extends InspectionToolWrapper<InspectionTool, InspectionEP> {
|
||||
public CommonInspectionToolWrapper(@NotNull InspectionEP ep) {
|
||||
@@ -41,7 +26,6 @@ public class CommonInspectionToolWrapper extends InspectionToolWrapper<Inspectio
|
||||
|
||||
public CommonInspectionToolWrapper(@NotNull InspectionTool tool) {
|
||||
super(tool);
|
||||
assert !(tool instanceof InspectionToolWrapper);
|
||||
}
|
||||
|
||||
private CommonInspectionToolWrapper(@NotNull CommonInspectionToolWrapper other) {
|
||||
@@ -54,158 +38,15 @@ public class CommonInspectionToolWrapper extends InspectionToolWrapper<Inspectio
|
||||
return new CommonInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull AnalysisScope scope, @NotNull InspectionManager manager) {
|
||||
getTool().runInspection(scope, manager);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RefManager getRefManager() {
|
||||
return getTool().getRefManager();
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context) {
|
||||
return getTool().getJobDescriptors(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull GlobalInspectionContextImpl context) {
|
||||
public void initialize(@NotNull GlobalInspectionContext context) {
|
||||
super.initialize(context);
|
||||
getTool().initialize(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext globalInspectionContext) {
|
||||
return getTool().getJobDescriptors(globalInspectionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGraphNeeded() {
|
||||
return getTool().isGraphNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContent() {
|
||||
getTool().updateContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReportedProblems() {
|
||||
return getTool().hasReportedProblems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<RefEntity>> getContent() {
|
||||
return getTool().getContent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GlobalInspectionContextImpl getContext() {
|
||||
return getTool().getContext();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HTMLComposerImpl getComposer() {
|
||||
return getTool().getComposer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finalCleanup() {
|
||||
getTool().finalCleanup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
getTool().cleanup();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public QuickFixAction[] getQuickFixes(@NotNull RefEntity[] refElements) {
|
||||
return getTool().getQuickFixes(refElements);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionNode createToolNode(@NotNull InspectionRVContentProvider provider,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
boolean showStructure) {
|
||||
return getTool().createToolNode(provider, parentNode, showStructure);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
@Nullable
|
||||
public IntentionAction findQuickFixes(CommonProblemDescriptor descriptor, String hint) {
|
||||
return getTool().findQuickFixes(descriptor, hint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HighlightSeverity getCurrentSeverity(@NotNull RefElement element) {
|
||||
return getTool().getCurrentSeverity(element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileStatus getElementStatus(RefEntity element) {
|
||||
return getTool().getElementStatus(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isElementIgnored(RefEntity element) {
|
||||
return getTool().isElementIgnored(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Set<RefModule> getModuleProblems() {
|
||||
return getTool().getModuleProblems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOldProblemsIncluded() {
|
||||
return getTool().isOldProblemsIncluded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Map<String, Set<RefEntity>> getOldContent() {
|
||||
return getTool().getOldContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queryExternalUsagesRequests(@NotNull InspectionManager manager) {
|
||||
return getTool().queryExternalUsagesRequests(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportResults(@NotNull Element parentNode, @NotNull RefEntity refEntity) {
|
||||
getTool().exportResults(parentNode, refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportResults(@NotNull Element parentNode) {
|
||||
getTool().exportResults(parentNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amnesty(RefEntity refEntity) {
|
||||
getTool().amnesty(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreCurrentElement(RefEntity refElement) {
|
||||
getTool().ignoreCurrentElement(refElement);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<RefEntity> getIgnoredRefElements() {
|
||||
return getTool().getIgnoredRefElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public SuppressIntentionAction[] getSuppressActions() {
|
||||
return getTool().getSuppressActions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import org.jdom.Element;
|
||||
@@ -44,18 +45,18 @@ public class Descriptor {
|
||||
private final ScopeToolState myState;
|
||||
private final InspectionProfileImpl myInspectionProfile;
|
||||
|
||||
public Descriptor(@NotNull ScopeToolState state, @NotNull InspectionProfileImpl inspectionProfile) {
|
||||
public Descriptor(@NotNull ScopeToolState state, @NotNull InspectionProfileImpl inspectionProfile, @NotNull Project project) {
|
||||
myState = state;
|
||||
myInspectionProfile = inspectionProfile;
|
||||
InspectionToolWrapper tool = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper tool = 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));
|
||||
myScope = state.getScope(project);
|
||||
myLevel = inspectionProfile.getErrorLevel(myKey, myScope, project);
|
||||
myEnabled = inspectionProfile.isToolEnabled(myKey, myScope, project);
|
||||
myToolWrapper = tool;
|
||||
myScope = ScopeToolStateUtil.getScope(state);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
@@ -99,14 +100,14 @@ public class Descriptor {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionToolWrapper getTool() {
|
||||
public InspectionToolWrapper getToolWrapper() {
|
||||
return myToolWrapper;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String loadDescription() {
|
||||
if (myConfig == null) {
|
||||
InspectionToolWrapper toolWrapper = getTool();
|
||||
InspectionToolWrapper toolWrapper = getToolWrapper();
|
||||
myConfig = createConfigElement(toolWrapper);
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ public class Descriptor {
|
||||
public static Element createConfigElement(InspectionToolWrapper toolWrapper) {
|
||||
Element element = new Element("options");
|
||||
try {
|
||||
toolWrapper.writeSettings(element);
|
||||
toolWrapper.getTool().writeSettings(element);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.codeInspection.ex;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.injected.editor.VirtualFileWindow;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -38,9 +39,9 @@ import java.util.List;
|
||||
*/
|
||||
public class DescriptorComposer extends HTMLComposerImpl {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.DescriptorComposer");
|
||||
private final DescriptorProviderInspection myTool;
|
||||
private final InspectionToolPresentation myTool;
|
||||
|
||||
public DescriptorComposer(DescriptorProviderInspection tool) {
|
||||
public DescriptorComposer(@NotNull InspectionToolPresentation tool) {
|
||||
myTool = tool;
|
||||
}
|
||||
|
||||
@@ -72,14 +73,13 @@ public class DescriptorComposer extends HTMLComposerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] quickFixTexts(RefEntity where, InspectionTool tool){
|
||||
QuickFixAction[] quickFixes = tool.getQuickFixes(new RefEntity[] {where});
|
||||
public static String[] quickFixTexts(RefEntity where, @NotNull InspectionToolPresentation toolPresentation){
|
||||
QuickFixAction[] quickFixes = toolPresentation.getQuickFixes(new RefEntity[] {where});
|
||||
if (quickFixes == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> texts = new ArrayList<String>();
|
||||
for (int i = 0; i < quickFixes.length; i++) {
|
||||
QuickFixAction quickFix = quickFixes[i];
|
||||
for (QuickFixAction quickFix : quickFixes) {
|
||||
final String text = quickFix.getText(where);
|
||||
if (text == null) continue;
|
||||
texts.add(text);
|
||||
@@ -143,7 +143,7 @@ public class DescriptorComposer extends HTMLComposerImpl {
|
||||
|
||||
protected void composeDescription(@NotNull CommonProblemDescriptor description, int i, @NotNull StringBuffer buf, @NotNull RefEntity refElement) {
|
||||
PsiElement expression = description instanceof ProblemDescriptor ? ((ProblemDescriptor)description).getPsiElement() : null;
|
||||
StringBuffer anchor = new StringBuffer();
|
||||
StringBuilder anchor = new StringBuilder();
|
||||
VirtualFile vFile = null;
|
||||
|
||||
if (expression != null) {
|
||||
@@ -156,7 +156,8 @@ public class DescriptorComposer extends HTMLComposerImpl {
|
||||
if (myExporter == null){
|
||||
//noinspection HardCodedStringLiteral
|
||||
anchor.append(new URL(vFile.getUrl() + "#descr:" + i));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
anchor.append(myExporter.getURL(refElement));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ 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();
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)inspectionProfile.getInspectionTool(myToolId);
|
||||
InspectionToolWrapper toolWrapper = inspectionProfile.getInspectionTool(myToolId, project);
|
||||
return toolWrapper == null || toolWrapper.getDefaultLevel() != HighlightDisplayLevel.NON_SWITCHABLE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
+119
-76
@@ -24,7 +24,9 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.lang.GlobalInspectionContextExtension;
|
||||
import com.intellij.codeInspection.lang.InspectionExtensionsFactory;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.DefaultInspectionToolPresentation;
|
||||
import com.intellij.codeInspection.ui.InspectionResultsView;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.concurrency.JobLauncher;
|
||||
import com.intellij.lang.annotation.ProblemGroup;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
@@ -40,7 +42,7 @@ import com.intellij.openapi.progress.util.ProgressWrapper;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
import com.intellij.openapi.project.ProjectUtilCore;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -113,7 +115,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
private final Map<String, Tools> myTools = new THashMap<String, Tools>();
|
||||
|
||||
private AnalysisUIOptions myUIOptions;
|
||||
@NonNls static final String LOCAL_TOOL_ATTRIBUTE = "is_local_tool";
|
||||
@NonNls public static final String LOCAL_TOOL_ATTRIBUTE = "is_local_tool";
|
||||
|
||||
private boolean myUseProgressIndicatorInTests = false;
|
||||
|
||||
@@ -184,7 +186,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
final NamedScope namedScope = state.getScope(project);
|
||||
if (namedScope == null || namedScope.getValue().contains(file, getCurrentProfile().getProfileManager().getScopesManager())) {
|
||||
return state.isEnabled() && ((InspectionToolWrapper)state.getTool()).getTool() == tool;
|
||||
return state.isEnabled() && state.getTool().getTool() == tool;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,7 +232,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.INSPECTION).activate(null);
|
||||
}
|
||||
|
||||
protected void addView(@NotNull InspectionResultsView view) {
|
||||
public 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 +248,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
|
||||
for (Tools tools : myTools.values()) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
toolWrapper.cleanup();
|
||||
}
|
||||
}
|
||||
@@ -313,10 +315,9 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
final InspectionManager manager,
|
||||
@NotNull final List<File> inspectionsResults) {
|
||||
cleanup();
|
||||
|
||||
myCurrentScope = scope;
|
||||
|
||||
InspectionTool.setOutputPath(outputPath);
|
||||
DefaultInspectionToolPresentation.setOutputPath(outputPath);
|
||||
final boolean oldToolsSettings = RUN_GLOBAL_TOOLS_ONLY;
|
||||
RUN_GLOBAL_TOOLS_ONLY = runGlobalToolsOnly;
|
||||
try {
|
||||
@@ -332,14 +333,14 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
String toolName = stringSetEntry.getKey();
|
||||
if (sameTools != null) {
|
||||
for (ScopeToolState toolDescr : sameTools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)toolDescr.getTool();
|
||||
InspectionToolWrapper toolWrapper = toolDescr.getTool();
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
hasProblems = new File(outputPath, toolName + ext).exists();
|
||||
}
|
||||
else if (toolWrapper.getTool() instanceof InspectionTool) {
|
||||
InspectionTool tool = (InspectionTool)toolWrapper.getTool();
|
||||
tool.updateContent();
|
||||
if (tool.hasReportedProblems()) {
|
||||
else {
|
||||
InspectionToolPresentation presentation = getPresentation(toolWrapper);
|
||||
presentation.updateContent();
|
||||
if (presentation.hasReportedProblems()) {
|
||||
final Element root = new Element(InspectionsBundle.message("inspection.problems"));
|
||||
globalTools.put(root, sameTools);
|
||||
LOG.assertTrue(!hasProblems, toolName);
|
||||
@@ -367,8 +368,9 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
final Tools tools = globalTools.get(element);
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
try {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
toolWrapper.exportResults(element, refEntity);
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
InspectionToolPresentation presentation = getPresentation(toolWrapper);
|
||||
presentation.exportResults(element, refEntity);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error("Problem when exporting: " + refEntity.getExternalName(), e);
|
||||
@@ -404,7 +406,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
});
|
||||
}
|
||||
finally {
|
||||
InspectionTool.setOutputPath(null);
|
||||
DefaultInspectionToolPresentation.setOutputPath(null);
|
||||
RUN_GLOBAL_TOOLS_ONLY = oldToolsSettings;
|
||||
}
|
||||
}
|
||||
@@ -421,7 +423,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
final NamedScope namedScope = state.getScope(file.getProject());
|
||||
if (namedScope == null || namedScope.getValue().contains(file, getCurrentProfile().getProfileManager().getScopesManager())) {
|
||||
if (state.isEnabled()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
if (toolWrapper.getTool() == tool) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -436,7 +438,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
final Tools tools = myTools.get(tool.getShortName());
|
||||
if (tools != null){
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
ignoreElementRecursively(toolWrapper, refElement);
|
||||
}
|
||||
}
|
||||
@@ -446,12 +448,10 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
return myView;
|
||||
}
|
||||
|
||||
private static void ignoreElementRecursively(@NotNull InspectionToolWrapper toolWrapper, final RefEntity refElement) {
|
||||
private void ignoreElementRecursively(@NotNull InspectionToolWrapper toolWrapper, final RefEntity refElement) {
|
||||
if (refElement != null) {
|
||||
InspectionProfileEntry tool = toolWrapper.getTool();
|
||||
if (tool instanceof InspectionTool) {
|
||||
((InspectionTool)tool).ignoreCurrentElement(refElement);
|
||||
}
|
||||
InspectionToolPresentation presentation = getPresentation(toolWrapper);
|
||||
presentation.ignoreCurrentElement(refElement);
|
||||
final List<RefEntity> children = refElement.getChildren();
|
||||
if (children != null) {
|
||||
for (RefEntity child : children) {
|
||||
@@ -488,28 +488,33 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.info("Code inspection finished");
|
||||
|
||||
if (myView != null) {
|
||||
if (!myView.update() && !getUIOptions().SHOW_ONLY_DIFF) {
|
||||
NotificationGroup.toolWindowGroup("Inspection Results", ToolWindowId.INSPECTION, true)
|
||||
.createNotification(InspectionsBundle.message("inspection.no.problems.message"), MessageType.INFO).notify(myProject);
|
||||
close(true);
|
||||
}
|
||||
else {
|
||||
addView(myView);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
notifyInspectionsFinished();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void performInspectionsWithProgress(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
|
||||
private void notifyInspectionsFinished() {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOG.info("Code inspection finished");
|
||||
|
||||
if (myView != null) {
|
||||
if (!myView.update() && !getUIOptions().SHOW_ONLY_DIFF) {
|
||||
NotificationGroup.toolWindowGroup("Inspection Results", ToolWindowId.INSPECTION, true)
|
||||
.createNotification(InspectionsBundle.message("inspection.no.problems.message"), MessageType.INFO).notify(myProject);
|
||||
close(true);
|
||||
}
|
||||
else {
|
||||
addView(myView);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void performInspectionsWithProgress(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
|
||||
final PsiManager psiManager = PsiManager.getInstance(myProject);
|
||||
myProgressIndicator = getProgressIndicator();
|
||||
//init manager in read action
|
||||
@@ -567,7 +572,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
// run special tools first
|
||||
for (Tools tools : specialTools) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
InspectionTool tool = (InspectionTool)toolWrapper.getTool();
|
||||
try {
|
||||
if (tool.isGraphNeeded()) {
|
||||
@@ -592,14 +597,15 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
|
||||
for (Tools tools : globalTools) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
GlobalInspectionTool tool = (GlobalInspectionTool)toolWrapper.getTool();
|
||||
InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
|
||||
try {
|
||||
if (tool.isGraphNeeded()) {
|
||||
((RefManagerImpl)getRefManager()).findAllDeclarations();
|
||||
}
|
||||
tool.runInspection(scope, manager, this, toolWrapper);
|
||||
if (tool.queryExternalUsagesRequests(manager,this, toolWrapper)) {
|
||||
tool.runInspection(scope, manager, this, toolPresentation);
|
||||
if (tool.queryExternalUsagesRequests(manager,this, toolPresentation)) {
|
||||
needRepeatSearchRequest.add(toolWrapper);
|
||||
}
|
||||
}
|
||||
@@ -635,16 +641,17 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
for (Tools tools : globalSimpleTools) {
|
||||
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
|
||||
GlobalSimpleInspectionTool tool = (GlobalSimpleInspectionTool)toolWrapper.getTool();
|
||||
tool.inspectionStarted(manager, this, toolWrapper);
|
||||
tool.inspectionStarted(manager, this, getPresentation(toolWrapper));
|
||||
}
|
||||
|
||||
final Map<String, DescriptorProviderInspection> map = getInspectionWrappersMap(localTools);
|
||||
final Map<String, InspectionToolWrapper> map = getInspectionWrappersMap(localTools);
|
||||
scope.accept(new PsiElementVisitor() {
|
||||
@Override
|
||||
public void visitFile(final PsiFile file) {
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
incrementJobDoneAmount(getStdJobDescriptors().LOCAL_ANALYSIS, ProjectUtil.calcRelativeToProjectPath(virtualFile, myProject));
|
||||
incrementJobDoneAmount(getStdJobDescriptors().LOCAL_ANALYSIS, ProjectUtilCore.displayUrlRelativeToProject(virtualFile, virtualFile
|
||||
.getPresentableUrl(), myProject, true, false));
|
||||
if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return;
|
||||
if (localScopeFiles != null && !localScopeFiles.add(virtualFile)) return;
|
||||
}
|
||||
@@ -672,8 +679,9 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
ProblemsHolder problemsHolder = new ProblemsHolder(manager, file, false);
|
||||
ProblemDescriptionsProcessor problemDescriptionProcessor = getProblemDescriptionProcessor(toolWrapper, map);
|
||||
tool.checkFile(file, manager, problemsHolder, GlobalInspectionContextImpl.this, problemDescriptionProcessor);
|
||||
LocalInspectionToolWrapper.addProblemDescriptors(problemsHolder.getResults(), false, GlobalInspectionContextImpl.this, null,
|
||||
CONVERT, toolWrapper);
|
||||
InspectionToolPresentation toolPresentation = getPresentation(toolWrapper);
|
||||
LocalDescriptorsUtil.addProblemDescriptors(problemsHolder.getResults(), false, GlobalInspectionContextImpl.this, null,
|
||||
CONVERT, toolPresentation);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -704,39 +712,56 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ProblemDescriptionsProcessor getProblemDescriptionProcessor(@NotNull final GlobalInspectionToolWrapper toolWrapper,
|
||||
@NotNull final Map<String, DescriptorProviderInspection> wrappersMap) {
|
||||
return new GlobalInspectionToolWrapper(toolWrapper.getTool()) {
|
||||
private ProblemDescriptionsProcessor getProblemDescriptionProcessor(@NotNull final GlobalInspectionToolWrapper toolWrapper,
|
||||
@NotNull final Map<String, InspectionToolWrapper> wrappersMap) {
|
||||
return new ProblemDescriptionsProcessor() {
|
||||
@Nullable
|
||||
@Override
|
||||
public void addProblemElement(RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
|
||||
public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
|
||||
return new CommonProblemDescriptor[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreElement(@NotNull RefEntity refEntity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
|
||||
for (CommonProblemDescriptor problemDescriptor : commonProblemDescriptors) {
|
||||
if (problemDescriptor instanceof ProblemDescriptor) {
|
||||
ProblemGroup problemGroup = ((ProblemDescriptor)problemDescriptor).getProblemGroup();
|
||||
if (!(problemDescriptor instanceof ProblemDescriptor)) {
|
||||
continue;
|
||||
}
|
||||
ProblemGroup problemGroup = ((ProblemDescriptor)problemDescriptor).getProblemGroup();
|
||||
|
||||
if (problemGroup != null) {
|
||||
DescriptorProviderInspection dummyWrapper = wrappersMap.get(problemGroup.getProblemName());
|
||||
InspectionToolWrapper targetWrapper;
|
||||
if (problemGroup == null) {
|
||||
targetWrapper = toolWrapper;
|
||||
}
|
||||
else {
|
||||
targetWrapper = wrappersMap.get(problemGroup.getProblemName());
|
||||
|
||||
if (dummyWrapper != null) { // Else it's switched off
|
||||
dummyWrapper.addProblemElement(refEntity, problemDescriptor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
toolWrapper.addProblemElement(refEntity, problemDescriptor);
|
||||
}
|
||||
}
|
||||
if (targetWrapper != null) { // Else it's switched off
|
||||
InspectionToolPresentation toolPresentation = getPresentation(targetWrapper);
|
||||
toolPresentation.addProblemElement(refEntity, problemDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<String, DescriptorProviderInspection> getInspectionWrappersMap(@NotNull List<Tools> tools) {
|
||||
Map<String, DescriptorProviderInspection> name2Inspection = new HashMap<String, DescriptorProviderInspection>(tools.size());
|
||||
private static Map<String, InspectionToolWrapper> getInspectionWrappersMap(@NotNull List<Tools> tools) {
|
||||
Map<String, InspectionToolWrapper> name2Inspection = new HashMap<String, InspectionToolWrapper>(tools.size());
|
||||
for (Tools tool : tools) {
|
||||
InspectionProfileEntry profileEntry = tool.getTool();
|
||||
if (profileEntry instanceof DescriptorProviderInspection) {
|
||||
name2Inspection.put(profileEntry.getShortName(), (DescriptorProviderInspection)profileEntry);
|
||||
}
|
||||
InspectionToolWrapper toolWrapper = tool.getTool();
|
||||
name2Inspection.put(toolWrapper.getShortName(), toolWrapper);
|
||||
}
|
||||
|
||||
return name2Inspection;
|
||||
@@ -769,11 +794,11 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
for (Tools currentTools : usedTools) {
|
||||
final String shortName = currentTools.getShortName();
|
||||
myTools.put(shortName, currentTools);
|
||||
InspectionToolWrapper toolWrapper1 = (InspectionToolWrapper)currentTools.getTool();
|
||||
InspectionToolWrapper toolWrapper1 = currentTools.getTool();
|
||||
classifyTool(outGlobalTools, outLocalTools, outGlobalSimpleTools, outSpecialTools, currentTools, toolWrapper1);
|
||||
|
||||
for (ScopeToolState state : currentTools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
toolWrapper.initialize(this);
|
||||
}
|
||||
}
|
||||
@@ -787,7 +812,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
List<Tools> tools = profile.getAllEnabledInspectionTools(myProject);
|
||||
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<InspectionToolWrapper>();
|
||||
for (Tools tool : tools) {
|
||||
profile.collectDependentInspections((InspectionToolWrapper)tool.getTool(), dependentTools);
|
||||
profile.collectDependentInspections(tool.getTool(), dependentTools, getProject());
|
||||
}
|
||||
|
||||
if (dependentTools.isEmpty()) {
|
||||
@@ -863,12 +888,12 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
myView = null;
|
||||
}
|
||||
|
||||
public void cleanup(final InspectionManagerEx managerEx) {
|
||||
public void cleanup(@NotNull InspectionManagerEx managerEx) {
|
||||
managerEx.closeRunningContext(this);
|
||||
for (Tools tools : myTools.values()) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper tool = (InspectionToolWrapper)state.getTool();
|
||||
tool.finalCleanup();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
getPresentation(toolWrapper).finalCleanup();
|
||||
}
|
||||
}
|
||||
cleanup();
|
||||
@@ -914,4 +939,22 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
|
||||
public StdJobDescriptors getStdJobDescriptors() {
|
||||
return myStdJobDescriptors;
|
||||
}
|
||||
|
||||
private final Map<InspectionToolWrapper, InspectionToolPresentation> myPresentationMap = new THashMap<InspectionToolWrapper, InspectionToolPresentation>();
|
||||
@NotNull
|
||||
public InspectionToolPresentation getPresentation(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
InspectionToolPresentation presentation = myPresentationMap.get(toolWrapper);
|
||||
if (presentation == null) {
|
||||
InspectionProfileEntry tool = toolWrapper.getTool();
|
||||
if (tool instanceof InspectionPresentationProvider) {
|
||||
presentation = ((InspectionPresentationProvider)tool).createPresentation(toolWrapper);
|
||||
}
|
||||
else {
|
||||
presentation = new DefaultInspectionToolPresentation(toolWrapper);
|
||||
}
|
||||
presentation.initialize(this);
|
||||
myPresentationMap.put(toolWrapper, presentation);
|
||||
}
|
||||
return presentation;
|
||||
}
|
||||
}
|
||||
|
||||
-153
@@ -1,153 +0,0 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefGraphAnnotator;
|
||||
import com.intellij.codeInspection.reference.RefManagerImpl;
|
||||
import com.intellij.codeInspection.reference.RefVisitor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 28-Dec-2005
|
||||
*/
|
||||
public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalInspectionTool, InspectionEP> {
|
||||
public GlobalInspectionToolWrapper(@NotNull GlobalInspectionTool globalInspectionTool) {
|
||||
super(globalInspectionTool);
|
||||
}
|
||||
|
||||
public GlobalInspectionToolWrapper(@NotNull InspectionEP ep) {
|
||||
super(ep);
|
||||
}
|
||||
|
||||
private GlobalInspectionToolWrapper(@NotNull GlobalInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionToolWrapper<GlobalInspectionTool, InspectionEP> createCopy() {
|
||||
return new GlobalInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull GlobalInspectionContextImpl context) {
|
||||
super.initialize(context);
|
||||
final RefGraphAnnotator annotator = getTool().getAnnotator(getRefManager());
|
||||
if (annotator != null) {
|
||||
((RefManagerImpl)getRefManager()).registerGraphAnnotator(annotator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
|
||||
throw new RuntimeException();
|
||||
//getTool().runInspection(scope, manager, getContext(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queryExternalUsagesRequests(@NotNull final InspectionManager manager) {
|
||||
throw new RuntimeException();
|
||||
//return getTool().queryExternalUsagesRequests(manager, getContext(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context) {
|
||||
final JobDescriptor[] additionalJobs = getTool().getAdditionalJobs();
|
||||
if (additionalJobs == null) {
|
||||
return getTool().isGraphNeeded() ? context.getStdJobDescriptors().BUILD_GRAPH_ONLY : JobDescriptor.EMPTY_ARRAY;
|
||||
}
|
||||
else {
|
||||
return getTool().isGraphNeeded() ? ArrayUtil.append(additionalJobs, context.getStdJobDescriptors().BUILD_GRAPH) : additionalJobs;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGraphNeeded() {
|
||||
throw new RuntimeException();
|
||||
//return getTool().isGraphNeeded();
|
||||
}
|
||||
|
||||
public void processFile(@NotNull final AnalysisScope analysisScope,
|
||||
@NotNull final InspectionManager manager,
|
||||
@NotNull final GlobalInspectionContext context,
|
||||
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);
|
||||
if (descriptors != null) {
|
||||
addProblemElement(refEntity, filterSuppressed, descriptors);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HTMLComposerImpl getComposer() {
|
||||
return new DescriptorComposer(this) {
|
||||
@Override
|
||||
protected void composeAdditionalDescription(@NotNull final StringBuffer buf, @NotNull final RefEntity refEntity) {
|
||||
getTool().compose(buf, refEntity, this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IntentionAction findQuickFixes(final CommonProblemDescriptor problemDescriptor, final String hint) {
|
||||
final QuickFix fix = getTool().getQuickFix(hint);
|
||||
if (fix == 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() {
|
||||
return getTool().worksInBatchModeOnly();
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.lang.InspectionExtensionsFactory;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.impl.ContentManagerWatcher;
|
||||
import com.intellij.ide.ui.search.SearchableOptionsRegistrar;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
@@ -39,18 +41,24 @@ import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.profile.codeInspection.ui.InspectionToolsConfigurable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.ui.content.ContentFactory;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import com.intellij.ui.content.TabbedPaneContentUI;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class InspectionManagerEx extends InspectionManagerBase {
|
||||
private GlobalInspectionContextImpl myGlobalInspectionContext = null;
|
||||
@@ -133,6 +141,23 @@ public class InspectionManagerEx extends InspectionManagerBase {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SuppressIntentionAction[] getSuppressActions(@NotNull InspectionProfileEntry tool) {
|
||||
if (tool instanceof CustomSuppressableInspectionTool) {
|
||||
return ((CustomSuppressableInspectionTool)tool).getSuppressActions(null);
|
||||
}
|
||||
if (tool instanceof BatchSuppressableTool) {
|
||||
LocalQuickFix[] actions = ((BatchSuppressableTool)tool).getBatchSuppressActions(null);
|
||||
return ContainerUtil.map2Array(actions, SuppressIntentionAction.class, new Function<LocalQuickFix, SuppressIntentionAction>() {
|
||||
@Override
|
||||
public SuppressIntentionAction fun(final LocalQuickFix fix) {
|
||||
return convertBatchToSuppressIntentionAction((SuppressQuickFix)fix);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public ProblemDescriptor createProblemDescriptor(@NotNull final PsiElement psiElement,
|
||||
@@ -230,4 +255,41 @@ public class InspectionManagerEx extends InspectionManagerBase {
|
||||
public NotNullLazyValue<ContentManager> getContentManager() {
|
||||
return myContentManager;
|
||||
}
|
||||
|
||||
private final AtomicBoolean myToolsAreInitialized = new AtomicBoolean(false);
|
||||
private static final Pattern HTML_PATTERN = Pattern.compile("<[^<>]*>");
|
||||
public void buildInspectionSearchIndexIfNecessary() {
|
||||
if (!myToolsAreInitialized.getAndSet(true)) {
|
||||
final SearchableOptionsRegistrar myOptionsRegistrar = SearchableOptionsRegistrar.getInstance();
|
||||
final InspectionToolRegistrar toolRegistrar = InspectionToolRegistrar.getInstance();
|
||||
final Application app = ApplicationManager.getApplication();
|
||||
if (app.isUnitTestMode() || app.isHeadlessEnvironment()) return;
|
||||
|
||||
app.executeOnPooledThread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
List<InspectionToolWrapper> tools = toolRegistrar.createTools();
|
||||
for (InspectionToolWrapper toolWrapper : tools) {
|
||||
processText(toolWrapper.getDisplayName().toLowerCase(), toolWrapper, myOptionsRegistrar);
|
||||
|
||||
final String description = toolWrapper.loadDescription();
|
||||
if (description != null) {
|
||||
@NonNls String descriptionText = HTML_PATTERN.matcher(description).replaceAll(" ");
|
||||
processText(descriptionText, toolWrapper, myOptionsRegistrar);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void processText(@NotNull @NonNls String descriptionText,
|
||||
@NotNull InspectionToolWrapper tool,
|
||||
@NotNull SearchableOptionsRegistrar myOptionsRegistrar) {
|
||||
if (ApplicationManager.getApplication().isDisposed()) return;
|
||||
final Set<String> words = myOptionsRegistrar.getProcessedWordsWithoutStemming(descriptionText);
|
||||
for (String word : words) {
|
||||
myOptionsRegistrar.addOption(word, tool.getShortName(), tool.getDisplayName(), InspectionToolsConfigurable.ID, InspectionToolsConfigurable.DISPLAY_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-11
@@ -15,17 +15,10 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ScopeToolStateUtil {
|
||||
@Nullable
|
||||
public static NamedScope getScope(@NotNull ScopeToolState toolState) {
|
||||
Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
|
||||
return toolState.getScope(project);
|
||||
}
|
||||
public interface InspectionPresentationProvider {
|
||||
@NotNull
|
||||
InspectionToolPresentation createPresentation(@NotNull InspectionToolWrapper toolWrapper);
|
||||
}
|
||||
+27
-21
@@ -52,7 +52,7 @@ public abstract class InspectionRVContentProvider {
|
||||
UserObjectContainer<T> getOwner();
|
||||
|
||||
@NotNull
|
||||
RefElementNode createNode(@NotNull InspectionTool tool);
|
||||
RefElementNode createNode(@NotNull InspectionToolPresentation presentation);
|
||||
|
||||
T getUserObject();
|
||||
|
||||
@@ -64,29 +64,34 @@ public abstract class InspectionRVContentProvider {
|
||||
boolean supportStructure();
|
||||
}
|
||||
|
||||
public abstract boolean checkReportedProblems(@NotNull InspectionToolWrapper toolWrapper);
|
||||
public abstract boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context, @NotNull InspectionToolWrapper toolWrapper);
|
||||
|
||||
@Nullable
|
||||
public abstract QuickFixAction[] getQuickFixes(@NotNull InspectionTool tool, @NotNull InspectionTree tree);
|
||||
public abstract QuickFixAction[] getQuickFixes(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionTree tree);
|
||||
|
||||
|
||||
public void appendToolNodeContent(@NotNull InspectionNode toolNode,
|
||||
public void appendToolNodeContent(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull InspectionNode toolNode,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
final boolean showStructure) {
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
final Map<String, Set<RefEntity>> content = tool.getContent();
|
||||
appendToolNodeContent(toolNode, parentNode, showStructure, content != null ? content : new HashMap<String, Set<RefEntity>>(),
|
||||
tool instanceof DescriptorProviderInspection ? ((DescriptorProviderInspection)tool).getProblemElements() : null, null);
|
||||
InspectionToolWrapper wrapper = toolNode.getToolWrapper();
|
||||
InspectionToolPresentation presentation = context.getPresentation(wrapper);
|
||||
Map<String, Set<RefEntity>> content = presentation.getContent();
|
||||
Map<RefEntity, CommonProblemDescriptor[]> problems = presentation.getProblemElements();
|
||||
Map<String, Set<RefEntity>> contents = content == null ? new HashMap<String, Set<RefEntity>>() : content;
|
||||
appendToolNodeContent(context, toolNode, parentNode, showStructure, contents, problems, null);
|
||||
}
|
||||
|
||||
public abstract void appendToolNodeContent(final InspectionNode toolNode,
|
||||
final InspectionTreeNode parentNode,
|
||||
public abstract void appendToolNodeContent(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull InspectionNode toolNode,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
final boolean showStructure,
|
||||
final Map<String, Set<RefEntity>> contents,
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
@NotNull Map<String, Set<RefEntity>> contents,
|
||||
@NotNull Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
@Nullable final DefaultTreeModel model);
|
||||
|
||||
protected abstract void appendDescriptor(@NotNull InspectionTool tool,
|
||||
protected abstract void appendDescriptor(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull InspectionToolWrapper toolWrapper,
|
||||
@NotNull UserObjectContainer container,
|
||||
@NotNull InspectionPackageNode pNode,
|
||||
final boolean canPackageRepeat);
|
||||
@@ -95,10 +100,11 @@ public abstract class InspectionRVContentProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected <T> List<InspectionTreeNode> buildTree(final Map<String, Set<T>> packageContents,
|
||||
protected <T> List<InspectionTreeNode> buildTree(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull Map<String, Set<T>> packageContents,
|
||||
final boolean canPackageRepeat,
|
||||
final InspectionTool tool,
|
||||
final Function<T, UserObjectContainer<T>> computeContainer,
|
||||
@NotNull InspectionToolWrapper toolWrapper,
|
||||
@NotNull Function<T, UserObjectContainer<T>> computeContainer,
|
||||
final boolean showStructure) {
|
||||
final List<InspectionTreeNode> content = new ArrayList<InspectionTreeNode>();
|
||||
final Map<String, Map<String, InspectionPackageNode>> module2PackageMap = new HashMap<String, Map<String, InspectionPackageNode>>();
|
||||
@@ -119,7 +125,7 @@ public abstract class InspectionRVContentProvider {
|
||||
pNode = new InspectionPackageNode(packageName);
|
||||
packageNodes.put(packageName, pNode);
|
||||
}
|
||||
appendDescriptor(tool, container, pNode, canPackageRepeat);
|
||||
appendDescriptor(context, toolWrapper, container, pNode, canPackageRepeat);
|
||||
}
|
||||
}
|
||||
if (supportStructure) {
|
||||
@@ -213,14 +219,14 @@ public abstract class InspectionRVContentProvider {
|
||||
|
||||
@NotNull
|
||||
protected static RefElementNode addNodeToParent(@NotNull UserObjectContainer container,
|
||||
@NotNull InspectionTool tool,
|
||||
@NotNull InspectionToolPresentation presentation,
|
||||
final InspectionTreeNode parentNode) {
|
||||
final RefElementNode nodeToBeAdded = container.createNode(tool);
|
||||
final RefElementNode nodeToBeAdded = container.createNode(presentation);
|
||||
final Ref<Boolean> firstLevel = new Ref<Boolean>(true);
|
||||
RefElementNode prevNode = null;
|
||||
final Ref<RefElementNode> result = new Ref<RefElementNode>();
|
||||
while (true) {
|
||||
final RefElementNode currentNode = firstLevel.get() ? nodeToBeAdded : container.createNode(tool);
|
||||
final RefElementNode currentNode = firstLevel.get() ? nodeToBeAdded : container.createNode(presentation);
|
||||
final UserObjectContainer finalContainer = container;
|
||||
final RefElementNode finalPrevNode = prevNode;
|
||||
TreeUtil.traverseDepth(parentNode, new TreeUtil.Traverse() {
|
||||
@@ -280,7 +286,7 @@ public abstract class InspectionRVContentProvider {
|
||||
}
|
||||
}
|
||||
else if (current instanceof InspectionNode) {
|
||||
if (((InspectionNode)current).getTool().getShortName().compareTo(((InspectionNode)child).getTool().getShortName()) == 0) {
|
||||
if (((InspectionNode)current).getToolWrapper().getShortName().compareTo(((InspectionNode)child).getToolWrapper().getShortName()) == 0) {
|
||||
processDepth(model, child, current);
|
||||
return;
|
||||
}
|
||||
|
||||
+35
-38
@@ -21,10 +21,7 @@
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.CommonProblemDescriptor;
|
||||
import com.intellij.codeInspection.reference.RefDirectory;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -40,42 +37,45 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class InspectionRVContentProviderImpl extends InspectionRVContentProvider {
|
||||
|
||||
public InspectionRVContentProviderImpl(final Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkReportedProblems(@NotNull final InspectionToolWrapper toolWrapper) {
|
||||
toolWrapper.updateContent();
|
||||
return toolWrapper.hasReportedProblems();
|
||||
public boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull final InspectionToolWrapper toolWrapper) {
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
presentation.updateContent();
|
||||
return presentation.hasReportedProblems();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final InspectionTool tool, @NotNull final InspectionTree tree) {
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final InspectionToolWrapper toolWrapper, @NotNull final InspectionTree tree) {
|
||||
final RefEntity[] refEntities = tree.getSelectedElements();
|
||||
return refEntities.length == 0 ? null : tool.getQuickFixes(refEntities);
|
||||
InspectionToolPresentation presentation = ((GlobalInspectionContextImpl)toolWrapper.getContext()).getPresentation(toolWrapper);
|
||||
return refEntities.length == 0 ? null : presentation.getQuickFixes(refEntities);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void appendToolNodeContent(final InspectionNode toolNode,
|
||||
final InspectionTreeNode parentNode,
|
||||
public void appendToolNodeContent(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull final InspectionNode toolNode,
|
||||
@NotNull final InspectionTreeNode parentNode,
|
||||
final boolean showStructure,
|
||||
final Map<String, Set<RefEntity>> contents,
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
@NotNull final Map<String, Set<RefEntity>> contents,
|
||||
@NotNull final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
DefaultTreeModel model) {
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
final InspectionToolWrapper toolWrapper = toolNode.getToolWrapper();
|
||||
|
||||
Function<RefEntity, UserObjectContainer<RefEntity>> computeContainer = new Function<RefEntity, UserObjectContainer<RefEntity>>() {
|
||||
@Override
|
||||
public UserObjectContainer<RefEntity> fun(final RefEntity refElement) {
|
||||
return new RefElementContainer(refElement, problems != null ? problems.get(refElement) : null);
|
||||
return new RefElementContainer(refElement, problems.get(refElement));
|
||||
}
|
||||
};
|
||||
|
||||
final Set<RefModule> moduleProblems = tool.getModuleProblems();
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
final Set<RefModule> moduleProblems = presentation.getModuleProblems();
|
||||
if (moduleProblems != null && !moduleProblems.isEmpty()) {
|
||||
Set<RefEntity> entities = contents.get("");
|
||||
if (entities == null) {
|
||||
@@ -84,16 +84,14 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
}
|
||||
entities.addAll(moduleProblems);
|
||||
}
|
||||
List<InspectionTreeNode> list = buildTree(contents, false, tool, computeContainer, showStructure);
|
||||
List<InspectionTreeNode> list = buildTree(context, contents, false, toolWrapper, computeContainer, showStructure);
|
||||
|
||||
for (InspectionTreeNode node : list) {
|
||||
merge(model, node, toolNode, true);
|
||||
}
|
||||
|
||||
if (tool.isOldProblemsIncluded()) {
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> oldProblems =
|
||||
tool instanceof DescriptorProviderInspection && !(tool instanceof CommonInspectionToolWrapper)? ((DescriptorProviderInspection)tool)
|
||||
.getOldProblemElements() : null;
|
||||
if (presentation.isOldProblemsIncluded()) {
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> oldProblems = presentation.getOldProblemElements();
|
||||
computeContainer = new Function<RefEntity, UserObjectContainer<RefEntity>>() {
|
||||
@Override
|
||||
public UserObjectContainer<RefEntity> fun(final RefEntity refElement) {
|
||||
@@ -101,7 +99,7 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
}
|
||||
};
|
||||
|
||||
list = buildTree(tool.getOldContent(), true, tool, computeContainer, showStructure);
|
||||
list = buildTree(context, presentation.getOldContent(), true, toolWrapper, computeContainer, showStructure);
|
||||
|
||||
for (InspectionTreeNode node : list) {
|
||||
merge(model, node, toolNode, true);
|
||||
@@ -111,25 +109,24 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendDescriptor(@NotNull final InspectionTool tool,
|
||||
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull final InspectionToolWrapper toolWrapper,
|
||||
@NotNull final UserObjectContainer container,
|
||||
@NotNull final InspectionPackageNode pNode,
|
||||
final boolean canPackageRepeat) {
|
||||
final GlobalInspectionContextImpl context = tool.getContext();
|
||||
final RefElementContainer refElementDescriptor = (RefElementContainer)container;
|
||||
final RefEntity refElement = refElementDescriptor.getUserObject();
|
||||
if (context.getUIOptions().SHOW_ONLY_DIFF && tool.getElementStatus(refElement) == FileStatus.NOT_CHANGED) return;
|
||||
if (tool instanceof DescriptorProviderInspection && !(tool instanceof CommonInspectionToolWrapper)) {
|
||||
final DescriptorProviderInspection descriptorProviderInspection = (DescriptorProviderInspection)tool;
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
if (context.getUIOptions().SHOW_ONLY_DIFF && presentation.getElementStatus(refElement) == FileStatus.NOT_CHANGED) return;
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
final CommonProblemDescriptor[] problems = refElementDescriptor.getProblemDescriptors();
|
||||
if (problems != null) {
|
||||
final RefElementNode elemNode = addNodeToParent(container, tool, pNode);
|
||||
final RefElementNode elemNode = addNodeToParent(container, presentation, pNode);
|
||||
for (CommonProblemDescriptor problem : problems) {
|
||||
if (context.getUIOptions().SHOW_ONLY_DIFF && descriptorProviderInspection.getProblemStatus(problem) == FileStatus.NOT_CHANGED) {
|
||||
if (context.getUIOptions().SHOW_ONLY_DIFF && presentation.getProblemStatus(problem) == FileStatus.NOT_CHANGED) {
|
||||
continue;
|
||||
}
|
||||
elemNode.add(
|
||||
new ProblemDescriptionNode(refElement, problem, descriptorProviderInspection));
|
||||
elemNode.add(new ProblemDescriptionNode(refElement, problem, toolWrapper));
|
||||
if (problems.length == 1) {
|
||||
elemNode.setProblem(problems[0]);
|
||||
}
|
||||
@@ -138,13 +135,13 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
}
|
||||
else {
|
||||
if (canPackageRepeat) {
|
||||
final Set<RefEntity> currentElements = tool.getContent().get(pNode.getPackageName());
|
||||
final Set<RefEntity> currentElements = presentation.getContent().get(pNode.getPackageName());
|
||||
if (currentElements != null) {
|
||||
final Set<RefEntity> currentEntities = new HashSet<RefEntity>(currentElements);
|
||||
if (InspectionTool.contains(refElement, currentEntities)) return;
|
||||
if (RefUtil.contains(refElement, currentEntities)) return;
|
||||
}
|
||||
}
|
||||
addNodeToParent(container, tool, pNode);
|
||||
addNodeToParent(container, presentation, pNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,8 +167,8 @@ public class InspectionRVContentProviderImpl extends InspectionRVContentProvider
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RefElementNode createNode(@NotNull InspectionTool tool) {
|
||||
return new RefElementNode(myElement, tool);
|
||||
public RefElementNode createNode(@NotNull InspectionToolPresentation presentation) {
|
||||
return new RefElementNode(myElement, presentation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,90 +24,27 @@ package com.intellij.codeInspection.ex;
|
||||
|
||||
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.SeverityRegistrar;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.codeInspection.ui.InspectionNode;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
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 com.intellij.codeInspection.GlobalInspectionContext;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class InspectionTool extends InspectionProfileEntry {
|
||||
private GlobalInspectionContextImpl myContext;
|
||||
protected static String ourOutputPath;
|
||||
protected InspectionNode myToolNode;
|
||||
|
||||
public void initialize(@NotNull GlobalInspectionContextImpl context) {
|
||||
myContext = context;
|
||||
projectOpened(context.getProject());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GlobalInspectionContextImpl getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public RefManager getRefManager() {
|
||||
return getContext().getRefManager();
|
||||
}
|
||||
protected GlobalInspectionContextImpl myContext;
|
||||
|
||||
public abstract void runInspection(@NotNull AnalysisScope scope, @NotNull InspectionManager manager);
|
||||
|
||||
public void exportResults(@NotNull final Element parentNode) {
|
||||
getRefManager().iterate(new RefVisitor(){
|
||||
@Override
|
||||
public void visitElement(@NotNull RefEntity elem) {
|
||||
exportResults(parentNode, elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public abstract void exportResults(@NotNull Element parentNode, @NotNull RefEntity refEntity);
|
||||
|
||||
public abstract boolean isGraphNeeded();
|
||||
@Nullable
|
||||
public QuickFixAction[] getQuickFixes(@NotNull RefEntity[] refElements) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext globalInspectionContext);
|
||||
|
||||
public boolean queryExternalUsagesRequests(@NotNull InspectionManager manager) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
return getDefaultLevel() != HighlightDisplayLevel.DO_NOT_SHOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
@NotNull
|
||||
public final String getDescriptionFileName() {
|
||||
return getShortName() + ".html";
|
||||
}
|
||||
|
||||
public final String getFolderName() {
|
||||
return getShortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
@@ -117,121 +54,12 @@ public abstract class InspectionTool extends InspectionProfileEntry {
|
||||
myContext = null;
|
||||
}
|
||||
|
||||
public void finalCleanup(){
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract HTMLComposerImpl getComposer();
|
||||
|
||||
public abstract boolean hasReportedProblems();
|
||||
|
||||
public abstract void updateContent();
|
||||
|
||||
public abstract Map<String, Set<RefEntity>> getContent();
|
||||
|
||||
@Nullable
|
||||
public abstract Map<String, Set<RefEntity>> getOldContent();
|
||||
|
||||
public boolean isOldProblemsIncluded() {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
return context != null && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN && getOldContent() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<RefModule> getModuleProblems(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract void ignoreCurrentElement(RefEntity refElement);
|
||||
|
||||
@NotNull
|
||||
public abstract Collection<RefEntity> getIgnoredRefElements();
|
||||
|
||||
public abstract void amnesty(RefEntity refEntity);
|
||||
|
||||
public abstract boolean isElementIgnored(final RefEntity element);
|
||||
|
||||
@NotNull
|
||||
public abstract FileStatus getElementStatus(final RefEntity element);
|
||||
|
||||
@NotNull
|
||||
protected static FileStatus calcStatus(boolean old, boolean current) {
|
||||
if (old) {
|
||||
if (!current) {
|
||||
return FileStatus.DELETED;
|
||||
}
|
||||
}
|
||||
else if (current) {
|
||||
return FileStatus.ADDED;
|
||||
}
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
protected static boolean contains(RefEntity element, @NotNull Collection<RefEntity> entities){
|
||||
for (RefEntity refEntity : entities) {
|
||||
if (Comparing.equal(refEntity, element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public boolean queryExternalUsagesRequests(InspectionManager manager) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected HighlightSeverity getCurrentSeverity(@NotNull RefElement element) {
|
||||
final PsiElement psiElement = element.getPointer().getContainingFile();
|
||||
if (psiElement != null) {
|
||||
if (myContext != null) {
|
||||
final Tools tools = myContext.getTools().get(getShortName());
|
||||
if (tools != null) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
if (toolWrapper == this) {
|
||||
return myContext.getCurrentProfile().getErrorLevel(HighlightDisplayKey.find(getShortName()), psiElement).getSeverity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(getContext().getProject()).getInspectionProfile();
|
||||
final HighlightDisplayLevel level = profile.getErrorLevel(HighlightDisplayKey.find(getShortName()), psiElement);
|
||||
return level.getSeverity();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String getTextAttributeKey(@NotNull Project project, @NotNull HighlightSeverity severity, @NotNull ProblemHighlightType highlightType) {
|
||||
if (highlightType == ProblemHighlightType.LIKE_DEPRECATED) {
|
||||
return HighlightInfoType.DEPRECATED.getAttributesKey().getExternalName();
|
||||
}
|
||||
if (highlightType == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL && severity == HighlightSeverity.ERROR) {
|
||||
return HighlightInfoType.WRONG_REF.getAttributesKey().getExternalName();
|
||||
}
|
||||
if (highlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
|
||||
return HighlightInfoType.UNUSED_SYMBOL.getAttributesKey().getExternalName();
|
||||
}
|
||||
SeverityRegistrar registrar = InspectionProjectProfileManagerImpl.getInstanceImpl(project).getSeverityRegistrar();
|
||||
return registrar.getHighlightInfoTypeBySeverity(severity).getAttributesKey().getExternalName();
|
||||
}
|
||||
|
||||
public static void setOutputPath(final String output) {
|
||||
ourOutputPath = output;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
@Nullable
|
||||
public IntentionAction findQuickFixes(final CommonProblemDescriptor descriptor, final String hint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@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;
|
||||
public void initialize(@NotNull GlobalInspectionContext context) {
|
||||
myContext = (GlobalInspectionContextImpl)context;
|
||||
projectOpened(context.getProject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefManagerImpl;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.util.TripleFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LocalDescriptorsUtil {
|
||||
private static final TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext,RefElement> CONVERT = new TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext,RefElement>() {
|
||||
@Override
|
||||
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(element, context);
|
||||
}
|
||||
return refElement;
|
||||
}
|
||||
};
|
||||
|
||||
static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors,
|
||||
boolean filterSuppressed,
|
||||
@NotNull GlobalInspectionContext context,
|
||||
@Nullable LocalInspectionTool tool,
|
||||
@NotNull TripleFunction<LocalInspectionTool, PsiElement, GlobalInspectionContext, RefElement> getProblemElementFunction,
|
||||
@NotNull InspectionToolPresentation 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 element = descriptor.getPsiElement();
|
||||
if (element == null) continue;
|
||||
if (filterSuppressed) {
|
||||
String alternativeId;
|
||||
String id;
|
||||
if (refManager.isDeclarationsFound() &&
|
||||
(context.isSuppressed(element, id = tool.getID()) ||
|
||||
(alternativeId = tool.getAlternativeID()) != null &&
|
||||
!alternativeId.equals(id) &&
|
||||
context.isSuppressed(element, alternativeId))) {
|
||||
continue;
|
||||
}
|
||||
if (InspectionManagerEx.inspectionResultSuppressed(element, tool)) continue;
|
||||
}
|
||||
|
||||
|
||||
RefElement refElement = getProblemElementFunction.fun(tool, element, context);
|
||||
|
||||
List<ProblemDescriptor> elementProblems = problems.get(refElement);
|
||||
if (elementProblems == null) {
|
||||
elementProblems = new ArrayList<ProblemDescriptor>();
|
||||
problems.put(refElement, elementProblems);
|
||||
}
|
||||
elementProblems.add(descriptor);
|
||||
}
|
||||
|
||||
for (Map.Entry<RefElement, List<ProblemDescriptor>> entry : problems.entrySet()) {
|
||||
final List<ProblemDescriptor> problemDescriptors = entry.getValue();
|
||||
RefElement refElement = entry.getKey();
|
||||
CommonProblemDescriptor[] descriptions = problemDescriptors.toArray(new CommonProblemDescriptor[problemDescriptors.size()]);
|
||||
dpi.addProblemElement(refElement, filterSuppressed, descriptions);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addProblemDescriptors(@NotNull List<ProblemDescriptor> descriptors,
|
||||
@NotNull InspectionToolPresentation dpi,
|
||||
boolean filterSuppressed,
|
||||
@NotNull GlobalInspectionContext inspectionContext,
|
||||
@NotNull LocalInspectionTool tool) {
|
||||
addProblemDescriptors(descriptors, filterSuppressed, inspectionContext, tool, CONVERT, dpi);
|
||||
}
|
||||
}
|
||||
-250
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
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;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.TripleFunction;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspectionTool, LocalInspectionEP> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.LocalInspectionToolWrapper");
|
||||
|
||||
/** This should be used in tests primarily */
|
||||
@TestOnly
|
||||
public LocalInspectionToolWrapper(@NotNull LocalInspectionTool tool) {
|
||||
super(tool, ourEPMap.getValue().get(tool.getShortName()));
|
||||
}
|
||||
|
||||
public LocalInspectionToolWrapper(@NotNull LocalInspectionEP ep) {
|
||||
super(ep);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public LocalInspectionToolWrapper(@Nullable LocalInspectionTool tool, @Nullable LocalInspectionEP ep) {
|
||||
super(tool, ep);
|
||||
}
|
||||
|
||||
private LocalInspectionToolWrapper(@NotNull LocalInspectionToolWrapper other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LocalInspectionToolWrapper createCopy() {
|
||||
return new LocalInspectionToolWrapper(this);
|
||||
}
|
||||
|
||||
public void processFile(@NotNull PsiFile file, final boolean filterSuppressed, @NotNull InspectionManager manager) {
|
||||
List<ProblemDescriptor> results = getTool().processFile(file, manager);
|
||||
addProblemDescriptors(results, this, filterSuppressed, getContext(), getTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JobDescriptor[] getJobDescriptors(@NotNull GlobalInspectionContext context) {
|
||||
return context.getStdJobDescriptors().LOCAL_ANALYSIS_ARRAY;
|
||||
}
|
||||
|
||||
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 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(element, context);
|
||||
}
|
||||
return refElement;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void addProblemElement(RefEntity refElement, boolean filterSuppressed, @NotNull CommonProblemDescriptor... descriptions) {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context == null) return;
|
||||
super.addProblemElement(refElement, filterSuppressed, descriptions);
|
||||
final InspectionResultsView view = context.getView();
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 element = descriptor.getPsiElement();
|
||||
if (element == null) continue;
|
||||
if (filterSuppressed) {
|
||||
String alternativeId;
|
||||
String id;
|
||||
if (refManager.isDeclarationsFound() &&
|
||||
(context.isSuppressed(element, id = tool.getID()) ||
|
||||
(alternativeId = tool.getAlternativeID()) != null &&
|
||||
!alternativeId.equals(id) &&
|
||||
context.isSuppressed(element, alternativeId))) {
|
||||
continue;
|
||||
}
|
||||
if (InspectionManagerEx.inspectionResultSuppressed(element, tool)) continue;
|
||||
}
|
||||
|
||||
|
||||
RefElement refElement = getProblemElementFunction.fun(tool, element, context);
|
||||
|
||||
List<ProblemDescriptor> elementProblems = problems.get(refElement);
|
||||
if (elementProblems == null) {
|
||||
elementProblems = new ArrayList<ProblemDescriptor>();
|
||||
problems.put(refElement, elementProblems);
|
||||
}
|
||||
elementProblems.add(descriptor);
|
||||
}
|
||||
|
||||
for (Map.Entry<RefElement, List<ProblemDescriptor>> entry : problems.entrySet()) {
|
||||
final List<ProblemDescriptor> problemDescriptors = entry.getValue();
|
||||
RefElement refElement = entry.getKey();
|
||||
CommonProblemDescriptor[] descriptions = problemDescriptors.toArray(new CommonProblemDescriptor[problemDescriptors.size()]);
|
||||
dpi.addProblemElement(refElement, filterSuppressed, descriptions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull AnalysisScope scope, @NotNull final InspectionManager manager) {
|
||||
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode());
|
||||
scope.accept(new PsiRecursiveElementVisitor() {
|
||||
@Override public void visitFile(PsiFile file) {
|
||||
processFile(file, true, manager);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isUnfair() {
|
||||
return myEP == null ? getTool() instanceof UnfairLocalInspectionTool : myEP.unfair;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return myEP == null ? getTool().getID() : myEP.id == null ? myEP.getShortName() : myEP.id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAlternativeID() {
|
||||
return myEP == null ? getTool().getAlternativeID() : myEP.alternativeId;
|
||||
}
|
||||
|
||||
public boolean runForWholeFile() {
|
||||
return myEP == null ? getTool().runForWholeFile() : myEP.runForWholeFile;
|
||||
}
|
||||
|
||||
private static final NotNullLazyValue<Map<String, LocalInspectionEP>> ourEPMap = new NotNullLazyValue<Map<String, LocalInspectionEP>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, LocalInspectionEP> compute() {
|
||||
HashMap<String, LocalInspectionEP> map = new HashMap<String, LocalInspectionEP>();
|
||||
for (LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
|
||||
map.put(ep.getShortName(), ep);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
|
||||
public static InspectionToolWrapper findTool2RunInBatch(@NotNull Project project, @Nullable PsiElement element, @NotNull String name) {
|
||||
final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
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 ? (InspectionToolWrapper)inspectionProfile.getInspectionTool(oppositeShortName, element) : (InspectionToolWrapper)inspectionProfile.getInspectionTool(oppositeShortName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefManager;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -30,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -39,9 +41,8 @@ public class LocalQuickFixWrapper extends QuickFixAction {
|
||||
private final QuickFix myFix;
|
||||
private String myText;
|
||||
|
||||
public LocalQuickFixWrapper(@NotNull QuickFix fix, @NotNull DescriptorProviderInspection tool) {
|
||||
super(fix.getName(), tool);
|
||||
myTool = tool;
|
||||
public LocalQuickFixWrapper(@NotNull QuickFix fix, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(fix.getName(), toolWrapper);
|
||||
myFix = fix;
|
||||
myText = myFix.getName();
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class LocalQuickFixWrapper extends QuickFixAction {
|
||||
@NotNull final Set<PsiElement> ignoredElements) {
|
||||
final PsiModificationTracker tracker = PsiManager.getInstance(project).getModificationTracker();
|
||||
if (myFix instanceof BatchQuickFix) {
|
||||
final ArrayList<PsiElement> collectedElementsToIgnore = new ArrayList<PsiElement>();
|
||||
final List<PsiElement> collectedElementsToIgnore = new ArrayList<PsiElement>();
|
||||
final Runnable refreshViews = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -105,13 +106,13 @@ public class LocalQuickFixWrapper extends QuickFixAction {
|
||||
ignore(ignoredElements, descriptor, getWorkingQuickFix(descriptor.getFixes()));
|
||||
}
|
||||
|
||||
final RefManager refManager = myTool.getContext().getRefManager();
|
||||
final RefManager refManager = myToolWrapper.getContext().getRefManager();
|
||||
final RefElement[] refElements = new RefElement[collectedElementsToIgnore.size()];
|
||||
for (int i = 0, collectedElementsToIgnoreSize = collectedElementsToIgnore.size(); i < collectedElementsToIgnoreSize; i++) {
|
||||
refElements[i] = refManager.getReference(collectedElementsToIgnore.get(i));
|
||||
}
|
||||
|
||||
removeElements(refElements, project, myTool);
|
||||
removeElements(refElements, project, myToolWrapper);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,7 +144,9 @@ public class LocalQuickFixWrapper extends QuickFixAction {
|
||||
|
||||
private void ignore(@NotNull Set<PsiElement> ignoredElements, @NotNull CommonProblemDescriptor descriptor, @Nullable QuickFix fix) {
|
||||
if (fix != null) {
|
||||
((DescriptorProviderInspection)myTool).ignoreProblem(descriptor, fix);
|
||||
InspectionToolPresentation presentation =
|
||||
((GlobalInspectionContextImpl)myToolWrapper.getContext()).getPresentation(myToolWrapper);
|
||||
presentation.ignoreProblem(descriptor, fix);
|
||||
}
|
||||
if (descriptor instanceof ProblemDescriptor) {
|
||||
ignoredElements.add(((ProblemDescriptor)descriptor).getPsiElement());
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PlainTextFormatter implements InspectionsReportConverter {
|
||||
continue;
|
||||
}
|
||||
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)tools.get(fileNameWithoutExt).getTool();
|
||||
InspectionToolWrapper toolWrapper = tools.get(fileNameWithoutExt).getTool();
|
||||
|
||||
// Tool name and group
|
||||
w.append(getToolPresentableName(toolWrapper)).append("\n");
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInspection.CommonProblemDescriptor;
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
@@ -52,19 +53,19 @@ import java.util.*;
|
||||
* @author max
|
||||
*/
|
||||
public class QuickFixAction extends AnAction {
|
||||
protected InspectionTool myTool;
|
||||
protected final InspectionToolWrapper myToolWrapper;
|
||||
|
||||
public static InspectionResultsView getInvoker(AnActionEvent e) {
|
||||
return InspectionResultsView.DATA_KEY.getData(e.getDataContext());
|
||||
}
|
||||
|
||||
protected QuickFixAction(String text, @NotNull InspectionTool tool) {
|
||||
this(text, AllIcons.Actions.CreateFromUsage, null, tool);
|
||||
protected QuickFixAction(String text, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
this(text, AllIcons.Actions.CreateFromUsage, null, toolWrapper);
|
||||
}
|
||||
|
||||
protected QuickFixAction(String text, Icon icon, KeyStroke keyStroke, @NotNull InspectionTool tool) {
|
||||
protected QuickFixAction(String text, Icon icon, KeyStroke keyStroke, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(text, null, icon);
|
||||
myTool = tool;
|
||||
myToolWrapper = toolWrapper;
|
||||
if (keyStroke != null) {
|
||||
registerCustomShortcutSet(new CustomShortcutSet(keyStroke), null);
|
||||
}
|
||||
@@ -79,8 +80,8 @@ public class QuickFixAction extends AnAction {
|
||||
}
|
||||
|
||||
final InspectionTree tree = view.getTree();
|
||||
final InspectionTool tool = tree.getSelectedTool();
|
||||
if (!view.isSingleToolInSelection() || tool != myTool) {
|
||||
final InspectionToolWrapper toolWrapper = tree.getSelectedToolWrapper();
|
||||
if (!view.isSingleToolInSelection() || toolWrapper != myToolWrapper) {
|
||||
e.getPresentation().setVisible(false);
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
@@ -131,12 +132,9 @@ public class QuickFixAction extends AnAction {
|
||||
}
|
||||
}
|
||||
|
||||
if (!readOnlyFiles.isEmpty()) {
|
||||
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(VfsUtil.toVirtualFileArray(readOnlyFiles));
|
||||
if (operationStatus.hasReadonlyFiles()) return;
|
||||
}
|
||||
if (!FileModificationService.getInstance().prepareVirtualFilesForWrite(project, readOnlyFiles)) return;
|
||||
|
||||
final RefManagerImpl refManager = (RefManagerImpl)myTool.getContext().getRefManager();
|
||||
final RefManagerImpl refManager = (RefManagerImpl)myToolWrapper.getContext().getRefManager();
|
||||
|
||||
final boolean initial = refManager.isInProcess();
|
||||
|
||||
@@ -162,22 +160,22 @@ public class QuickFixAction extends AnAction {
|
||||
}
|
||||
}, getTemplatePresentation().getText(), null);
|
||||
|
||||
refreshViews(project, ignoredElements, myTool);
|
||||
refreshViews(project, ignoredElements, myToolWrapper);
|
||||
}
|
||||
finally { //to make offline view lazy
|
||||
if (initial) refManager.inspectionReadActionStarted();
|
||||
}
|
||||
}
|
||||
|
||||
public void doApplyFix(final RefElement[] refElements, InspectionResultsView view) {
|
||||
final RefManagerImpl refManager = (RefManagerImpl)myTool.getContext().getRefManager();
|
||||
public void doApplyFix(@NotNull final RefElement[] refElements, @NotNull InspectionResultsView view) {
|
||||
final RefManagerImpl refManager = (RefManagerImpl)view.getGlobalInspectionContext().getRefManager();
|
||||
|
||||
final boolean initial = refManager.isInProcess();
|
||||
|
||||
refManager.inspectionReadActionFinished();
|
||||
|
||||
try {
|
||||
final boolean[] refreshNeeded = new boolean[]{false};
|
||||
final boolean[] refreshNeeded = {false};
|
||||
if (refElements.length > 0) {
|
||||
final Project project = refElements[0].getRefManager().getProject();
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@@ -194,7 +192,7 @@ public class QuickFixAction extends AnAction {
|
||||
}, getTemplatePresentation().getText(), null);
|
||||
}
|
||||
if (refreshNeeded[0]) {
|
||||
refreshViews(view.getProject(), refElements, myTool);
|
||||
refreshViews(view.getProject(), refElements, myToolWrapper);
|
||||
}
|
||||
}
|
||||
finally { //to make offline view lazy
|
||||
@@ -202,8 +200,8 @@ public class QuickFixAction extends AnAction {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeElements(final RefElement[] refElements, final Project project, final InspectionTool tool) {
|
||||
refreshViews(project, refElements, tool);
|
||||
public static void removeElements(@NotNull RefElement[] refElements, @NotNull Project project, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
refreshViews(project, refElements, toolWrapper);
|
||||
final ArrayList<RefElement> deletedRefs = new ArrayList<RefElement>(1);
|
||||
for (RefElement refElement : refElements) {
|
||||
if (refElement == null) continue;
|
||||
@@ -261,18 +259,18 @@ public class QuickFixAction extends AnAction {
|
||||
return selection.toArray(new RefElement[selection.size()]);
|
||||
}
|
||||
|
||||
private static void refreshViews(final Project project, final Set<PsiElement> selectedElements, final InspectionTool tool) {
|
||||
private static void refreshViews(@NotNull Project project, @NotNull Set<PsiElement> selectedElements, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
InspectionManagerEx managerEx = (InspectionManagerEx)InspectionManager.getInstance(project);
|
||||
final Set<GlobalInspectionContextImpl> runningContexts = managerEx.getRunningContexts();
|
||||
for (GlobalInspectionContextImpl context : runningContexts) {
|
||||
for (PsiElement element : selectedElements) {
|
||||
context.ignoreElement(tool, element);
|
||||
context.ignoreElement(toolWrapper.getTool(), element);
|
||||
}
|
||||
context.refreshViews();
|
||||
}
|
||||
}
|
||||
|
||||
private static void refreshViews(final Project project, final RefElement[] refElements, final InspectionTool tool) {
|
||||
private static void refreshViews(@NotNull Project project, @NotNull RefElement[] refElements, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
final Set<PsiElement> ignoredElements = new HashSet<PsiElement>();
|
||||
for (RefElement element : refElements) {
|
||||
final PsiElement psiElement = element != null ? element.getElement() : null;
|
||||
@@ -280,7 +278,7 @@ public class QuickFixAction extends AnAction {
|
||||
ignoredElements.add(psiElement);
|
||||
}
|
||||
}
|
||||
refreshViews(project, ignoredElements, tool);
|
||||
refreshViews(project, ignoredElements, toolWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeInspection.InspectionEP;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.Factory;
|
||||
|
||||
public class SpecialToolsManager {
|
||||
public SpecialToolsManager(InspectionToolRegistrar inspectionToolRegistrar) {
|
||||
registerSpecialTools(inspectionToolRegistrar);
|
||||
}
|
||||
|
||||
private static final ExtensionPointName<InspectionEP> SPECIAL_TOOL = ExtensionPointName.create("com.intellij.specialTool");
|
||||
|
||||
private static void registerSpecialTools(InspectionToolRegistrar inspectionToolRegistrar) {
|
||||
InspectionEP[] specials = Extensions.getExtensions(SPECIAL_TOOL);
|
||||
if (specials.length == 0) return;
|
||||
for (final InspectionEP ep : specials) {
|
||||
inspectionToolRegistrar.registerInspectionToolFactory(new Factory<InspectionToolWrapper>() {
|
||||
@Override
|
||||
public InspectionToolWrapper create() {
|
||||
return new CommonInspectionToolWrapper(ep);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-10
@@ -25,7 +25,7 @@
|
||||
package com.intellij.codeInspection.export;
|
||||
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -37,12 +37,11 @@ import java.util.List;
|
||||
public class HTMLExportFrameMaker {
|
||||
private final String myRootFolder;
|
||||
private final Project myProject;
|
||||
private final List<InspectionTool> myInspectionTools;
|
||||
private final List<InspectionToolWrapper> myInspectionToolWrappers = new ArrayList<InspectionToolWrapper>();
|
||||
|
||||
public HTMLExportFrameMaker(String rootFolder, Project project) {
|
||||
myRootFolder = rootFolder;
|
||||
myProject = project;
|
||||
myInspectionTools = new ArrayList<InspectionTool>();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
@@ -56,19 +55,19 @@ public class HTMLExportFrameMaker {
|
||||
public void done() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
for (InspectionTool tool : myInspectionTools) {
|
||||
for (InspectionToolWrapper toolWrapper : myInspectionToolWrappers) {
|
||||
buf.append("<A HREF=\"");
|
||||
buf.append(tool.getFolderName());
|
||||
buf.append(toolWrapper.getFolderName());
|
||||
buf.append("-index.html\">");
|
||||
buf.append(tool.getDisplayName());
|
||||
buf.append(toolWrapper.getDisplayName());
|
||||
buf.append("</A><BR>");
|
||||
}
|
||||
|
||||
HTMLExportUtil.writeFile(myRootFolder, "index.html", buf, myProject);
|
||||
}
|
||||
|
||||
public void startInspection(@NotNull InspectionTool tool) {
|
||||
myInspectionTools.add(tool);
|
||||
public void startInspection(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
myInspectionToolWrappers.add(toolWrapper);
|
||||
@NonNls StringBuffer buf = new StringBuffer();
|
||||
buf.append("<HTML><HEAD><TITLE>");
|
||||
buf.append(ApplicationNamesInfo.getInstance().getFullProductName());
|
||||
@@ -76,14 +75,14 @@ public class HTMLExportFrameMaker {
|
||||
buf.append("</TITLE></HEAD>");
|
||||
buf.append("<FRAMESET cols=\"30%,70%\"><FRAMESET rows=\"30%,70%\">");
|
||||
buf.append("<FRAME src=\"");
|
||||
buf.append(tool.getFolderName());
|
||||
buf.append(toolWrapper.getFolderName());
|
||||
buf.append("/index.html\" name=\"inspectionFrame\">");
|
||||
buf.append("<FRAME src=\"empty.html\" name=\"packageFrame\">");
|
||||
buf.append("</FRAMESET>");
|
||||
buf.append("<FRAME src=\"empty.html\" name=\"elementFrame\">");
|
||||
buf.append("</FRAMESET></BODY></HTML");
|
||||
|
||||
HTMLExportUtil.writeFile(myRootFolder, tool.getFolderName() + "-index.html", buf, myProject);
|
||||
HTMLExportUtil.writeFile(myRootFolder, toolWrapper.getFolderName() + "-index.html", buf, myProject);
|
||||
}
|
||||
|
||||
public String getRootFolder() {
|
||||
|
||||
+29
-25
@@ -52,14 +52,15 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkReportedProblems(@NotNull final InspectionToolWrapper toolWrapper) {
|
||||
final Map<String, Set<OfflineProblemDescriptor>> content = getFilteredContent(toolWrapper);
|
||||
public boolean checkReportedProblems(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull final InspectionToolWrapper toolWrapper) {
|
||||
final Map<String, Set<OfflineProblemDescriptor>> content = getFilteredContent(context, toolWrapper);
|
||||
return content != null && !content.values().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final InspectionTool tool, @NotNull final InspectionTree tree) {
|
||||
public QuickFixAction[] getQuickFixes(@NotNull final InspectionToolWrapper toolWrapper, @NotNull final InspectionTree tree) {
|
||||
final TreePath[] treePaths = tree.getSelectionPaths();
|
||||
final List<RefEntity> selectedElements = new ArrayList<RefEntity>();
|
||||
final Map<RefEntity, Set<QuickFix>> actions = new HashMap<RefEntity, Set<QuickFix>>();
|
||||
@@ -97,11 +98,8 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
|
||||
final RefEntity[] selectedRefElements = selectedElements.toArray(new RefEntity[selectedElements.size()]);
|
||||
|
||||
if (tool instanceof DescriptorProviderInspection && !(tool instanceof CommonInspectionToolWrapper)) {
|
||||
return ((DescriptorProviderInspection)tool).extractActiveFixes(selectedRefElements, actions);
|
||||
}
|
||||
|
||||
return tool.getQuickFixes(selectedRefElements);
|
||||
InspectionToolPresentation presentation = ((GlobalInspectionContextImpl)toolWrapper.getContext()).getPresentation(toolWrapper);
|
||||
return presentation.extractActiveFixes(selectedRefElements, actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,14 +108,15 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendToolNodeContent(final InspectionNode toolNode,
|
||||
final InspectionTreeNode parentNode,
|
||||
public void appendToolNodeContent(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull final InspectionNode toolNode,
|
||||
@NotNull final InspectionTreeNode parentNode,
|
||||
final boolean showStructure,
|
||||
final Map<String, Set<RefEntity>> contents,
|
||||
final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
@NotNull final Map<String, Set<RefEntity>> contents,
|
||||
@NotNull final Map<RefEntity, CommonProblemDescriptor[]> problems,
|
||||
final DefaultTreeModel model) {
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
final Map<String, Set<OfflineProblemDescriptor>> filteredContent = getFilteredContent(tool);
|
||||
InspectionToolWrapper toolWrapper = toolNode.getToolWrapper();
|
||||
final Map<String, Set<OfflineProblemDescriptor>> filteredContent = getFilteredContent(context, toolWrapper);
|
||||
if (filteredContent != null && !filteredContent.values().isEmpty()) {
|
||||
final Function<OfflineProblemDescriptor, UserObjectContainer<OfflineProblemDescriptor>> computeContainer =
|
||||
new Function<OfflineProblemDescriptor, UserObjectContainer<OfflineProblemDescriptor>>() {
|
||||
@@ -126,7 +125,7 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
return new OfflineProblemDescriptorContainer(descriptor);
|
||||
}
|
||||
};
|
||||
final List<InspectionTreeNode> list = buildTree(filteredContent, false, tool, computeContainer, showStructure);
|
||||
final List<InspectionTreeNode> list = buildTree(context, filteredContent, false, toolWrapper, computeContainer, showStructure);
|
||||
for (InspectionTreeNode node : list) {
|
||||
toolNode.add(node);
|
||||
}
|
||||
@@ -136,13 +135,15 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings({"UnusedAssignment"})
|
||||
private Map<String, Set<OfflineProblemDescriptor>> getFilteredContent(@NotNull InspectionTool tool) {
|
||||
Map<String, Set<OfflineProblemDescriptor>> content = myContent.get(tool.getShortName());
|
||||
private Map<String, Set<OfflineProblemDescriptor>> getFilteredContent(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull InspectionToolWrapper toolWrapper) {
|
||||
Map<String, Set<OfflineProblemDescriptor>> content = myContent.get(toolWrapper.getShortName());
|
||||
if (content == null) return null;
|
||||
if (tool.getContext().getUIOptions().FILTER_RESOLVED_ITEMS) {
|
||||
if (context.getUIOptions().FILTER_RESOLVED_ITEMS) {
|
||||
final Map<String, Set<OfflineProblemDescriptor>> current = new HashMap<String, Set<OfflineProblemDescriptor>>(content);
|
||||
content = null; //GC it
|
||||
for (RefEntity refEntity : tool.getIgnoredRefElements()) {
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
for (RefEntity refEntity : presentation.getIgnoredRefElements()) {
|
||||
if (refEntity instanceof RefElement) {
|
||||
excludeProblem(refEntity.getExternalName(), current);
|
||||
}
|
||||
@@ -171,13 +172,16 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendDescriptor(@NotNull final InspectionTool tool,
|
||||
protected void appendDescriptor(@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull final InspectionToolWrapper toolWrapper,
|
||||
@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)) {
|
||||
elemNode.add(new OfflineProblemDescriptorNode(((OfflineProblemDescriptorContainer)container).getUserObject(), (DescriptorProviderInspection)tool));
|
||||
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
||||
final RefElementNode elemNode = addNodeToParent(container, presentation, packageNode);
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
elemNode.add(new OfflineProblemDescriptorNode(((OfflineProblemDescriptorContainer)container).getUserObject(),
|
||||
(LocalInspectionToolWrapper)toolWrapper));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,8 +207,8 @@ public class OfflineInspectionRVContentProvider extends InspectionRVContentProvi
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RefElementNode createNode(@NotNull InspectionTool tool) {
|
||||
return new OfflineRefElementNode(myDescriptor, tool);
|
||||
public RefElementNode createNode(@NotNull InspectionToolPresentation presentation) {
|
||||
return new OfflineRefElementNode(myDescriptor, presentation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+32
-28
@@ -24,25 +24,28 @@ import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.DescriptorProviderInspection;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.QuickFixWrapper;
|
||||
import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.ui.ProblemDescriptionNode;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
|
||||
public OfflineProblemDescriptorNode(final OfflineProblemDescriptor descriptor,
|
||||
final DescriptorProviderInspection tool) {
|
||||
super(descriptor, tool);
|
||||
public OfflineProblemDescriptorNode(final OfflineProblemDescriptor descriptor, @NotNull LocalInspectionToolWrapper toolWrapper) {
|
||||
super(descriptor, toolWrapper);
|
||||
}
|
||||
|
||||
private static PsiElement[] getElementsIntersectingRange(PsiFile file, final int startOffset, final int endOffset) {
|
||||
@@ -66,7 +69,7 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
if (userObject == null) {
|
||||
return null;
|
||||
}
|
||||
myElement = ((OfflineProblemDescriptor)userObject).getRefElement(myTool.getContext().getRefManager());
|
||||
myElement = ((OfflineProblemDescriptor)userObject).getRefElement(myToolWrapper.getContext().getRefManager());
|
||||
return myElement;
|
||||
}
|
||||
|
||||
@@ -77,42 +80,41 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
if (userObject instanceof CommonProblemDescriptor) {
|
||||
return (CommonProblemDescriptor)userObject;
|
||||
}
|
||||
final InspectionManager inspectionManager = InspectionManager.getInstance(myTool.getContext().getProject());
|
||||
|
||||
final InspectionManager inspectionManager = InspectionManager.getInstance(myToolWrapper.getContext().getProject());
|
||||
final OfflineProblemDescriptor offlineProblemDescriptor = (OfflineProblemDescriptor)userObject;
|
||||
final RefEntity element = getElement();
|
||||
if (myTool instanceof LocalInspectionToolWrapper) {
|
||||
if (myToolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
if (element instanceof RefElement) {
|
||||
final PsiElement psiElement = ((RefElement)element).getElement();
|
||||
if (psiElement != null) {
|
||||
PsiFile containingFile = psiElement.getContainingFile();
|
||||
final ProblemsHolder holder = new ProblemsHolder(inspectionManager, containingFile, false);
|
||||
final LocalInspectionTool localInspectionTool = ((LocalInspectionToolWrapper)myTool).getTool();
|
||||
final LocalInspectionTool localTool = ((LocalInspectionToolWrapper)myToolWrapper).getTool();
|
||||
final int startOffset = psiElement.getTextRange().getStartOffset();
|
||||
final int endOffset = psiElement.getTextRange().getEndOffset();
|
||||
LocalInspectionToolSession session = new LocalInspectionToolSession(containingFile, startOffset, endOffset);
|
||||
final PsiElementVisitor visitor = localInspectionTool.buildVisitor(holder, false, session);
|
||||
localInspectionTool.inspectionStarted(session, false);
|
||||
final PsiElementVisitor visitor = localTool.buildVisitor(holder, false, session);
|
||||
localTool.inspectionStarted(session, false);
|
||||
final PsiElement[] elementsInRange = getElementsIntersectingRange(containingFile,
|
||||
startOffset,
|
||||
endOffset);
|
||||
for (PsiElement el : elementsInRange) {
|
||||
el.accept(visitor);
|
||||
}
|
||||
localInspectionTool.inspectionFinished(session, holder);
|
||||
localTool.inspectionFinished(session, holder);
|
||||
if (holder.hasResults()) {
|
||||
final List<ProblemDescriptor> list = holder.getResults();
|
||||
final int idx = offlineProblemDescriptor.getProblemIndex();
|
||||
if (list != null) {
|
||||
int curIdx = 0;
|
||||
for (ProblemDescriptor descriptor : list) {
|
||||
final PsiNamedElement member = localInspectionTool.getProblemElement(descriptor.getPsiElement());
|
||||
if (psiElement instanceof PsiFile || member != null && member.equals(psiElement)) {
|
||||
if (curIdx == idx) {
|
||||
setUserObject(descriptor);
|
||||
return descriptor;
|
||||
}
|
||||
curIdx++;
|
||||
int curIdx = 0;
|
||||
for (ProblemDescriptor descriptor : list) {
|
||||
final PsiNamedElement member = localTool.getProblemElement(descriptor.getPsiElement());
|
||||
if (psiElement instanceof PsiFile || member != null && member.equals(psiElement)) {
|
||||
if (curIdx == idx) {
|
||||
setUserObject(descriptor);
|
||||
return descriptor;
|
||||
}
|
||||
curIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,11 +149,12 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LocalQuickFix[] getFixes(CommonProblemDescriptor descriptor, List<String> hints) {
|
||||
final List<LocalQuickFix> fixes = new ArrayList<LocalQuickFix>();
|
||||
private LocalQuickFix[] getFixes(@NotNull CommonProblemDescriptor descriptor, List<String> hints) {
|
||||
final List<LocalQuickFix> fixes = new ArrayList<LocalQuickFix>(hints == null ? 1 : hints.size());
|
||||
if (hints == null) {
|
||||
addFix(descriptor, fixes, null);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (String hint : hints) {
|
||||
addFix(descriptor, fixes, hint);
|
||||
}
|
||||
@@ -159,8 +162,9 @@ public class OfflineProblemDescriptorNode extends ProblemDescriptionNode {
|
||||
return fixes.isEmpty() ? null : fixes.toArray(new LocalQuickFix[fixes.size()]);
|
||||
}
|
||||
|
||||
private void addFix(final CommonProblemDescriptor descriptor, final List<LocalQuickFix> fixes, String hint) {
|
||||
final IntentionAction intentionAction = myTool.findQuickFixes(descriptor, hint);
|
||||
private void addFix(@NotNull CommonProblemDescriptor descriptor, final List<LocalQuickFix> fixes, String hint) {
|
||||
InspectionToolPresentation presentation = ((GlobalInspectionContextImpl)myToolWrapper.getContext()).getPresentation(myToolWrapper);
|
||||
final IntentionAction intentionAction = presentation.findQuickFixes(descriptor, hint);
|
||||
if (intentionAction instanceof QuickFixWrapper) {
|
||||
fixes.add(((QuickFixWrapper)intentionAction).getFix());
|
||||
}
|
||||
|
||||
+4
-5
@@ -20,17 +20,16 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.offlineViewer;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.offline.OfflineProblemDescriptor;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.ui.RefElementNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class OfflineRefElementNode extends RefElementNode {
|
||||
|
||||
public OfflineRefElementNode(@NotNull OfflineProblemDescriptor descriptor, @NotNull InspectionTool inspectionTool) {
|
||||
super(descriptor, inspectionTool);
|
||||
public OfflineRefElementNode(@NotNull OfflineProblemDescriptor descriptor, @NotNull InspectionToolPresentation presentation) {
|
||||
super(descriptor, presentation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +39,7 @@ public class OfflineRefElementNode extends RefElementNode {
|
||||
return (RefEntity)userObject;
|
||||
}
|
||||
if (userObject == null) return null;
|
||||
final RefEntity refElement = ((OfflineProblemDescriptor)userObject).getRefElement(myTool.getContext().getRefManager());
|
||||
final RefEntity refElement = ((OfflineProblemDescriptor)userObject).getRefElement(myToolPresentation.getContext().getRefManager());
|
||||
setUserObject(refElement);
|
||||
return refElement;
|
||||
}
|
||||
|
||||
@@ -121,15 +121,15 @@ class Browser extends JPanel {
|
||||
void referenceClicked(ClickEvent e);
|
||||
}
|
||||
|
||||
private void showPageFromHistory(RefEntity newEntity) {
|
||||
InspectionTool tool = getTool(newEntity);
|
||||
private void showPageFromHistory(@NotNull RefEntity newEntity) {
|
||||
InspectionToolWrapper toolWrapper = getToolWrapper(newEntity);
|
||||
try {
|
||||
if (tool instanceof DescriptorProviderInspection && !(tool instanceof CommonInspectionToolWrapper)) {
|
||||
if (!(toolWrapper instanceof CommonInspectionToolWrapper)) {
|
||||
showEmpty();
|
||||
}
|
||||
else {
|
||||
try {
|
||||
String html = generateHTML(newEntity, tool);
|
||||
String html = generateHTML(newEntity, toolWrapper);
|
||||
myHTMLViewer.read(new StringReader(html), null);
|
||||
setupStyle();
|
||||
myHTMLViewer.setCaretPosition(0);
|
||||
@@ -182,83 +182,7 @@ class Browser extends JPanel {
|
||||
myHyperLinkListener = new HyperlinkListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent e) {
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
JEditorPane pane = (JEditorPane)e.getSource();
|
||||
if (e instanceof HTMLFrameHyperlinkEvent) {
|
||||
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
|
||||
HTMLDocument doc = (HTMLDocument)pane.getDocument();
|
||||
doc.processHTMLFrameHyperlinkEvent(evt);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
URL url = e.getURL();
|
||||
@NonNls String ref = url.getRef();
|
||||
if (ref.startsWith("pos:")) {
|
||||
int delimeterPos = ref.indexOf(':', "pos:".length() + 1);
|
||||
String startPosition = ref.substring("pos:".length(), delimeterPos);
|
||||
String endPosition = ref.substring(delimeterPos + 1);
|
||||
Integer textStartOffset = new Integer(startPosition);
|
||||
Integer textEndOffset = new Integer(endPosition);
|
||||
String fileURL = url.toExternalForm();
|
||||
fileURL = fileURL.substring(0, fileURL.indexOf('#'));
|
||||
VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
|
||||
if (vFile != null) {
|
||||
fireClickEvent(vFile, textStartOffset.intValue(), textEndOffset.intValue());
|
||||
}
|
||||
}
|
||||
else if (ref.startsWith("descr:")) {
|
||||
if (myCurrentDescriptor instanceof ProblemDescriptor) {
|
||||
PsiElement psiElement = ((ProblemDescriptor)myCurrentDescriptor).getPsiElement();
|
||||
if (psiElement == null) return;
|
||||
VirtualFile vFile = psiElement.getContainingFile().getVirtualFile();
|
||||
if (vFile != null) {
|
||||
TextRange range = ((ProblemDescriptorBase)myCurrentDescriptor).getTextRange();
|
||||
fireClickEvent(vFile, range.getStartOffset(), range.getEndOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ref.startsWith("invoke:")) {
|
||||
int actionNumber = Integer.parseInt(ref.substring("invoke:".length()));
|
||||
getTool().getQuickFixes(new RefElement[]{(RefElement)myCurrentEntity})[actionNumber]
|
||||
.doApplyFix(new RefElement[]{(RefElement)myCurrentEntity}, myView);
|
||||
}
|
||||
else if (ref.startsWith("invokelocal:")) {
|
||||
int actionNumber = Integer.parseInt(ref.substring("invokelocal:".length()));
|
||||
if (actionNumber > -1) {
|
||||
invokeLocalFix(actionNumber);
|
||||
}
|
||||
} else if (ref.startsWith("suppress:")){
|
||||
final SuppressActionWrapper.SuppressTreeAction[] suppressTreeActions =
|
||||
new SuppressActionWrapper(myView.getProject(), getTool(), myView.getTree().getSelectionPaths()).getChildren(null);
|
||||
final List<AnAction> activeActions = new ArrayList<AnAction>();
|
||||
for (SuppressActionWrapper.SuppressTreeAction suppressTreeAction : suppressTreeActions) {
|
||||
if (suppressTreeAction.isAvailable()) activeActions.add(suppressTreeAction);
|
||||
}
|
||||
if (!activeActions.isEmpty()) {
|
||||
int actionNumber = Integer.parseInt(ref.substring("suppress:".length()));
|
||||
if (actionNumber > -1 && activeActions.size() > actionNumber) {
|
||||
activeActions.get(actionNumber).actionPerformed(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
int offset = Integer.parseInt(ref);
|
||||
String fileURL = url.toExternalForm();
|
||||
fileURL = fileURL.substring(0, fileURL.indexOf('#'));
|
||||
VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
|
||||
if (vFile == null) {
|
||||
vFile = VfsUtil.findFileByURL(url);
|
||||
}
|
||||
if (vFile != null) {
|
||||
fireClickEvent(vFile, offset, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
//???
|
||||
}
|
||||
}
|
||||
}
|
||||
Browser.this.hyperlinkUpdate(e);
|
||||
}
|
||||
};
|
||||
myHTMLViewer.addHyperlinkListener(myHyperLinkListener);
|
||||
@@ -269,6 +193,88 @@ class Browser extends JPanel {
|
||||
setupStyle();
|
||||
}
|
||||
|
||||
private void hyperlinkUpdate(HyperlinkEvent e) {
|
||||
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
|
||||
return;
|
||||
}
|
||||
JEditorPane pane = (JEditorPane)e.getSource();
|
||||
if (e instanceof HTMLFrameHyperlinkEvent) {
|
||||
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
|
||||
HTMLDocument doc = (HTMLDocument)pane.getDocument();
|
||||
doc.processHTMLFrameHyperlinkEvent(evt);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
URL url = e.getURL();
|
||||
@NonNls String ref = url.getRef();
|
||||
if (ref.startsWith("pos:")) {
|
||||
int delimeterPos = ref.indexOf(':', "pos:".length() + 1);
|
||||
String startPosition = ref.substring("pos:".length(), delimeterPos);
|
||||
String endPosition = ref.substring(delimeterPos + 1);
|
||||
Integer textStartOffset = new Integer(startPosition);
|
||||
Integer textEndOffset = new Integer(endPosition);
|
||||
String fileURL = url.toExternalForm();
|
||||
fileURL = fileURL.substring(0, fileURL.indexOf('#'));
|
||||
VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
|
||||
if (vFile != null) {
|
||||
fireClickEvent(vFile, textStartOffset.intValue(), textEndOffset.intValue());
|
||||
}
|
||||
}
|
||||
else if (ref.startsWith("descr:")) {
|
||||
if (myCurrentDescriptor instanceof ProblemDescriptor) {
|
||||
PsiElement psiElement = ((ProblemDescriptor)myCurrentDescriptor).getPsiElement();
|
||||
if (psiElement == null) return;
|
||||
VirtualFile vFile = psiElement.getContainingFile().getVirtualFile();
|
||||
if (vFile != null) {
|
||||
TextRange range = ((ProblemDescriptorBase)myCurrentDescriptor).getTextRange();
|
||||
fireClickEvent(vFile, range.getStartOffset(), range.getEndOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ref.startsWith("invoke:")) {
|
||||
int actionNumber = Integer.parseInt(ref.substring("invoke:".length()));
|
||||
InspectionToolWrapper toolWrapper = getToolWrapper();
|
||||
InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(toolWrapper);
|
||||
QuickFixAction fixAction = presentation.getQuickFixes(new RefElement[]{(RefElement)myCurrentEntity})[actionNumber];
|
||||
fixAction.doApplyFix(new RefElement[]{(RefElement)myCurrentEntity}, myView);
|
||||
}
|
||||
else if (ref.startsWith("invokelocal:")) {
|
||||
int actionNumber = Integer.parseInt(ref.substring("invokelocal:".length()));
|
||||
if (actionNumber > -1) {
|
||||
invokeLocalFix(actionNumber);
|
||||
}
|
||||
} else if (ref.startsWith("suppress:")){
|
||||
final SuppressActionWrapper.SuppressTreeAction[] suppressTreeActions =
|
||||
new SuppressActionWrapper(myView.getProject(), getToolWrapper(), myView.getTree().getSelectionPaths()).getChildren(null);
|
||||
final List<AnAction> activeActions = new ArrayList<AnAction>();
|
||||
for (SuppressActionWrapper.SuppressTreeAction suppressTreeAction : suppressTreeActions) {
|
||||
if (suppressTreeAction.isAvailable()) activeActions.add(suppressTreeAction);
|
||||
}
|
||||
if (!activeActions.isEmpty()) {
|
||||
int actionNumber = Integer.parseInt(ref.substring("suppress:".length()));
|
||||
if (actionNumber > -1 && activeActions.size() > actionNumber) {
|
||||
activeActions.get(actionNumber).actionPerformed(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
int offset = Integer.parseInt(ref);
|
||||
String fileURL = url.toExternalForm();
|
||||
fileURL = fileURL.substring(0, fileURL.indexOf('#'));
|
||||
VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
|
||||
if (vFile == null) {
|
||||
vFile = VfsUtil.findFileByURL(url);
|
||||
}
|
||||
if (vFile != null) {
|
||||
fireClickEvent(vFile, offset, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
//???
|
||||
}
|
||||
}
|
||||
|
||||
private void setupStyle() {
|
||||
Document document = myHTMLViewer.getDocument();
|
||||
if (!(document instanceof StyledDocument)) {
|
||||
@@ -298,19 +304,19 @@ class Browser extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private String generateHTML(final RefEntity refEntity, final InspectionTool tool) {
|
||||
private String generateHTML(final RefEntity refEntity, @NotNull final InspectionToolWrapper toolWrapper) {
|
||||
final StringBuffer buf = new StringBuffer();
|
||||
final HTMLComposerImpl htmlComposer = getPresentation(toolWrapper).getComposer();
|
||||
if (refEntity instanceof RefElement) {
|
||||
final Runnable action = new Runnable() {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tool.getComposer().compose(buf, refEntity);
|
||||
htmlComposer.compose(buf, refEntity);
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().runReadAction(action);
|
||||
});
|
||||
}
|
||||
else {
|
||||
tool.getComposer().compose(buf, refEntity);
|
||||
htmlComposer.compose(buf, refEntity);
|
||||
}
|
||||
|
||||
uppercaseFirstLetter(buf);
|
||||
@@ -324,6 +330,10 @@ class Browser extends JPanel {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static InspectionToolPresentation getPresentation(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
return ((GlobalInspectionContextImpl)toolWrapper.getContext()).getPresentation(toolWrapper);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
private static void insertHeaderFooter(final StringBuffer buf) {
|
||||
buf.insert(0, "<HTML><BODY>");
|
||||
@@ -335,8 +345,8 @@ class Browser extends JPanel {
|
||||
final Runnable action = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InspectionTool tool = getTool(refEntity);
|
||||
tool.getComposer().compose(buf, refEntity, descriptor);
|
||||
InspectionToolWrapper toolWrapper = getToolWrapper(refEntity);
|
||||
getPresentation(toolWrapper).getComposer().compose(buf, refEntity, descriptor);
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().runReadAction(action);
|
||||
@@ -351,27 +361,25 @@ class Browser extends JPanel {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private InspectionTool getTool(final RefEntity refEntity) {
|
||||
InspectionTool tool = getTool();
|
||||
assert tool != null;
|
||||
final GlobalInspectionContextImpl manager = tool.getContext();
|
||||
if (manager == null) return tool;
|
||||
private InspectionToolWrapper getToolWrapper(final RefEntity refEntity) {
|
||||
InspectionToolWrapper toolWrapper = getToolWrapper();
|
||||
assert toolWrapper != null;
|
||||
final GlobalInspectionContextImpl context = myView.getGlobalInspectionContext();
|
||||
if (refEntity instanceof RefElement){
|
||||
PsiElement element = ((RefElement)refEntity).getElement();
|
||||
if (element == null) return tool;
|
||||
InspectionProfileWrapper profileWrapper = InspectionProjectProfileManagerImpl.getInstanceImpl(manager.getProject()).getProfileWrapper();
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)profileWrapper.getInspectionTool(tool.getShortName(), element);
|
||||
tool = toolWrapper;
|
||||
if (element == null) return toolWrapper;
|
||||
InspectionProfileWrapper profileWrapper = InspectionProjectProfileManagerImpl.getInstanceImpl(context.getProject()).getProfileWrapper();
|
||||
toolWrapper = profileWrapper.getInspectionTool(toolWrapper.getShortName(), element);
|
||||
}
|
||||
return tool;
|
||||
return toolWrapper;
|
||||
}
|
||||
|
||||
private void appendSuppressSection(final StringBuffer buf) {
|
||||
final InspectionTool tool = getTool();
|
||||
if (tool != null) {
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
|
||||
final InspectionToolWrapper toolWrapper = getToolWrapper();
|
||||
if (toolWrapper != null) {
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
|
||||
if (key != null){//dummy entry points
|
||||
final SuppressActionWrapper.SuppressTreeAction[] suppressActions = new SuppressActionWrapper(myView.getProject(), tool, myView.getTree().getSelectionPaths()).getChildren(null);
|
||||
final SuppressActionWrapper.SuppressTreeAction[] suppressActions = new SuppressActionWrapper(myView.getProject(), toolWrapper, myView.getTree().getSelectionPaths()).getChildren(null);
|
||||
if (suppressActions.length > 0) {
|
||||
final List<AnAction> activeSuppressActions = new ArrayList<AnAction>();
|
||||
for (SuppressActionWrapper.SuppressTreeAction suppressAction : suppressActions) {
|
||||
@@ -419,8 +427,8 @@ class Browser extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
public void showDescription(@NotNull InspectionTool tool){
|
||||
if (tool.getShortName().isEmpty()){
|
||||
public void showDescription(@NotNull InspectionToolWrapper toolWrapper){
|
||||
if (toolWrapper.getShortName().isEmpty()){
|
||||
showEmpty();
|
||||
return;
|
||||
}
|
||||
@@ -431,7 +439,7 @@ class Browser extends JPanel {
|
||||
page.append("</td></tr>");
|
||||
page.append("<tr><td width='37'></td>" +
|
||||
"<td>");
|
||||
page.append(tool.getShortName());
|
||||
page.append(toolWrapper.getShortName());
|
||||
page.append("</td></tr>");
|
||||
page.append("<tr height='10'></tr>");
|
||||
page.append("<tr><td colspan='2'>");
|
||||
@@ -441,7 +449,7 @@ class Browser extends JPanel {
|
||||
"<td>");
|
||||
@NonNls final String underConstruction = "<b>" + UNDER_CONSTRUCTION + "</b></html>";
|
||||
try {
|
||||
@NonNls String description = tool.loadDescription();
|
||||
@NonNls String description = toolWrapper.loadDescription();
|
||||
if (description == null) {
|
||||
description = underConstruction;
|
||||
}
|
||||
@@ -457,9 +465,9 @@ class Browser extends JPanel {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private InspectionTool getTool() {
|
||||
private InspectionToolWrapper getToolWrapper() {
|
||||
if (myView != null){
|
||||
return myView.getTree().getSelectedTool();
|
||||
return myView.getTree().getSelectedToolWrapper();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -512,9 +520,11 @@ class Browser extends JPanel {
|
||||
//CCE here means QuickFix was incorrectly inherited
|
||||
fix.applyFix(myView.getProject(), descriptor);
|
||||
if (startCount != tracker.getModificationCount()) {
|
||||
final DescriptorProviderInspection tool = (DescriptorProviderInspection)myView.getTree().getSelectedTool();
|
||||
if (tool != null) {
|
||||
tool.ignoreProblem(element, descriptor, idx);
|
||||
InspectionToolWrapper toolWrapper = myView.getTree().getSelectedToolWrapper();
|
||||
if (toolWrapper != null) {
|
||||
InspectionToolPresentation presentation =
|
||||
myView.getGlobalInspectionContext().getPresentation(toolWrapper);
|
||||
presentation.ignoreProblem(element, descriptor, idx);
|
||||
}
|
||||
myView.updateView(false);
|
||||
}
|
||||
|
||||
+265
-39
@@ -13,25 +13,34 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ui;
|
||||
|
||||
package com.intellij.codeInspection.ex;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.components.PathMacroManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManagerImpl;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.IllegalDataException;
|
||||
@@ -39,13 +48,17 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public abstract class DescriptorProviderInspection extends InspectionTool implements ProblemDescriptionsProcessor {
|
||||
public class DefaultInspectionToolPresentation implements ProblemDescriptionsProcessor, InspectionToolPresentation {
|
||||
@NotNull private final InspectionToolWrapper myToolWrapper;
|
||||
|
||||
private GlobalInspectionContextImpl myContext;
|
||||
protected static String ourOutputPath;
|
||||
protected InspectionNode myToolNode;
|
||||
|
||||
private static final Object lock = new Object();
|
||||
private Map<RefEntity, CommonProblemDescriptor[]> myProblemElements;
|
||||
private Map<String, Set<RefEntity>> myContents = null;
|
||||
@@ -58,16 +71,105 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
private Map<RefEntity, CommonProblemDescriptor[]> myOldProblemElements = null;
|
||||
protected static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.DescriptorProviderInspection");
|
||||
|
||||
public DefaultInspectionToolPresentation(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
myToolWrapper = toolWrapper;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static FileStatus calcStatus(boolean old, boolean current) {
|
||||
if (old) {
|
||||
if (!current) {
|
||||
return FileStatus.DELETED;
|
||||
}
|
||||
}
|
||||
else if (current) {
|
||||
return FileStatus.ADDED;
|
||||
}
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
protected static HighlightSeverity getSeverity(@NotNull RefElement element,
|
||||
@NotNull GlobalInspectionContextImpl context,
|
||||
@NotNull InspectionToolWrapper thisToolWrapper) {
|
||||
final PsiElement psiElement = element.getPointer().getContainingFile();
|
||||
if (psiElement != null) {
|
||||
String shortName = thisToolWrapper.getShortName();
|
||||
final Tools tools = context.getTools().get(shortName);
|
||||
if (tools != null) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
if (toolWrapper == thisToolWrapper) {
|
||||
return context.getCurrentProfile().getErrorLevel(HighlightDisplayKey.find(shortName), psiElement).getSeverity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(context.getProject()).getInspectionProfile();
|
||||
final HighlightDisplayLevel level = profile.getErrorLevel(HighlightDisplayKey.find(shortName), psiElement);
|
||||
return level.getSeverity();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String getTextAttributeKey(@NotNull Project project,
|
||||
@NotNull HighlightSeverity severity,
|
||||
@NotNull ProblemHighlightType highlightType) {
|
||||
if (highlightType == ProblemHighlightType.LIKE_DEPRECATED) {
|
||||
return HighlightInfoType.DEPRECATED.getAttributesKey().getExternalName();
|
||||
}
|
||||
if (highlightType == ProblemHighlightType.LIKE_UNKNOWN_SYMBOL && severity == HighlightSeverity.ERROR) {
|
||||
return HighlightInfoType.WRONG_REF.getAttributesKey().getExternalName();
|
||||
}
|
||||
if (highlightType == ProblemHighlightType.LIKE_UNUSED_SYMBOL) {
|
||||
return HighlightInfoType.UNUSED_SYMBOL.getAttributesKey().getExternalName();
|
||||
}
|
||||
SeverityRegistrar registrar = InspectionProjectProfileManagerImpl.getInstanceImpl(project).getSeverityRegistrar();
|
||||
return registrar.getHighlightInfoTypeBySeverity(severity).getAttributesKey().getExternalName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionToolWrapper getToolWrapper() {
|
||||
return myToolWrapper;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public RefManager getRefManager() {
|
||||
return getContext().getRefManager();
|
||||
}
|
||||
@Override
|
||||
@NotNull
|
||||
public GlobalInspectionContextImpl getContext() {
|
||||
return myContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportResults(@NotNull final Element parentNode) {
|
||||
getRefManager().iterate(new RefVisitor(){
|
||||
@Override
|
||||
public void visitElement(@NotNull RefEntity elem) {
|
||||
exportResults(parentNode, elem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOldProblemsIncluded() {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
return context != null && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN && getOldContent() != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addProblemElement(RefEntity refElement, @NotNull CommonProblemDescriptor... descriptions){
|
||||
addProblemElement(refElement, true, descriptions);
|
||||
}
|
||||
|
||||
protected void addProblemElement(RefEntity refElement, boolean filterSuppressed, @NotNull CommonProblemDescriptor... descriptions) {
|
||||
@Override
|
||||
public void addProblemElement(RefEntity refElement, boolean filterSuppressed, @NotNull CommonProblemDescriptor... descriptions) {
|
||||
if (refElement == null) return;
|
||||
if (descriptions.length == 0) return;
|
||||
if (filterSuppressed) {
|
||||
if (ourOutputPath == null || !(this instanceof LocalInspectionToolWrapper)) {
|
||||
if (ourOutputPath == null || !(myToolWrapper instanceof LocalInspectionToolWrapper)) {
|
||||
synchronized (lock) {
|
||||
Map<RefEntity, CommonProblemDescriptor[]> problemElements = getProblemElements();
|
||||
CommonProblemDescriptor[] problems = problemElements.get(refElement);
|
||||
@@ -88,15 +190,59 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
getProblemToElements().put(description, refElement);
|
||||
}
|
||||
}
|
||||
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (myToolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
final InspectionResultsView view = context.getView();
|
||||
if (view == null || !(refElement instanceof RefElement)) {
|
||||
return;
|
||||
}
|
||||
InspectionNode toolNode = myToolNode;
|
||||
if (toolNode == null) {
|
||||
final HighlightSeverity currentSeverity = getSeverity((RefElement)refElement, context, myToolWrapper);
|
||||
view.addTool(myToolWrapper, 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() {
|
||||
if (!isDisposed()) {
|
||||
view.getProvider().appendToolNodeContent(context, myToolNode,
|
||||
(InspectionTreeNode)myToolNode.getParent(), context.getUIOptions().SHOW_STRUCTURE,
|
||||
contents, problems, (DefaultTreeModel)view.getTree().getModel());
|
||||
context.addView(view);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDisposed() {
|
||||
return myContext == null;
|
||||
}
|
||||
|
||||
|
||||
private void writeOutput(@NotNull final CommonProblemDescriptor[] descriptions, @NotNull RefEntity refElement) {
|
||||
final Element parentNode = new Element(InspectionsBundle.message("inspection.problems"));
|
||||
exportResults(descriptions, refElement, parentNode);
|
||||
final List list = parentNode.getChildren();
|
||||
|
||||
@NonNls final String ext = ".xml";
|
||||
final String fileName = ourOutputPath + File.separator + getShortName() + ext;
|
||||
final String fileName = ourOutputPath + File.separator + myToolWrapper.getShortName() + ext;
|
||||
final PathMacroManager pathMacroManager = PathMacroManager.getInstance(getContext().getProject());
|
||||
PrintWriter printWriter = null;
|
||||
try {
|
||||
@@ -105,7 +251,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
final CharArrayWriter writer = new CharArrayWriter();
|
||||
if (!file.exists()) {
|
||||
writer.append("<").append(InspectionsBundle.message("inspection.problems")).append(" " + GlobalInspectionContextImpl.LOCAL_TOOL_ATTRIBUTE + "=\"")
|
||||
.append(Boolean.toString(this instanceof LocalInspectionToolWrapper)).append("\">\n");
|
||||
.append(Boolean.toString(myToolWrapper instanceof LocalInspectionToolWrapper)).append("\">\n");
|
||||
}
|
||||
for (Object o : list) {
|
||||
final Element element = (Element)o;
|
||||
@@ -126,12 +272,13 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<CommonProblemDescriptor> getProblemDescriptors() {
|
||||
return getProblemToElements().keySet();
|
||||
}
|
||||
|
||||
private void collectQuickFixes(final QuickFix[] fixes, final RefEntity refEntity) {
|
||||
private void collectQuickFixes(final QuickFix[] fixes, @NotNull RefEntity refEntity) {
|
||||
if (fixes != null && fixes.length != 0) {
|
||||
Set<QuickFix> localQuickFixes = getQuickFixActions().get(refEntity);
|
||||
if (localQuickFixes == null) {
|
||||
@@ -159,6 +306,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
getIgnoredElements().remove(refEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreProblem(RefEntity refEntity, CommonProblemDescriptor problem, int idx) {
|
||||
if (refEntity == null) return;
|
||||
final Set<QuickFix> localQuickFixes = getQuickFixActions().get(refEntity);
|
||||
@@ -191,6 +339,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
getIgnoredElements().put(refEntity, problemDescriptors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreCurrentElementProblem(RefEntity refEntity, CommonProblemDescriptor descriptor) {
|
||||
CommonProblemDescriptor[] descriptors = getIgnoredElements().get(refEntity);
|
||||
if (descriptors == null) {
|
||||
@@ -214,9 +363,15 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull GlobalInspectionContextImpl context) {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
super.cleanup();
|
||||
myContext = null;
|
||||
|
||||
myOldProblemElements = null;
|
||||
|
||||
synchronized (lock) {
|
||||
@@ -233,8 +388,8 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
|
||||
@Override
|
||||
public void finalCleanup() {
|
||||
super.finalCleanup();
|
||||
myOldProblemElements = null;
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -278,15 +433,15 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
int line = description instanceof ProblemDescriptor ? ((ProblemDescriptor)description).getLineNumber() : -1;
|
||||
final PsiElement psiElement = description instanceof ProblemDescriptor ? ((ProblemDescriptor)description).getPsiElement() : null;
|
||||
@NonNls String problemText = StringUtil.replace(StringUtil.replace(template, "#ref", psiElement != null ? ProblemDescriptorUtil
|
||||
.extractHighlightedText(description, psiElement): "") , " #loc ", " ");
|
||||
.extractHighlightedText(description, psiElement) : ""), " #loc ", " ");
|
||||
|
||||
Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
|
||||
if (element == null) return;
|
||||
@NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
|
||||
problemClassElement.addContent(getDisplayName());
|
||||
problemClassElement.addContent(myToolWrapper.getDisplayName());
|
||||
if (refEntity instanceof RefElement){
|
||||
final RefElement refElement = (RefElement)refEntity;
|
||||
final HighlightSeverity severity = getCurrentSeverity(refElement);
|
||||
final HighlightSeverity severity = getSeverity(refElement, getContext(), getToolWrapper());
|
||||
ProblemHighlightType problemHighlightType = description instanceof ProblemDescriptor
|
||||
? ((ProblemDescriptor)description).getHighlightType()
|
||||
: ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
|
||||
@@ -295,8 +450,8 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
problemClassElement.setAttribute("attribute_key", attributeKey);
|
||||
}
|
||||
element.addContent(problemClassElement);
|
||||
if (this instanceof GlobalInspectionToolWrapper) {
|
||||
final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper)this).getTool();
|
||||
if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
|
||||
final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper)myToolWrapper).getTool();
|
||||
final QuickFix[] fixes = description.getFixes();
|
||||
if (fixes != null) {
|
||||
@NonNls Element hintsElement = new Element("hints");
|
||||
@@ -318,7 +473,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
}
|
||||
catch (IllegalDataException e) {
|
||||
//noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
|
||||
System.out.println("Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + getShortName());
|
||||
System.out.println("Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + myToolWrapper.getShortName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,7 +509,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
|
||||
@Override
|
||||
public void updateContent() {
|
||||
myContents = new HashMap<String, Set<RefEntity>>();
|
||||
myContents = new com.intellij.util.containers.HashMap<String, Set<RefEntity>>();
|
||||
myModulesProblems = new HashSet<RefModule>();
|
||||
final Set<RefEntity> elements = getProblemElements().keySet();
|
||||
for (RefEntity element : elements) {
|
||||
@@ -382,14 +537,15 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
@Override
|
||||
public Map<String, Set<RefEntity>> getOldContent() {
|
||||
if (myOldProblemElements == null) return null;
|
||||
final HashMap<String, Set<RefEntity>> oldContents = new HashMap<String, Set<RefEntity>>();
|
||||
final com.intellij.util.containers.HashMap<String, Set<RefEntity>>
|
||||
oldContents = new com.intellij.util.containers.HashMap<String, Set<RefEntity>>();
|
||||
final Set<RefEntity> elements = myOldProblemElements.keySet();
|
||||
for (RefEntity element : elements) {
|
||||
String groupName = element instanceof RefElement ? element.getRefManager().getGroupName((RefElement)element) : element.getName();
|
||||
final Set<RefEntity> collection = myContents.get(groupName);
|
||||
if (collection != null) {
|
||||
final Set<RefEntity> currentElements = new HashSet<RefEntity>(collection);
|
||||
if (contains(element, currentElements)) continue;
|
||||
if (RefUtil.contains(element, currentElements)) continue;
|
||||
}
|
||||
Set<RefEntity> oldContent = oldContents.get(groupName);
|
||||
if (oldContent == null) {
|
||||
@@ -412,9 +568,10 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
return extractActiveFixes(refElements, getQuickFixActions());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public QuickFixAction[] extractActiveFixes(@NotNull RefEntity[] refElements, @NotNull Map<RefEntity, Set<QuickFix>> actions) {
|
||||
Map<Class, QuickFixAction> result = new HashMap<Class, QuickFixAction>();
|
||||
Map<Class, QuickFixAction> result = new com.intellij.util.containers.HashMap<Class, QuickFixAction>();
|
||||
for (RefEntity refElement : refElements) {
|
||||
final Set<QuickFix> localQuickFixes = actions.get(refElement);
|
||||
if (localQuickFixes == null) continue;
|
||||
@@ -422,7 +579,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
if (fix == null) continue;
|
||||
final Class klass = fix instanceof ActionClassHolder ? ((ActionClassHolder ) fix).getActionClass() : fix.getClass();
|
||||
final QuickFixAction quickFixAction = result.get(klass);
|
||||
if (quickFixAction != null){
|
||||
if (quickFixAction != null) {
|
||||
try {
|
||||
String familyName = fix.getFamilyName();
|
||||
familyName = !familyName.isEmpty() ? "\'" + familyName + "\'" : familyName;
|
||||
@@ -432,8 +589,9 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
//for plugin compatibility
|
||||
((LocalQuickFixWrapper)quickFixAction).setText(InspectionsBundle.message("inspection.descriptor.provider.apply.fix", ""));
|
||||
}
|
||||
} else {
|
||||
LocalQuickFixWrapper quickFixWrapper = new LocalQuickFixWrapper(fix, this);
|
||||
}
|
||||
else {
|
||||
LocalQuickFixWrapper quickFixWrapper = new LocalQuickFixWrapper(fix, myToolWrapper);
|
||||
result.put(klass, quickFixWrapper);
|
||||
}
|
||||
}
|
||||
@@ -446,6 +604,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
return getProblemToElements().get(descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreProblem(@NotNull CommonProblemDescriptor descriptor, @NotNull QuickFix fix) {
|
||||
RefEntity refElement = getProblemToElements().get(descriptor);
|
||||
if (refElement != null) {
|
||||
@@ -462,7 +621,6 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
|
||||
@Override
|
||||
public boolean isElementIgnored(final RefEntity element) {
|
||||
if (getIgnoredElements() == null) return false;
|
||||
for (RefEntity entity : getIgnoredElements().keySet()) {
|
||||
if (Comparing.equal(entity, element)) {
|
||||
return true;
|
||||
@@ -471,8 +629,8 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProblemResolved(RefEntity refEntity, CommonProblemDescriptor descriptor) {
|
||||
if (getIgnoredElements() == null) return false;
|
||||
if (descriptor == null) return true;
|
||||
for (RefEntity entity : getIgnoredElements().keySet()) {
|
||||
if (Comparing.equal(entity, refEntity)) {
|
||||
@@ -483,6 +641,8 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public FileStatus getProblemStatus(final CommonProblemDescriptor descriptor) {
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context != null && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN){
|
||||
@@ -493,15 +653,15 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
ContainerUtil.addAll(allAvailable, descriptors);
|
||||
}
|
||||
}
|
||||
final boolean old = contains(descriptor, allAvailable);
|
||||
final boolean current = contains(descriptor, getProblemToElements().keySet());
|
||||
final boolean old = containsDescriptor(descriptor, allAvailable);
|
||||
final boolean current = containsDescriptor(descriptor, getProblemToElements().keySet());
|
||||
return calcStatus(old, current);
|
||||
}
|
||||
}
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
private static boolean contains(CommonProblemDescriptor descriptor, Collection<CommonProblemDescriptor> descriptors){
|
||||
private static boolean containsDescriptor(CommonProblemDescriptor descriptor, Collection<CommonProblemDescriptor> descriptors){
|
||||
PsiElement element = null;
|
||||
if (descriptor instanceof ProblemDescriptor){
|
||||
element = ((ProblemDescriptor)descriptor).getPsiElement();
|
||||
@@ -526,8 +686,8 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
final GlobalInspectionContextImpl context = getContext();
|
||||
if (context != null && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN){
|
||||
if (myOldProblemElements != null){
|
||||
final boolean old = contains(element, myOldProblemElements.keySet());
|
||||
final boolean current = contains(element, getProblemElements().keySet());
|
||||
final boolean old = RefUtil.contains(element, myOldProblemElements.keySet());
|
||||
final boolean current = RefUtil.contains(element, getProblemElements().keySet());
|
||||
return calcStatus(old, current);
|
||||
}
|
||||
}
|
||||
@@ -540,6 +700,8 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
return getIgnoredElements().keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<RefEntity, CommonProblemDescriptor[]> getProblemElements() {
|
||||
synchronized (lock) {
|
||||
if (myProblemElements == null) {
|
||||
@@ -549,6 +711,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Map<RefEntity, CommonProblemDescriptor[]> getOldProblemElements() {
|
||||
return myOldProblemElements;
|
||||
@@ -564,21 +727,84 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<RefEntity, Set<QuickFix>> getQuickFixActions() {
|
||||
synchronized (lock) {
|
||||
if (myQuickFixActions == null) {
|
||||
myQuickFixActions = Collections.synchronizedMap(new HashMap<RefEntity, Set<QuickFix>>());
|
||||
myQuickFixActions = Collections.synchronizedMap(new com.intellij.util.containers.HashMap<RefEntity, Set<QuickFix>>());
|
||||
}
|
||||
return myQuickFixActions;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<RefEntity, CommonProblemDescriptor[]> getIgnoredElements() {
|
||||
synchronized (lock) {
|
||||
if (myIgnoredElements == null) {
|
||||
myIgnoredElements = Collections.synchronizedMap(new HashMap<RefEntity, CommonProblemDescriptor[]>());
|
||||
myIgnoredElements = Collections.synchronizedMap(new com.intellij.util.containers.HashMap<RefEntity, CommonProblemDescriptor[]>());
|
||||
}
|
||||
return myIgnoredElements;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InspectionNode createToolNode(@NotNull GlobalInspectionContextImpl globalInspectionContext, @NotNull InspectionNode node,
|
||||
@NotNull InspectionRVContentProvider provider,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
boolean showStructure) {
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IntentionAction findQuickFixes(@NotNull final CommonProblemDescriptor problemDescriptor, final String hint) {
|
||||
InspectionProfileEntry tool = getToolWrapper().getTool();
|
||||
if (!(tool instanceof GlobalInspectionTool)) return null;
|
||||
final QuickFix fix = ((GlobalInspectionTool)tool).getQuickFix(hint);
|
||||
if (fix == 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 static void setOutputPath(final String output) {
|
||||
ourOutputPath = output;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ui.LayeredIcon;
|
||||
import com.intellij.util.IconUtil;
|
||||
@@ -32,17 +32,18 @@ public class InspectionNode extends InspectionTreeNode {
|
||||
public static final Icon TOOL = LayeredIcon.create(AllIcons.Toolwindows.ToolWindowInspection, IconUtil.getEmptyIcon(false));
|
||||
private boolean myTooBigForOnlineRefresh = false;
|
||||
|
||||
public InspectionNode(@NotNull InspectionTool tool) {
|
||||
super(tool);
|
||||
public InspectionNode(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(toolWrapper);
|
||||
assert toolWrapper.getContext() != null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getTool().getDisplayName();
|
||||
return getToolWrapper().getDisplayName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionTool getTool() {
|
||||
return (InspectionTool)getUserObject();
|
||||
public InspectionToolWrapper getToolWrapper() {
|
||||
return (InspectionToolWrapper)getUserObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -104,18 +104,20 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
});
|
||||
|
||||
private final Splitter mySplitter;
|
||||
@NotNull
|
||||
private final GlobalInspectionContextImpl myGlobalInspectionContext;
|
||||
private boolean myRerun = false;
|
||||
|
||||
@NotNull
|
||||
private final InspectionRVContentProvider myProvider;
|
||||
private AnAction myIncludeAction;
|
||||
private AnAction myExcludeAction;
|
||||
|
||||
public InspectionResultsView(final Project project,
|
||||
public InspectionResultsView(@NotNull final Project project,
|
||||
final InspectionProfile inspectionProfile,
|
||||
final AnalysisScope scope,
|
||||
final GlobalInspectionContextImpl globalInspectionContext,
|
||||
final InspectionRVContentProvider provider) {
|
||||
@NotNull AnalysisScope scope,
|
||||
@NotNull GlobalInspectionContextImpl globalInspectionContext,
|
||||
@NotNull InspectionRVContentProvider provider) {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
myProject = project;
|
||||
@@ -423,7 +425,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
showInBrowser(problemNode.getElement(), problemNode.getDescriptor());
|
||||
}
|
||||
else if (node instanceof InspectionNode) {
|
||||
showInBrowser(((InspectionNode)node).getTool());
|
||||
showInBrowser(((InspectionNode)node).getToolWrapper());
|
||||
}
|
||||
else {
|
||||
myBrowser.showEmpty();
|
||||
@@ -439,10 +441,10 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
setCursor(currentCursor);
|
||||
}
|
||||
|
||||
private void showInBrowser(InspectionTool tool) {
|
||||
private void showInBrowser(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
Cursor currentCursor = getCursor();
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
myBrowser.showDescription(tool);
|
||||
myBrowser.showDescription(toolWrapper);
|
||||
setCursor(currentCursor);
|
||||
}
|
||||
|
||||
@@ -453,15 +455,24 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
setCursor(currentCursor);
|
||||
}
|
||||
|
||||
public void addTool(InspectionTool tool, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) {
|
||||
final InspectionTreeNode parentNode = getToolParentNode(
|
||||
!tool.getGroupDisplayName().isEmpty() ? tool.getGroupDisplayName() : InspectionProfileEntry.GENERAL_GROUP_NAME, errorLevel, groupedBySeverity);
|
||||
tool.createToolNode(myProvider, parentNode, myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE);
|
||||
registerActionShortcuts(tool);
|
||||
@NotNull
|
||||
public InspectionNode addTool(@NotNull final InspectionToolWrapper toolWrapper, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) {
|
||||
String groupName =
|
||||
toolWrapper.getGroupDisplayName().isEmpty() ? InspectionProfileEntry.GENERAL_GROUP_NAME : toolWrapper.getGroupDisplayName();
|
||||
InspectionTreeNode parentNode = getToolParentNode(groupName, errorLevel, groupedBySeverity);
|
||||
InspectionNode toolNode = new InspectionNode(toolWrapper);
|
||||
boolean showStructure = myGlobalInspectionContext.getUIOptions().SHOW_STRUCTURE;
|
||||
myProvider.appendToolNodeContent(myGlobalInspectionContext, toolNode, parentNode, showStructure);
|
||||
InspectionToolPresentation presentation = myGlobalInspectionContext.getPresentation(toolWrapper);
|
||||
toolNode = presentation.createToolNode(myGlobalInspectionContext, toolNode, myProvider, parentNode, showStructure);
|
||||
((DefaultInspectionToolPresentation)presentation).myToolNode = toolNode;
|
||||
|
||||
registerActionShortcuts(presentation);
|
||||
return toolNode;
|
||||
}
|
||||
|
||||
private void registerActionShortcuts(InspectionTool tool) {
|
||||
final QuickFixAction[] fixes = tool.getQuickFixes(new RefEntity[0]);
|
||||
private void registerActionShortcuts(@NotNull InspectionToolPresentation presentation) {
|
||||
final QuickFixAction[] fixes = presentation.getQuickFixes(RefEntity.EMPTY_ELEMENTS_ARRAY);
|
||||
if (fixes != null) {
|
||||
for (QuickFixAction fix : fixes) {
|
||||
fix.registerCustomShortcutSet(fix.getShortcutSet(), this);
|
||||
@@ -476,7 +487,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
|
||||
@Nullable
|
||||
public String getCurrentProfileName() {
|
||||
return myInspectionProfile != null ? myInspectionProfile.getDisplayName() : null;
|
||||
return myInspectionProfile == null ? null : myInspectionProfile.getDisplayName();
|
||||
}
|
||||
|
||||
public InspectionProfile getCurrentProfile() {
|
||||
@@ -499,18 +510,18 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
|
||||
private boolean buildTree() {
|
||||
final InspectionProfile profile = myInspectionProfile;
|
||||
final boolean isGroupedBySeverity = myGlobalInspectionContext.getUIOptions().GROUP_BY_SEVERITY;
|
||||
InspectionProfile profile = myInspectionProfile;
|
||||
boolean isGroupedBySeverity = myGlobalInspectionContext.getUIOptions().GROUP_BY_SEVERITY;
|
||||
myGroups = new HashMap<HighlightDisplayLevel, Map<String, InspectionGroupNode>>();
|
||||
final Map<String, Tools> tools = myGlobalInspectionContext.getTools();
|
||||
boolean resultsFound = false;
|
||||
for (Tools currentTools : tools.values()) {
|
||||
final InspectionTool defaultTool = (InspectionTool)currentTools.getDefaultState().getTool();
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(defaultTool.getShortName());
|
||||
InspectionToolWrapper defaultToolWrapper = currentTools.getDefaultState().getTool();
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(defaultToolWrapper.getShortName());
|
||||
for (ScopeToolState state : currentTools.getTools()) {
|
||||
final InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
if (myProvider.checkReportedProblems(toolWrapper)) {
|
||||
addTool(toolWrapper, ((InspectionProfileImpl)profile).getErrorLevel(key, state.getScope(myProject)), isGroupedBySeverity);
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
if (myProvider.checkReportedProblems(myGlobalInspectionContext, toolWrapper)) {
|
||||
addTool(toolWrapper, ((InspectionProfileImpl)profile).getErrorLevel(key, state.getScope(myProject), myProject), isGroupedBySeverity);
|
||||
resultsFound = true;
|
||||
}
|
||||
}
|
||||
@@ -518,8 +529,9 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
return resultsFound;
|
||||
}
|
||||
|
||||
public InspectionTreeNode getToolParentNode(String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) {
|
||||
if (groupName == null || groupName.isEmpty()) {
|
||||
@NotNull
|
||||
public InspectionTreeNode getToolParentNode(@NotNull String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) {
|
||||
if (groupName.isEmpty()) {
|
||||
return getRelativeRootNode(groupedBySeverity, errorLevel);
|
||||
}
|
||||
if (myGroups == null) {
|
||||
@@ -532,8 +544,8 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
Map<String, InspectionGroupNode> searchMap = new HashMap<String, InspectionGroupNode>(map);
|
||||
if (!groupedBySeverity) {
|
||||
for (HighlightDisplayLevel level : myGroups.keySet()) {
|
||||
searchMap.putAll(myGroups.get(level));
|
||||
for (Map<String, InspectionGroupNode> groupMap : myGroups.values()) {
|
||||
searchMap.putAll(groupMap);
|
||||
}
|
||||
}
|
||||
InspectionGroupNode group = searchMap.get(groupName);
|
||||
@@ -545,21 +557,18 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
return group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private InspectionTreeNode getRelativeRootNode(boolean isGroupedBySeverity, HighlightDisplayLevel level) {
|
||||
if (isGroupedBySeverity) {
|
||||
if (mySeverityGroupNodes.containsKey(level)) {
|
||||
return mySeverityGroupNodes.get(level);
|
||||
}
|
||||
else {
|
||||
final InspectionSeverityGroupNode severityGroupNode = new InspectionSeverityGroupNode(myProject, level);
|
||||
mySeverityGroupNodes.put(level, severityGroupNode);
|
||||
myTree.getRoot().add(severityGroupNode);
|
||||
return severityGroupNode;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return myTree.getRoot();
|
||||
final InspectionSeverityGroupNode severityGroupNode = new InspectionSeverityGroupNode(myProject, level);
|
||||
mySeverityGroupNodes.put(level, severityGroupNode);
|
||||
myTree.getRoot().add(severityGroupNode);
|
||||
return severityGroupNode;
|
||||
}
|
||||
return myTree.getRoot();
|
||||
}
|
||||
|
||||
|
||||
@@ -597,6 +606,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
return myOccurenceNavigator != null ? myOccurenceNavigator.getPreviousOccurenceActionName() : "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
@@ -604,7 +614,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
if (PlatformDataKeys.HELP_ID.is(dataId)) return HELP_ID;
|
||||
if (InspectionResultsView.DATA_KEY.is(dataId)) return this;
|
||||
if (DATA_KEY.is(dataId)) return this;
|
||||
if (myTree == null) return null;
|
||||
TreePath[] paths = myTree.getSelectionPaths();
|
||||
|
||||
@@ -614,9 +624,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
|
||||
return collectPsiElements();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
TreePath path = paths[0];
|
||||
@@ -629,7 +637,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
if (refElement == null) return null;
|
||||
final RefEntity item = refElement.getRefManager().getRefinedElement(refElement);
|
||||
|
||||
if (item == null || !item.isValid()) return null;
|
||||
if (!item.isValid()) return null;
|
||||
|
||||
PsiElement psiElement = item instanceof RefElement ? ((RefElement)item).getElement() : null;
|
||||
if (psiElement == null) return null;
|
||||
@@ -721,15 +729,15 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
|
||||
actions.addSeparator();
|
||||
|
||||
final InspectionTool tool = myTree.getSelectedTool();
|
||||
if (tool != null) {
|
||||
final QuickFixAction[] quickFixes = myProvider.getQuickFixes(tool, myTree);
|
||||
final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper();
|
||||
if (toolWrapper != null) {
|
||||
final QuickFixAction[] quickFixes = myProvider.getQuickFixes(toolWrapper, myTree);
|
||||
if (quickFixes != null) {
|
||||
for (QuickFixAction quickFixe : quickFixes) {
|
||||
actions.add(quickFixe);
|
||||
}
|
||||
}
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
|
||||
if (key == null) return; //e.g. DummyEntryPointsTool
|
||||
|
||||
//options
|
||||
@@ -748,20 +756,23 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
menu.getComponent().show(component, x, y);
|
||||
}
|
||||
|
||||
@NotNull public InspectionTree getTree(){
|
||||
@NotNull
|
||||
public InspectionTree getTree(){
|
||||
return myTree;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GlobalInspectionContextImpl getGlobalInspectionContext() {
|
||||
return myGlobalInspectionContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionRVContentProvider getProvider() {
|
||||
return myProvider;
|
||||
}
|
||||
|
||||
public boolean isSingleToolInSelection() {
|
||||
return myTree != null && myTree.getSelectedTool() != null;
|
||||
return myTree != null && myTree.getSelectedToolWrapper() != null;
|
||||
}
|
||||
|
||||
public boolean isRerun() {
|
||||
@@ -782,12 +793,10 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!profiles.isEmpty()) {
|
||||
return profiles.iterator().next();
|
||||
}
|
||||
else {
|
||||
if (profiles.isEmpty()) {
|
||||
return (InspectionProfile)profileManager.getProjectProfileImpl();
|
||||
}
|
||||
return profiles.iterator().next();
|
||||
}
|
||||
|
||||
public boolean isProfileDefined() {
|
||||
@@ -827,15 +836,15 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(myProject);
|
||||
final InspectionTool tool = myTree.getSelectedTool();
|
||||
final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper();
|
||||
InspectionProfile inspectionProfile = myInspectionProfile;
|
||||
final boolean profileIsDefined = isProfileDefined();
|
||||
if (!profileIsDefined) {
|
||||
inspectionProfile = guessProfileToSelect(profileManager);
|
||||
}
|
||||
|
||||
if (tool != null) {
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName()); //do not search for dead code entry point tool
|
||||
if (toolWrapper != null) {
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName()); //do not search for dead code entry point tool
|
||||
if (key != null){
|
||||
if (new EditInspectionToolsSettingsAction(key).editToolSettings(myProject, (InspectionProfileImpl)inspectionProfile, profileIsDefined)
|
||||
&& profileIsDefined){
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.CommonProblemDescriptor;
|
||||
import com.intellij.codeInspection.ProblemDescriptionsProcessor;
|
||||
import com.intellij.codeInspection.QuickFix;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.HTMLComposerImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionRVContentProvider;
|
||||
import com.intellij.codeInspection.ex.QuickFixAction;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface InspectionToolPresentation extends ProblemDescriptionsProcessor {
|
||||
@NotNull
|
||||
InspectionNode createToolNode(@NotNull GlobalInspectionContextImpl globalInspectionContext,
|
||||
@NotNull InspectionNode node,
|
||||
@NotNull InspectionRVContentProvider provider,
|
||||
@NotNull InspectionTreeNode parentNode,
|
||||
final boolean showStructure);
|
||||
void updateContent();
|
||||
|
||||
boolean hasReportedProblems();
|
||||
|
||||
Map<String, Set<RefEntity>> getContent();
|
||||
|
||||
Map<String, Set<RefEntity>> getOldContent();
|
||||
void ignoreCurrentElement(RefEntity refEntity);
|
||||
void amnesty(RefEntity refEntity);
|
||||
void cleanup();
|
||||
void finalCleanup();
|
||||
void initialize(@NotNull GlobalInspectionContextImpl context);
|
||||
boolean isGraphNeeded();
|
||||
boolean isElementIgnored(final RefEntity element);
|
||||
@NotNull
|
||||
FileStatus getElementStatus(final RefEntity element);
|
||||
@NotNull
|
||||
Collection<RefEntity> getIgnoredRefElements();
|
||||
@Nullable
|
||||
IntentionAction findQuickFixes(@NotNull CommonProblemDescriptor descriptor, final String hint);
|
||||
@NotNull
|
||||
HTMLComposerImpl getComposer();
|
||||
void exportResults(@NotNull final Element parentNode, @NotNull RefEntity refEntity);
|
||||
Set<RefModule> getModuleProblems();
|
||||
@Nullable
|
||||
QuickFixAction[] getQuickFixes(@NotNull final RefEntity[] refElements);
|
||||
@NotNull
|
||||
Map<RefEntity, CommonProblemDescriptor[]> getProblemElements();
|
||||
@NotNull
|
||||
Collection<CommonProblemDescriptor> getProblemDescriptors();
|
||||
@NotNull
|
||||
FileStatus getProblemStatus(final CommonProblemDescriptor descriptor);
|
||||
boolean isOldProblemsIncluded();
|
||||
@Nullable
|
||||
Map<RefEntity, CommonProblemDescriptor[]> getOldProblemElements();
|
||||
boolean isProblemResolved(RefEntity refEntity, CommonProblemDescriptor descriptor);
|
||||
void ignoreCurrentElementProblem(RefEntity refEntity, CommonProblemDescriptor descriptor);
|
||||
void addProblemElement(RefEntity refElement, boolean filterSuppressed, @NotNull CommonProblemDescriptor... descriptions);
|
||||
void ignoreProblem(@NotNull CommonProblemDescriptor descriptor, @NotNull QuickFix fix);
|
||||
@NotNull
|
||||
GlobalInspectionContextImpl getContext();
|
||||
void ignoreProblem(RefEntity refEntity, CommonProblemDescriptor problem, int idx);
|
||||
@Nullable
|
||||
QuickFixAction[] extractActiveFixes(@NotNull RefEntity[] refElements, @NotNull Map<RefEntity, Set<QuickFix>> actions);
|
||||
void exportResults(@NotNull final Element parentNode);
|
||||
}
|
||||
@@ -25,9 +25,7 @@ package com.intellij.codeInspection.ui;
|
||||
import com.intellij.codeInspection.CommonProblemDescriptor;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ex.CommonInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.DescriptorProviderInspection;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.*;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -101,19 +99,20 @@ public class InspectionTree extends Tree {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public InspectionTool getSelectedTool() {
|
||||
public InspectionToolWrapper getSelectedToolWrapper() {
|
||||
final TreePath[] paths = getSelectionPaths();
|
||||
if (paths == null) return null;
|
||||
InspectionTool tool = null;
|
||||
InspectionToolWrapper toolWrapper = null;
|
||||
for (TreePath path : paths) {
|
||||
Object[] nodes = path.getPath();
|
||||
for (int j = nodes.length - 1; j >= 0; j--) {
|
||||
Object node = nodes[j];
|
||||
if (node instanceof InspectionNode) {
|
||||
if (tool == null) {
|
||||
tool = ((InspectionNode)node).getTool();
|
||||
InspectionToolWrapper wrapper = ((InspectionNode)node).getToolWrapper();
|
||||
if (toolWrapper == null) {
|
||||
toolWrapper = wrapper;
|
||||
}
|
||||
else if (tool != ((InspectionNode)node).getTool()) {
|
||||
else if (toolWrapper != wrapper) {
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
@@ -121,15 +120,15 @@ public class InspectionTree extends Tree {
|
||||
}
|
||||
}
|
||||
|
||||
return tool;
|
||||
return toolWrapper;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public RefEntity[] getSelectedElements() {
|
||||
TreePath[] selectionPaths = getSelectionPaths();
|
||||
if (selectionPaths != null) {
|
||||
final InspectionTool selectedTool = getSelectedTool();
|
||||
if (selectedTool == null) return RefEntity.EMPTY_ELEMENTS_ARRAY;
|
||||
InspectionToolWrapper toolWrapper = getSelectedToolWrapper();
|
||||
if (toolWrapper == null) return RefEntity.EMPTY_ELEMENTS_ARRAY;
|
||||
|
||||
List<RefEntity> result = new ArrayList<RefEntity>();
|
||||
for (TreePath selectionPath : selectionPaths) {
|
||||
@@ -163,8 +162,8 @@ public class InspectionTree extends Tree {
|
||||
}
|
||||
|
||||
public CommonProblemDescriptor[] getSelectedDescriptors() {
|
||||
final InspectionTool tool = getSelectedTool();
|
||||
if (getSelectionCount() == 0 || !(tool instanceof DescriptorProviderInspection && !(tool instanceof CommonInspectionToolWrapper))) return EMPTY_DESCRIPTORS;
|
||||
final InspectionToolWrapper toolWrapper = getSelectedToolWrapper();
|
||||
if (getSelectionCount() == 0 || !(toolWrapper instanceof LocalInspectionToolWrapper)) return EMPTY_DESCRIPTORS;
|
||||
final TreePath[] paths = getSelectionPaths();
|
||||
final LinkedHashSet<CommonProblemDescriptor> descriptors = new LinkedHashSet<CommonProblemDescriptor>();
|
||||
for (TreePath path : paths) {
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.DescriptorProviderInspection;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -33,21 +35,22 @@ import javax.swing.*;
|
||||
public class ProblemDescriptionNode extends InspectionTreeNode {
|
||||
protected RefEntity myElement;
|
||||
private final CommonProblemDescriptor myDescriptor;
|
||||
protected final DescriptorProviderInspection myTool;
|
||||
protected final InspectionToolWrapper myToolWrapper;
|
||||
|
||||
public ProblemDescriptionNode(final Object userObject, final DescriptorProviderInspection tool) {
|
||||
public ProblemDescriptionNode(final Object userObject, @NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(userObject);
|
||||
myTool = tool;
|
||||
myToolWrapper = toolWrapper;
|
||||
myDescriptor = null;
|
||||
myElement = null;
|
||||
}
|
||||
|
||||
public ProblemDescriptionNode(RefEntity element,
|
||||
CommonProblemDescriptor descriptor,
|
||||
DescriptorProviderInspection descriptorProviderInspection) {
|
||||
@NotNull InspectionToolWrapper toolWrapper) {
|
||||
super(descriptor);
|
||||
myElement = element;
|
||||
myDescriptor = descriptor;
|
||||
myTool = descriptorProviderInspection;
|
||||
myToolWrapper = toolWrapper;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -89,23 +92,30 @@ public class ProblemDescriptionNode extends InspectionTreeNode {
|
||||
|
||||
@Override
|
||||
public boolean isResolved() {
|
||||
return myElement instanceof RefElement && myTool.isProblemResolved(myElement, getDescriptor());
|
||||
return myElement instanceof RefElement && getPresentation().isProblemResolved(myElement, getDescriptor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignoreElement() {
|
||||
myTool.ignoreCurrentElementProblem(getElement(), getDescriptor());
|
||||
InspectionToolPresentation presentation = getPresentation();
|
||||
presentation.ignoreCurrentElementProblem(getElement(), getDescriptor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amnesty() {
|
||||
myTool.amnesty(getElement());
|
||||
InspectionToolPresentation presentation = getPresentation();
|
||||
presentation.amnesty(getElement());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private InspectionToolPresentation getPresentation() {
|
||||
return ((GlobalInspectionContextImpl)myToolWrapper.getContext()).getPresentation(myToolWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStatus getNodeStatus() {
|
||||
if (myElement instanceof RefElement){
|
||||
return myTool.getProblemStatus(myDescriptor);
|
||||
return getPresentation().getProblemStatus(myDescriptor);
|
||||
}
|
||||
return FileStatus.NOT_CHANGED;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.CommonProblemDescriptor;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
@@ -36,7 +35,7 @@ import javax.swing.tree.MutableTreeNode;
|
||||
public class RefElementNode extends InspectionTreeNode {
|
||||
private boolean myHasDescriptorsUnder = false;
|
||||
private CommonProblemDescriptor mySingleDescriptor = null;
|
||||
protected final InspectionTool myTool;
|
||||
protected final InspectionToolPresentation myToolPresentation;
|
||||
private final ComputableIcon myIcon = new ComputableIcon(new Computable<Icon>() {
|
||||
@Override
|
||||
public Icon compute() {
|
||||
@@ -48,13 +47,13 @@ public class RefElementNode extends InspectionTreeNode {
|
||||
}
|
||||
});
|
||||
|
||||
public RefElementNode(@NotNull Object userObject, @NotNull InspectionTool tool) {
|
||||
public RefElementNode(@NotNull Object userObject, @NotNull InspectionToolPresentation presentation) {
|
||||
super(userObject);
|
||||
myTool = tool;
|
||||
myToolPresentation = presentation;
|
||||
}
|
||||
|
||||
public RefElementNode(@NotNull RefElement element, @NotNull InspectionTool tool) {
|
||||
this((Object)element, tool);
|
||||
public RefElementNode(@NotNull RefElement element, @NotNull InspectionToolPresentation presentation) {
|
||||
this((Object)element, presentation);
|
||||
}
|
||||
|
||||
public boolean hasDescriptorsUnder() {
|
||||
@@ -93,25 +92,25 @@ public class RefElementNode extends InspectionTreeNode {
|
||||
|
||||
@Override
|
||||
public boolean isResolved() {
|
||||
return myTool.isElementIgnored(getElement());
|
||||
return myToolPresentation.isElementIgnored(getElement());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void ignoreElement() {
|
||||
myTool.ignoreCurrentElement(getElement());
|
||||
myToolPresentation.ignoreCurrentElement(getElement());
|
||||
super.ignoreElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amnesty() {
|
||||
myTool.amnesty(getElement());
|
||||
myToolPresentation.amnesty(getElement());
|
||||
super.amnesty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStatus getNodeStatus() {
|
||||
return myTool.getElementStatus(getElement());
|
||||
return myToolPresentation.getElementStatus(getElement());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+31
-23
@@ -28,6 +28,7 @@ import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.ui.InspectionNode;
|
||||
import com.intellij.codeInspection.ui.InspectionResultsView;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
import com.intellij.codeInspection.util.RefEntityAlphabeticalComparator;
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -53,6 +54,7 @@ import com.intellij.util.ui.tree.TreeUtil;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
@@ -157,15 +159,17 @@ public class ExportHTMLAction extends AnAction implements DumbAware {
|
||||
if (node instanceof InspectionNode) {
|
||||
InspectionNode toolNode = (InspectionNode)node;
|
||||
Element problems = new Element(PROBLEMS);
|
||||
final InspectionTool tool = toolNode.getTool();
|
||||
final Set<InspectionTool> tools = getWorkedTools(toolNode);
|
||||
for (InspectionTool inspectionTool : tools) {
|
||||
inspectionTool.exportResults(problems);
|
||||
InspectionToolWrapper toolWrapper = toolNode.getToolWrapper();
|
||||
|
||||
final Set<InspectionToolWrapper> toolWrappers = getWorkedTools(toolNode);
|
||||
for (InspectionToolWrapper wrapper : toolWrappers) {
|
||||
InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(wrapper);
|
||||
presentation.exportResults(problems);
|
||||
}
|
||||
PathMacroManager.getInstance(myView.getProject()).collapsePaths(problems);
|
||||
try {
|
||||
JDOMUtil.writeDocument(new Document(problems),
|
||||
outputDirectoryName + File.separator + tool.getShortName() + InspectionApplication.XML_EXTENSION,
|
||||
outputDirectoryName + File.separator + toolWrapper.getShortName() + InspectionApplication.XML_EXTENSION,
|
||||
CodeStyleSettingsManager.getSettings(null).getLineSeparator());
|
||||
}
|
||||
catch (IOException e) {
|
||||
@@ -197,19 +201,20 @@ public class ExportHTMLAction extends AnAction implements DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<InspectionTool> getWorkedTools(InspectionNode node) {
|
||||
final Set<InspectionTool> result = new HashSet<InspectionTool>();
|
||||
final InspectionTool tool = node.getTool();
|
||||
@NotNull
|
||||
private Set<InspectionToolWrapper> getWorkedTools(@NotNull InspectionNode node) {
|
||||
final Set<InspectionToolWrapper> result = new HashSet<InspectionToolWrapper>();
|
||||
final InspectionToolWrapper wrapper = node.getToolWrapper();
|
||||
if (myView.getCurrentProfileName() != null){
|
||||
result.add(tool);
|
||||
result.add(wrapper);
|
||||
return result;
|
||||
}
|
||||
final String shortName = tool.getShortName();
|
||||
final String shortName = wrapper.getShortName();
|
||||
final GlobalInspectionContextImpl context = myView.getGlobalInspectionContext();
|
||||
final Tools tools = context.getTools().get(shortName);
|
||||
if (tools != null) { //dummy entry points tool
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
InspectionToolWrapper toolWrapper = (InspectionToolWrapper)state.getTool();
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
result.add(toolWrapper);
|
||||
}
|
||||
}
|
||||
@@ -217,29 +222,31 @@ public class ExportHTMLAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
private void exportHTML(HTMLExportFrameMaker frameMaker, InspectionNode node) {
|
||||
final Set<InspectionTool> tools = getWorkedTools(node);
|
||||
final InspectionTool tool = node.getTool();
|
||||
final Set<InspectionToolWrapper> toolWrappers = getWorkedTools(node);
|
||||
final InspectionToolWrapper toolWrapper = node.getToolWrapper();
|
||||
|
||||
final HTMLExporter exporter =
|
||||
new HTMLExporter(frameMaker.getRootFolder() + "/" + tool.getShortName(), tool.getComposer());
|
||||
frameMaker.startInspection(tool);
|
||||
new HTMLExporter(frameMaker.getRootFolder() + "/" + toolWrapper.getShortName(), myView.getGlobalInspectionContext().getPresentation(toolWrapper).getComposer());
|
||||
frameMaker.startInspection(toolWrapper);
|
||||
HTMLExportUtil.runExport(myView.getProject(), new ThrowableRunnable<IOException>() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
exportHTML(tools, exporter);
|
||||
exportHTML(toolWrappers, exporter);
|
||||
exporter.generateReferencedPages();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
private void exportHTML(Set<InspectionTool> tools, HTMLExporter exporter) throws IOException {
|
||||
private void exportHTML(@NotNull Set<InspectionToolWrapper> toolWrappers, HTMLExporter exporter) throws IOException {
|
||||
StringBuffer packageIndex = new StringBuffer();
|
||||
packageIndex.append("<html><body>");
|
||||
|
||||
final Map<String, Set<RefEntity>> content = new HashMap<String, Set<RefEntity>>();
|
||||
|
||||
for (InspectionTool tool : tools) {
|
||||
final Map<String, Set<RefEntity>> toolContent = tool.getContent();
|
||||
for (InspectionToolWrapper toolWrapper : toolWrappers) {
|
||||
InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(toolWrapper);
|
||||
final Map<String, Set<RefEntity>> toolContent = presentation.getContent();
|
||||
if (toolContent != null) {
|
||||
content.putAll(toolContent);
|
||||
}
|
||||
@@ -250,12 +257,12 @@ public class ExportHTMLAction extends AnAction implements DumbAware {
|
||||
content.put("default package" , defaultPackageEntities);
|
||||
}
|
||||
|
||||
ArrayList<String> packageNames = new ArrayList<String>(content.keySet());
|
||||
List<String> packageNames = new ArrayList<String>(content.keySet());
|
||||
|
||||
Collections.sort(packageNames);
|
||||
for (String packageName : packageNames) {
|
||||
appendPackageReference(packageIndex, packageName);
|
||||
final ArrayList<RefEntity> packageContent = new ArrayList<RefEntity>(content.get(packageName));
|
||||
List<RefEntity> packageContent = new ArrayList<RefEntity>(content.get(packageName));
|
||||
Collections.sort(packageContent, RefEntityAlphabeticalComparator.getInstance());
|
||||
StringBuffer contentIndex = new StringBuffer();
|
||||
contentIndex.append("<html><body>");
|
||||
@@ -275,8 +282,9 @@ public class ExportHTMLAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
final Set<RefModule> modules = new HashSet<RefModule>();
|
||||
for (InspectionTool tool : tools) {
|
||||
final Set<RefModule> problems = tool.getModuleProblems();
|
||||
for (InspectionToolWrapper toolWrapper : toolWrappers) {
|
||||
InspectionToolPresentation presentation = myView.getGlobalInspectionContext().getPresentation(toolWrapper);
|
||||
final Set<RefModule> problems = presentation.getModuleProblems();
|
||||
if (problems != null) {
|
||||
modules.addAll(problems);
|
||||
}
|
||||
|
||||
+18
-17
@@ -1,4 +1,3 @@
|
||||
|
||||
package com.intellij.codeInspection.ui.actions;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
@@ -9,7 +8,7 @@ import com.intellij.codeInspection.ModifiableModel;
|
||||
import com.intellij.codeInspection.actions.RunInspectionIntention;
|
||||
import com.intellij.codeInspection.ex.DisableInspectionToolAction;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionResultsView;
|
||||
@@ -25,6 +24,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.ListPopup;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -54,14 +54,14 @@ public class InspectionsOptionsToolbarAction extends AnAction {
|
||||
}
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final ListPopup popup = JBPopupFactory.getInstance()
|
||||
.createActionGroupPopup(getSelectedTool().getDisplayName(), options, dataContext,
|
||||
.createActionGroupPopup(getSelectedToolWrapper().getDisplayName(), options, dataContext,
|
||||
JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
|
||||
InspectionResultsView.showPopup(e, popup);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private InspectionTool getSelectedTool() {
|
||||
return myView.getTree().getSelectedTool();
|
||||
private InspectionToolWrapper getSelectedToolWrapper() {
|
||||
return myView.getTree().getSelectedToolWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,28 +70,29 @@ public class InspectionsOptionsToolbarAction extends AnAction {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
final InspectionTool selectedTool = getSelectedTool();
|
||||
assert selectedTool != null;
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(selectedTool.getShortName());
|
||||
InspectionToolWrapper toolWrapper = getSelectedToolWrapper();
|
||||
assert toolWrapper != null;
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
|
||||
if (key == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
}
|
||||
e.getPresentation().setEnabled(true);
|
||||
final String text = getToolOptions(selectedTool);
|
||||
final String text = getToolOptions(toolWrapper);
|
||||
e.getPresentation().setText(text);
|
||||
e.getPresentation().setDescription(text);
|
||||
}
|
||||
|
||||
private static String getToolOptions(@Nullable final InspectionTool selectedTool) {
|
||||
return InspectionsBundle.message("inspections.view.options.title", selectedTool != null ? selectedTool.getDisplayName() : "");
|
||||
@NotNull
|
||||
private static String getToolOptions(@Nullable final InspectionToolWrapper toolWrapper) {
|
||||
return InspectionsBundle.message("inspections.view.options.title", toolWrapper != null ? toolWrapper.getDisplayName() : "");
|
||||
}
|
||||
|
||||
public List<AnAction> createActions() {
|
||||
final List<AnAction> result = new ArrayList<AnAction>();
|
||||
final InspectionTree tree = myView.getTree();
|
||||
final InspectionTool tool = tree.getSelectedTool();
|
||||
if (tool == null) return result;
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
|
||||
final InspectionToolWrapper toolWrapper = tree.getSelectedToolWrapper();
|
||||
if (toolWrapper == null) return result;
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName());
|
||||
if (key == null) return result;
|
||||
|
||||
result.add(new DisableInspectionAction(key));
|
||||
@@ -101,7 +102,7 @@ public class InspectionsOptionsToolbarAction extends AnAction {
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
final PsiElement psiElement = getPsiElement(tree);
|
||||
assert psiElement != null;
|
||||
new RunInspectionIntention(tool).invoke(myView.getProject(), null, psiElement.getContainingFile());
|
||||
new RunInspectionIntention(toolWrapper).invoke(myView.getProject(), null, psiElement.getContainingFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +125,7 @@ public class InspectionsOptionsToolbarAction extends AnAction {
|
||||
}
|
||||
});
|
||||
|
||||
result.add(new SuppressActionWrapper(myView.getProject(), tool, tree.getSelectionPaths()));
|
||||
result.add(new SuppressActionWrapper(myView.getProject(), toolWrapper, tree.getSelectionPaths()));
|
||||
|
||||
|
||||
return result;
|
||||
@@ -143,7 +144,7 @@ public class InspectionsOptionsToolbarAction extends AnAction {
|
||||
try {
|
||||
if (myView.isProfileDefined()) {
|
||||
final ModifiableModel model = myView.getCurrentProfile().getModifiableModel();
|
||||
model.disableTool(myKey.toString());
|
||||
model.disableTool(myKey.toString(), myView.getProject());
|
||||
model.commit();
|
||||
myView.updateCurrentProfile();
|
||||
} else {
|
||||
|
||||
+6
-6
@@ -18,7 +18,7 @@ package com.intellij.codeInspection.ui.actions;
|
||||
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.InspectionRVContentProvider;
|
||||
import com.intellij.codeInspection.ex.InspectionTool;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.QuickFixAction;
|
||||
import com.intellij.codeInspection.ui.InspectionResultsView;
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -55,10 +55,10 @@ public class InvokeQuickFixAction extends AnAction {
|
||||
}
|
||||
|
||||
//noinspection ConstantConditions
|
||||
final @NotNull InspectionTool tool = myView.getTree().getSelectedTool();
|
||||
@NotNull InspectionToolWrapper toolWrapper = myView.getTree().getSelectedToolWrapper();
|
||||
final InspectionRVContentProvider provider = myView.getProvider();
|
||||
if (provider.isContentLoaded()) {
|
||||
final QuickFixAction[] quickFixes = provider.getQuickFixes(tool, myView.getTree());
|
||||
final QuickFixAction[] quickFixes = provider.getQuickFixes(toolWrapper, myView.getTree());
|
||||
if (quickFixes == null || quickFixes.length == 0) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
@@ -85,9 +85,9 @@ public class InvokeQuickFixAction extends AnAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final InspectionTool tool = myView.getTree().getSelectedTool();
|
||||
assert tool != null;
|
||||
final QuickFixAction[] quickFixes = myView.getProvider().getQuickFixes(tool, myView.getTree());
|
||||
InspectionToolWrapper toolWrapper = myView.getTree().getSelectedToolWrapper();
|
||||
assert toolWrapper != null;
|
||||
final QuickFixAction[] quickFixes = myView.getProvider().getQuickFixes(toolWrapper, myView.getTree());
|
||||
if (quickFixes == null || quickFixes.length == 0) {
|
||||
Messages.showInfoMessage(myView, "There are no applicable quickfixes", "Nothing found to fix");
|
||||
return;
|
||||
|
||||
+7
-8
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 29-Jan-2007
|
||||
@@ -8,7 +7,7 @@ package com.intellij.codeInspection.ui.actions;
|
||||
import com.intellij.codeInspection.*;
|
||||
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.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.ui.InspectionTreeNode;
|
||||
@@ -40,11 +39,11 @@ public class SuppressActionWrapper extends ActionGroup {
|
||||
private final Project myProject;
|
||||
private final InspectionManagerEx myManager;
|
||||
private final Set<InspectionTreeNode> myNodesToSuppress = new HashSet<InspectionTreeNode>();
|
||||
private final InspectionTool myTool;
|
||||
private final InspectionToolWrapper myToolWrapper;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.actions.SuppressActionWrapper");
|
||||
|
||||
public SuppressActionWrapper(@NotNull final Project project,
|
||||
@NotNull final InspectionTool tool,
|
||||
@NotNull final InspectionToolWrapper toolWrapper,
|
||||
@NotNull final TreePath[] paths) {
|
||||
super(InspectionsBundle.message("suppress.inspection.problem"), false);
|
||||
myProject = project;
|
||||
@@ -63,13 +62,13 @@ public class SuppressActionWrapper extends ActionGroup {
|
||||
}
|
||||
});
|
||||
}
|
||||
myTool = tool;
|
||||
myToolWrapper = toolWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public SuppressTreeAction[] getChildren(@Nullable final AnActionEvent e) {
|
||||
final SuppressIntentionAction[] suppressActions = myTool.getSuppressActions();
|
||||
final SuppressIntentionAction[] suppressActions = InspectionManagerEx.getSuppressActions(myToolWrapper.getTool());
|
||||
if (suppressActions == null || suppressActions.length == 0) return new SuppressTreeAction[0];
|
||||
final SuppressTreeAction[] actions = new SuppressTreeAction[suppressActions.length];
|
||||
for (int i = 0; i < suppressActions.length; i++) {
|
||||
@@ -93,7 +92,7 @@ public class SuppressActionWrapper extends ActionGroup {
|
||||
if (startModificationCount != tracker.getModificationCount()) {
|
||||
final Set<GlobalInspectionContextImpl> globalInspectionContexts = myManager.getRunningContexts();
|
||||
for (GlobalInspectionContextImpl context : globalInspectionContexts) {
|
||||
context.ignoreElement(myTool, element);
|
||||
context.ignoreElement(myToolWrapper.getTool(), element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,7 +107,7 @@ public class SuppressActionWrapper extends ActionGroup {
|
||||
@Override
|
||||
public void update(final AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(myTool != null && myTool.getSuppressActions() != null);
|
||||
e.getPresentation().setEnabled(InspectionManagerEx.getSuppressActions(myToolWrapper.getTool()) != null);
|
||||
}
|
||||
|
||||
private static Pair<PsiElement, CommonProblemDescriptor> getContentToSuppress(InspectionTreeNode node) {
|
||||
|
||||
+21
-3
@@ -25,8 +25,10 @@ import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
|
||||
import com.intellij.codeInspection.ex.SpecialToolsManager;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.ExportableComponent;
|
||||
import com.intellij.openapi.components.NamedComponent;
|
||||
import com.intellij.openapi.components.RoamingType;
|
||||
@@ -40,6 +42,7 @@ import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.options.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.profile.Profile;
|
||||
@@ -79,7 +82,7 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
return (InspectionProfileManagerImpl)ServiceManager.getService(InspectionProfileManager.class);
|
||||
}
|
||||
|
||||
public InspectionProfileManagerImpl(InspectionToolRegistrar registrar, SchemesManagerFactory schemesManagerFactory) {
|
||||
public InspectionProfileManagerImpl(InspectionToolRegistrar registrar, SchemesManagerFactory schemesManagerFactory, SpecialToolsManager specialToolsManager) {
|
||||
myRegistrar = registrar;
|
||||
mySeverityRegistrar = new SeverityRegistrar();
|
||||
registerProvidedSeverities();
|
||||
@@ -88,7 +91,7 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
@Override
|
||||
public InspectionProfileImpl readScheme(final Document document) {
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl(getProfileName(document), myRegistrar, InspectionProfileManagerImpl.this);
|
||||
profile.load(document.getRootElement());
|
||||
load(profile, document.getRootElement());
|
||||
return profile;
|
||||
}
|
||||
|
||||
@@ -128,6 +131,21 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
mySchemesManager = schemesManagerFactory.createSchemesManager(FILE_SPEC, processor, RoamingType.PER_USER);
|
||||
}
|
||||
|
||||
private static void load(final InspectionProfileImpl profile, @NotNull Element element) {
|
||||
try {
|
||||
profile.readExternal(element);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Messages.showErrorDialog(InspectionsBundle.message("inspection.error.loading.message", 0, profile.getName()),
|
||||
InspectionsBundle.message("inspection.errors.occurred.dialog.title"));
|
||||
}
|
||||
}, ModalityState.NON_MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static InspectionProfileImpl createSampleProfile() {
|
||||
return new InspectionProfileImpl("Default");
|
||||
@@ -215,7 +233,7 @@ public class InspectionProfileManagerImpl extends InspectionProfileManager imple
|
||||
if (profileElement != null) {
|
||||
rootElement = profileElement;
|
||||
}
|
||||
profile.load(rootElement);
|
||||
load(profile, rootElement);
|
||||
return profile;
|
||||
}
|
||||
return getProfile(path, false);
|
||||
|
||||
+6
-6
@@ -17,7 +17,7 @@ package com.intellij.profile.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.ex.Descriptor;
|
||||
import com.intellij.codeInspection.ex.ScopeToolState;
|
||||
import com.intellij.codeInspection.ex.ScopeToolStateUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.ClearableLazyValue;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.ui.CheckedTreeNode;
|
||||
@@ -37,7 +37,7 @@ public class InspectionConfigTreeNode extends CheckedTreeNode {
|
||||
@Override
|
||||
protected Boolean compute() {
|
||||
Descriptor descriptor = getDescriptor();
|
||||
if (descriptor != null) return descriptor.getInspectionProfile().isProperSetting(descriptor.getTool().getShortName());
|
||||
if (descriptor != null) return descriptor.getInspectionProfile().isProperSetting(descriptor.getToolWrapper().getShortName());
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
InspectionConfigTreeNode node = (InspectionConfigTreeNode)getChildAt(i);
|
||||
if (node.isProperSetting()) {
|
||||
@@ -48,7 +48,7 @@ public class InspectionConfigTreeNode extends CheckedTreeNode {
|
||||
}
|
||||
};
|
||||
|
||||
public InspectionConfigTreeNode(Object userObject, ScopeToolState state, boolean byDefault, boolean inspectionNode) {
|
||||
public InspectionConfigTreeNode(@NotNull Object userObject, ScopeToolState state, boolean byDefault, boolean inspectionNode) {
|
||||
super(userObject);
|
||||
myState = state;
|
||||
myByDefault = byDefault;
|
||||
@@ -58,7 +58,7 @@ public class InspectionConfigTreeNode extends CheckedTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
public InspectionConfigTreeNode(Descriptor descriptor, ScopeToolState state, boolean byDefault, boolean isEnabled,
|
||||
public InspectionConfigTreeNode(@NotNull Descriptor descriptor, ScopeToolState state, boolean byDefault, boolean isEnabled,
|
||||
boolean inspectionNode) {
|
||||
this(descriptor, state, byDefault, inspectionNode);
|
||||
setChecked(isEnabled);
|
||||
@@ -71,8 +71,8 @@ public class InspectionConfigTreeNode extends CheckedTreeNode {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public NamedScope getScope() {
|
||||
return myState != null ? ScopeToolStateUtil.getScope(myState) : null;
|
||||
public NamedScope getScope(Project project) {
|
||||
return myState == null ? null : myState.getScope(project);
|
||||
}
|
||||
|
||||
public boolean isByDefault() {
|
||||
|
||||
+8
-6
@@ -25,6 +25,7 @@ package com.intellij.profile.codeInspection.ui;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.codeInspection.ModifiableModel;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -94,20 +95,21 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple
|
||||
private JButton myCopyButton;
|
||||
private JBScrollPane myJBScrollPane;
|
||||
|
||||
private final ArrayList<String> myDeletedProfiles = new ArrayList<String>();
|
||||
private final List<String> myDeletedProfiles = new ArrayList<String>();
|
||||
protected final InspectionProfileManager myProfileManager;
|
||||
protected final InspectionProjectProfileManager myProjectProfileManager;
|
||||
private static final Logger LOG = Logger.getInstance("#" + InspectionToolsConfigurable.class.getName());
|
||||
private Alarm mySelectionAlarm;
|
||||
|
||||
|
||||
public InspectionToolsConfigurable(InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) {
|
||||
InspectionToolRegistrar.getInstance().buildInspectionSearchIndexIfNecessary();
|
||||
public InspectionToolsConfigurable(@NotNull final InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) {
|
||||
((InspectionManagerEx)InspectionManagerEx.getInstance(projectProfileManager.getProject())).buildInspectionSearchIndexIfNecessary();
|
||||
myAddButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Set<String> existingProfileNames = myPanels.keySet();
|
||||
final ModifiableModel model = SingleInspectionProfilePanel.createNewProfile(-1, getSelectedObject(), myWholePanel, "", existingProfileNames);
|
||||
final ModifiableModel model = SingleInspectionProfilePanel.createNewProfile(-1, getSelectedObject(), myWholePanel, "", existingProfileNames,
|
||||
projectProfileManager.getProject());
|
||||
if (model != null) {
|
||||
addProfile((InspectionProfileImpl)model);
|
||||
myDeletedProfiles.remove(getProfilePrefix(model) + model.getName());
|
||||
@@ -181,7 +183,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple
|
||||
}
|
||||
profile.readExternal(rootElement);
|
||||
profile.setLocal(true);
|
||||
profile.initInspectionTools(null);
|
||||
profile.initInspectionTools(project);
|
||||
if (getProfilePanel(profile) != null) {
|
||||
if (Messages.showOkCancelDialog(myWholePanel, "Profile with name \'" +
|
||||
profile.getName() +
|
||||
@@ -250,7 +252,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Set<String> existingProfileNames = myPanels.keySet();
|
||||
final InspectionProfileImpl model = (InspectionProfileImpl)
|
||||
SingleInspectionProfilePanel.createNewProfile(0, getSelectedObject(), myWholePanel, "", existingProfileNames);
|
||||
SingleInspectionProfilePanel.createNewProfile(0, getSelectedObject(), myWholePanel, "", existingProfileNames, project);
|
||||
if (model != null) {
|
||||
final InspectionProfileImpl modifiableModel = (InspectionProfileImpl)model.getModifiableModel();
|
||||
modifiableModel.setModified(true);
|
||||
|
||||
+10
-3
@@ -26,6 +26,7 @@ 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.openapi.project.Project;
|
||||
import com.intellij.ui.CheckboxTree;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
@@ -38,6 +39,12 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
abstract class InspectionsConfigTreeRenderer extends CheckboxTree.CheckboxTreeCellRenderer {
|
||||
private final Project myProject;
|
||||
|
||||
public InspectionsConfigTreeRenderer(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
protected abstract String getFilter();
|
||||
|
||||
@Override
|
||||
@@ -58,7 +65,7 @@ abstract class InspectionsConfigTreeRenderer extends CheckboxTree.CheckboxTreeCe
|
||||
Color foreground =
|
||||
selected ? UIUtil.getTreeSelectionForeground() : node.isProperSetting() ? PlatformColors.BLUE : UIUtil.getTreeTextForeground();
|
||||
|
||||
@NonNls String text = null;
|
||||
@NonNls String text;
|
||||
int style = SimpleTextAttributes.STYLE_PLAIN;
|
||||
String hint = null;
|
||||
if (object instanceof String) {
|
||||
@@ -74,7 +81,7 @@ abstract class InspectionsConfigTreeRenderer extends CheckboxTree.CheckboxTreeCe
|
||||
}
|
||||
else {
|
||||
text = "In scope \'" + scopeName + "\'";
|
||||
if (node.getScope() == null) {
|
||||
if (node.getScope(myProject) == null) {
|
||||
foreground = JBColor.RED;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +104,7 @@ abstract class InspectionsConfigTreeRenderer extends CheckboxTree.CheckboxTreeCe
|
||||
|
||||
@Nullable
|
||||
private static String getHint(Descriptor descriptor) {
|
||||
final InspectionToolWrapper toolWrapper = descriptor.getTool();
|
||||
final InspectionToolWrapper toolWrapper = descriptor.getToolWrapper();
|
||||
if (toolWrapper == null) {
|
||||
return InspectionsBundle.message("inspection.tool.availability.in.tree.node");
|
||||
}
|
||||
|
||||
+62
-65
@@ -39,6 +39,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.Splitter;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -107,6 +108,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
private boolean myModified = false;
|
||||
private Tree myTree;
|
||||
private TreeExpander myTreeExpander;
|
||||
@NotNull
|
||||
private String myInitialProfile;
|
||||
@NonNls private static final String EMPTY_HTML = "<html><body></body></html>";
|
||||
private boolean myIsInRestore = false;
|
||||
@@ -119,11 +121,9 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
private Splitter myRightSplitter;
|
||||
private Splitter myMainSplitter;
|
||||
|
||||
public SingleInspectionProfilePanel(final String inspectionProfileName, final ModifiableModel profile) {
|
||||
this(null, inspectionProfileName, profile);
|
||||
}
|
||||
|
||||
public SingleInspectionProfilePanel(InspectionProjectProfileManager projectProfileManager, final String inspectionProfileName, final ModifiableModel profile) {
|
||||
public SingleInspectionProfilePanel(@NotNull InspectionProjectProfileManager projectProfileManager,
|
||||
@NotNull String inspectionProfileName,
|
||||
@NotNull ModifiableModel profile) {
|
||||
super(new BorderLayout());
|
||||
myProjectProfileManager = projectProfileManager;
|
||||
mySelectedProfile = (InspectionProfileImpl)profile;
|
||||
@@ -195,7 +195,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
}
|
||||
|
||||
private boolean wereToolSettingsModified(Descriptor descriptor) {
|
||||
InspectionToolWrapper toolWrapper = descriptor.getTool();
|
||||
InspectionToolWrapper toolWrapper = descriptor.getToolWrapper();
|
||||
if (toolWrapper == null || !mySelectedProfile.isToolEnabled(descriptor.getKey())) {
|
||||
return false;
|
||||
}
|
||||
@@ -242,28 +242,26 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
final InspectionProfileImpl profile = mySelectedProfile;
|
||||
if (profile == null) return;
|
||||
myDescriptors.clear();
|
||||
List<ScopeToolState> tools = profile.getDefaultStates();
|
||||
List<ScopeToolState> tools = profile.getDefaultStates(myProjectProfileManager.getProject());
|
||||
for (ScopeToolState state : tools) {
|
||||
final ArrayList<Descriptor> descriptors = new ArrayList<Descriptor>();
|
||||
if (state.getLevel() == HighlightDisplayLevel.NON_SWITCHABLE_ERROR) {
|
||||
continue;
|
||||
}
|
||||
myDescriptors.put(new Descriptor(state, profile), descriptors);
|
||||
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));
|
||||
}
|
||||
Project project = myProjectProfileManager.getProject();
|
||||
myDescriptors.put(new Descriptor(state, profile, project), descriptors);
|
||||
InspectionToolWrapper toolWrapper = state.getTool();
|
||||
final List<ScopeToolState> nonDefaultTools = profile.getNonDefaultTools(toolWrapper.getShortName(), project);
|
||||
for (ScopeToolState nonDefaultToolState : nonDefaultTools) {
|
||||
descriptors.add(new Descriptor(nonDefaultToolState, profile, project));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void postProcessModification() {
|
||||
wereToolSettingsModified();
|
||||
//resetup configs
|
||||
for (ScopeToolState state : mySelectedProfile.getAllTools()) {
|
||||
for (ScopeToolState state : mySelectedProfile.getAllTools(myProjectProfileManager.getProject())) {
|
||||
state.resetConfigPanel();
|
||||
}
|
||||
fillTreeData(myProfileFilter.getFilter(), true);
|
||||
@@ -276,7 +274,8 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
ModifiableModel selectedProfile,
|
||||
JPanel parent,
|
||||
String profileName,
|
||||
Set<String> existingProfileNames) {
|
||||
Set<String> existingProfileNames,
|
||||
@NotNull Project project) {
|
||||
profileName = Messages.showInputDialog(parent, profileName, "Create New Inspection Profile", Messages.getQuestionIcon());
|
||||
if (profileName == null) return null;
|
||||
final ProfileManager profileManager = selectedProfile.getProfileManager();
|
||||
@@ -288,11 +287,11 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
InspectionProfileImpl inspectionProfile =
|
||||
new InspectionProfileImpl(profileName, InspectionToolRegistrar.getInstance(), profileManager);
|
||||
if (initValue == -1) {
|
||||
inspectionProfile.initInspectionTools(null);
|
||||
inspectionProfile.initInspectionTools(project);
|
||||
ModifiableModel profileModifiableModel = inspectionProfile.getModifiableModel();
|
||||
final InspectionToolWrapper[] profileEntries = (InspectionToolWrapper[])profileModifiableModel.getInspectionTools(null);
|
||||
final InspectionToolWrapper[] profileEntries = profileModifiableModel.getInspectionTools(null);
|
||||
for (InspectionToolWrapper toolWrapper : profileEntries) {
|
||||
profileModifiableModel.disableTool(toolWrapper.getShortName(), (NamedScope)null);
|
||||
profileModifiableModel.disableTool(toolWrapper.getShortName(), (NamedScope)null, project);
|
||||
}
|
||||
profileModifiableModel.setLocal(true);
|
||||
profileModifiableModel.setModified(true);
|
||||
@@ -300,7 +299,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
} else if (initValue == 0) {
|
||||
inspectionProfile.copyFrom(selectedProfile);
|
||||
inspectionProfile.setName(profileName);
|
||||
inspectionProfile.initInspectionTools(null);
|
||||
inspectionProfile.initInspectionTools(project);
|
||||
inspectionProfile.setModified(true);
|
||||
return inspectionProfile;
|
||||
}
|
||||
@@ -364,7 +363,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
mySelectedProfile.resetToBase();
|
||||
mySelectedProfile.resetToBase(myProjectProfileManager.getProject());
|
||||
postProcessModification();
|
||||
}
|
||||
});
|
||||
@@ -373,12 +372,12 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(mySelectedProfile != null && mySelectedProfile.isExecutable());
|
||||
e.getPresentation().setEnabled(mySelectedProfile != null && mySelectedProfile.isExecutable(myProjectProfileManager.getProject()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
mySelectedProfile.resetToEmpty();
|
||||
mySelectedProfile.resetToEmpty(e.getProject());
|
||||
postProcessModification();
|
||||
}
|
||||
});
|
||||
@@ -465,7 +464,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
fillTreeData(null, true);
|
||||
|
||||
final InspectionsConfigTreeRenderer renderer = new InspectionsConfigTreeRenderer(){
|
||||
final InspectionsConfigTreeRenderer renderer = new InspectionsConfigTreeRenderer(myProjectProfileManager.getProject()){
|
||||
@Override
|
||||
protected String getFilter() {
|
||||
return myProfileFilter != null ? myProfileFilter.getFilter() : null;
|
||||
@@ -615,29 +614,31 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
private void toggleToolNode(final InspectionConfigTreeNode toolNode) {
|
||||
final Descriptor descriptor = toolNode.getDescriptor();
|
||||
Project project = myProjectProfileManager.getProject();
|
||||
if (descriptor!= null) {
|
||||
final HighlightDisplayKey key = descriptor.getKey();
|
||||
final String toolShortName = key.toString();
|
||||
if (toolNode.isChecked()) {
|
||||
if (toolNode.getScope() != null){
|
||||
if (toolNode.getScope(project) != null){
|
||||
if (toolNode.isByDefault()) {
|
||||
mySelectedProfile.enableToolByDefault(toolShortName);
|
||||
} else {
|
||||
mySelectedProfile.enableTool(toolShortName, toolNode.getScope());
|
||||
mySelectedProfile.enableToolByDefault(toolShortName, project);
|
||||
}
|
||||
else {
|
||||
mySelectedProfile.enableTool(toolShortName, toolNode.getScope(project), project);
|
||||
}
|
||||
} else {
|
||||
mySelectedProfile.enableTool(toolShortName);
|
||||
mySelectedProfile.enableTool(toolShortName, project);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (toolNode.getScope() != null) {
|
||||
if (toolNode.getScope(project) != null) {
|
||||
if (toolNode.isByDefault()) {
|
||||
mySelectedProfile.disableToolByDefault(toolShortName);
|
||||
mySelectedProfile.disableToolByDefault(toolShortName, project);
|
||||
} else {
|
||||
mySelectedProfile.disableTool(toolShortName, toolNode.getScope());
|
||||
mySelectedProfile.disableTool(toolShortName, toolNode.getScope(project), project);
|
||||
}
|
||||
} else if (toolNode.getChildCount() == 0){ //default node and no scopes configured
|
||||
mySelectedProfile.disableTool(toolShortName);
|
||||
mySelectedProfile.disableTool(toolShortName, project);
|
||||
}
|
||||
}
|
||||
toolNode.dropCache();
|
||||
@@ -656,16 +657,6 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean wasModified(InspectionConfigTreeNode node) {
|
||||
for (int i = 0; i < node.getChildCount(); i++) {
|
||||
final InspectionConfigTreeNode childNode = (InspectionConfigTreeNode)node.getChildAt(i);
|
||||
if (childNode.isProperSetting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isDescriptorAccepted(Descriptor descriptor,
|
||||
@NonNls String filter,
|
||||
final boolean forceInclude,
|
||||
@@ -689,7 +680,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
final String description = descriptor.getTool().loadDescription();
|
||||
final String description = descriptor.getToolWrapper().loadDescription();
|
||||
if (description != null && StringUtil.containsIgnoreCase(description.toLowerCase(), stripped)) {
|
||||
if (!forceInclude) return true;
|
||||
} else if (forceInclude) return false;
|
||||
@@ -716,22 +707,24 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
myRoot.dropCache();
|
||||
List<Set<String>> keySetList = new ArrayList<Set<String>>();
|
||||
final Set<String> quated = new HashSet<String>();
|
||||
if (filter != null && filter.length() > 0) {
|
||||
if (filter != null && !filter.isEmpty()) {
|
||||
keySetList.addAll(SearchUtil.findKeys(filter, quated));
|
||||
}
|
||||
Project project = myProjectProfileManager.getProject();
|
||||
for (Descriptor descriptor : myDescriptors.keySet()) {
|
||||
if (filter != null && filter.length() > 0 && !isDescriptorAccepted(descriptor, filter, forceInclude, keySetList, quated)) {
|
||||
if (filter != null && !filter.isEmpty() && !isDescriptorAccepted(descriptor, filter, forceInclude, keySetList, quated)) {
|
||||
continue;
|
||||
}
|
||||
final List<ScopeToolState> nonDefaultTools = mySelectedProfile.getNonDefaultTools(descriptor.getKey().toString());
|
||||
final List<ScopeToolState> nonDefaultTools = mySelectedProfile.getNonDefaultTools(descriptor.getKey().toString(), project);
|
||||
final HighlightDisplayKey key = descriptor.getKey();
|
||||
final boolean enabled = mySelectedProfile.isToolEnabled(key);
|
||||
boolean hasNonDefaultScope = nonDefaultTools != null && !nonDefaultTools.isEmpty();
|
||||
boolean hasNonDefaultScope = !nonDefaultTools.isEmpty();
|
||||
final InspectionConfigTreeNode node = new InspectionConfigTreeNode(descriptor, null, !hasNonDefaultScope, enabled, !hasNonDefaultScope);
|
||||
getGroupNode(myRoot, descriptor.getGroup()).add(node);
|
||||
if (hasNonDefaultScope) {
|
||||
for (ScopeToolState nonDefaultState : nonDefaultTools) {
|
||||
node.add(new InspectionConfigTreeNode(new Descriptor(nonDefaultState, mySelectedProfile), nonDefaultState, false, false));
|
||||
node.add(new InspectionConfigTreeNode(new Descriptor(nonDefaultState, mySelectedProfile,
|
||||
project), nonDefaultState, false, false));
|
||||
}
|
||||
node.add(new InspectionConfigTreeNode(descriptor, descriptor.getState(), true, false));
|
||||
}
|
||||
@@ -783,7 +776,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
myOptionsPanel.removeAll();
|
||||
|
||||
final NamedScope scope = node.getScope();
|
||||
final NamedScope scope = node.getScope(myProjectProfileManager.getProject());
|
||||
if (scope != null || node.isInspectionNode()) {
|
||||
final HighlightDisplayKey key = descriptor.getKey();
|
||||
final LevelChooser chooser = new LevelChooser(((SeverityProvider)mySelectedProfile.getProfileManager()).getOwnSeverityRegistrar()) {
|
||||
@@ -801,12 +794,14 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
chooser.getComboBox().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
boolean toUpdate = mySelectedProfile.getErrorLevel(key, scope) != chooser.getLevel();
|
||||
mySelectedProfile.setErrorLevel(key, chooser.getLevel(), node.isInspectionNode() || node.isByDefault() ? -1 : node.getParent().getIndex(node));
|
||||
Project project = myProjectProfileManager.getProject();
|
||||
boolean toUpdate = mySelectedProfile.getErrorLevel(key, scope, project) != chooser.getLevel();
|
||||
mySelectedProfile.setErrorLevel(key, chooser.getLevel(), node.isInspectionNode() || node.isByDefault() ? -1 : node.getParent().getIndex(node),
|
||||
project);
|
||||
if (toUpdate) node.dropCache();
|
||||
}
|
||||
});
|
||||
chooser.setLevel(mySelectedProfile.getErrorLevel(key, scope));
|
||||
chooser.setLevel(mySelectedProfile.getErrorLevel(key, scope, myProjectProfileManager.getProject()));
|
||||
|
||||
final JPanel withSeverity = new JPanel(new GridBagLayout());
|
||||
withSeverity.add(new JLabel(InspectionsBundle.message("inspection.severity")),
|
||||
@@ -816,7 +811,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
GridBagConstraints.NONE, new Insets(0, 0, 10, 0), 0, 0));
|
||||
|
||||
final JComponent comp = descriptor.getState().getAdditionalConfigPanel();
|
||||
withSeverity.add(comp != null ? comp : new JPanel(),
|
||||
withSeverity.add(comp,
|
||||
new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
|
||||
GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
|
||||
@@ -897,7 +892,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
myAlarm.cancelAllRequests();
|
||||
myProfileFilter.dispose();
|
||||
if (mySelectedProfile != null) {
|
||||
for (ScopeToolState state : mySelectedProfile.getAllTools()) {
|
||||
for (ScopeToolState state : mySelectedProfile.getAllTools(myProjectProfileManager.getProject())) {
|
||||
state.resetConfigPanel();
|
||||
}
|
||||
}
|
||||
@@ -1033,29 +1028,30 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
private boolean descriptorsAreChanged() {
|
||||
for (Map.Entry<Descriptor, List<Descriptor>> entry : myDescriptors.entrySet()) {
|
||||
Descriptor desc = entry.getKey();
|
||||
if (mySelectedProfile.isToolEnabled(desc.getKey(), (NamedScope)null) != desc.isEnabled()){
|
||||
Project project = myProjectProfileManager.getProject();
|
||||
if (mySelectedProfile.isToolEnabled(desc.getKey(), (NamedScope)null, project) != desc.isEnabled()){
|
||||
return true;
|
||||
}
|
||||
if (mySelectedProfile.getErrorLevel(desc.getKey(), desc.getScope()) != desc.getLevel()) {
|
||||
if (mySelectedProfile.getErrorLevel(desc.getKey(), desc.getScope(), project) != desc.getLevel()) {
|
||||
return true;
|
||||
}
|
||||
final List<Descriptor> descriptors = entry.getValue();
|
||||
for (Descriptor descriptor : descriptors) {
|
||||
if (mySelectedProfile.isToolEnabled(descriptor.getKey(), descriptor.getScope()) != descriptor.isEnabled()) {
|
||||
if (mySelectedProfile.isToolEnabled(descriptor.getKey(), descriptor.getScope(), project) != descriptor.isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
if (mySelectedProfile.getErrorLevel(descriptor.getKey(), descriptor.getScope()) != descriptor.getLevel()) {
|
||||
if (mySelectedProfile.getErrorLevel(descriptor.getKey(), descriptor.getScope(), project) != descriptor.getLevel()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final List<ScopeToolState> tools = mySelectedProfile.getNonDefaultTools(desc.getKey().toString());
|
||||
final List<ScopeToolState> tools = mySelectedProfile.getNonDefaultTools(desc.getKey().toString(), project);
|
||||
if (tools.size() != descriptors.size()) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0, toolsSize = tools.size(); i < toolsSize; i++) {
|
||||
for (int i = 0; i < tools.size(); i++) {
|
||||
final ScopeToolState pair = tools.get(i);
|
||||
if (!Comparing.equal(ScopeToolStateUtil.getScope(pair), descriptors.get(i).getScope())) {
|
||||
if (!Comparing.equal(pair.getScope(project), descriptors.get(i).getScope())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1130,7 +1126,8 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
final boolean showOptionsAndDescriptorPanels,
|
||||
@NotNull HighlightDisplayLevel level) {
|
||||
final HighlightDisplayKey key = child.getDescriptor().getKey();
|
||||
mySelectedProfile.setErrorLevel(key, level, child.isInspectionNode() || child.isByDefault() ? -1 : child.getParent().getIndex(child));
|
||||
mySelectedProfile.setErrorLevel(key, level, child.isInspectionNode() || child.isByDefault() ? -1 : child.getParent().getIndex(child),
|
||||
myProjectProfileManager.getProject());
|
||||
child.dropCache();
|
||||
if (showOptionsAndDescriptorPanels) {
|
||||
updateOptionsAndDescriptionPanel(new TreePath(child.getPath()));
|
||||
@@ -1155,7 +1152,7 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
getExpandedNodes(mySelectedProfile).saveVisibleState(myTree);
|
||||
fillTreeData(filter, true);
|
||||
reloadModel();
|
||||
if (filter == null || filter.length() == 0) {
|
||||
if (filter == null || filter.isEmpty()) {
|
||||
restoreTreeState();
|
||||
} else {
|
||||
TreeUtil.expandAll(myTree);
|
||||
|
||||
+9
-7
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.intellij.profile.codeInspection.ui.actions;
|
||||
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.ex.Descriptor;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
@@ -97,13 +98,14 @@ public abstract class AddScopeAction extends AnAction {
|
||||
for (InspectionConfigTreeNode node : nodes) {
|
||||
final Descriptor descriptor = node.getDescriptor();
|
||||
if (node.getScopeName() != null || descriptor == null) continue;
|
||||
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());
|
||||
final InspectionToolWrapper toolWrapper = descriptor.getToolWrapper(); //copy
|
||||
InspectionProfileImpl selectedProfile = getSelectedProfile();
|
||||
HighlightDisplayLevel level = selectedProfile.getErrorLevel(descriptor.getKey(), chosenScope, project);
|
||||
boolean enabled = selectedProfile.isToolEnabled(descriptor.getKey());
|
||||
final ScopeToolState scopeToolState = selectedProfile.addScope(toolWrapper, chosenScope, level, enabled, project);
|
||||
final Descriptor addedDescriptor = new Descriptor(scopeToolState, selectedProfile, project);
|
||||
if (node.getChildCount() == 0) {
|
||||
node.add(new InspectionConfigTreeNode(descriptor, getSelectedProfile().getToolDefaultState(descriptor.getKey().toString()), true, true, false));
|
||||
node.add(new InspectionConfigTreeNode(descriptor, selectedProfile.getToolDefaultState(descriptor.getKey().toString(), project), true, true, false));
|
||||
}
|
||||
node.insert(new InspectionConfigTreeNode(addedDescriptor, scopeToolState, false, false), 0);
|
||||
node.setInspectionNode(false);
|
||||
@@ -142,7 +144,7 @@ public abstract class AddScopeAction extends AnAction {
|
||||
|
||||
final Set<NamedScope> used = new HashSet<NamedScope>();
|
||||
for (Descriptor descriptor : descriptors) {
|
||||
final List<ScopeToolState> nonDefaultTools = getSelectedProfile().getNonDefaultTools(descriptor.getKey().toString());
|
||||
final List<ScopeToolState> nonDefaultTools = getSelectedProfile().getNonDefaultTools(descriptor.getKey().toString(), project);
|
||||
if (nonDefaultTools != null) {
|
||||
for (ScopeToolState state : nonDefaultTools) {
|
||||
used.add(state.getScope(project));
|
||||
|
||||
+4
-3
@@ -69,12 +69,13 @@ public abstract class DeleteScopeAction extends AnAction {
|
||||
parent = (InspectionConfigTreeNode)node.getParent();
|
||||
final HighlightDisplayKey key = descriptor.getKey();
|
||||
if (parent.getChildCount() <= 2) { //remove default with last non-default
|
||||
getSelectedProfile().removeAllScopes(key.toString());
|
||||
getSelectedProfile().removeAllScopes(key.toString(), e.getProject());
|
||||
parent.removeAllChildren();
|
||||
parent.setInspectionNode(true);
|
||||
parent.setByDefault(true);
|
||||
} else {
|
||||
getSelectedProfile().removeScope(key.toString(), parent.getIndex(node));
|
||||
}
|
||||
else {
|
||||
getSelectedProfile().removeScope(key.toString(), parent.getIndex(node), e.getProject());
|
||||
node.removeFromParent();
|
||||
}
|
||||
((DefaultTreeModel)myTree.getModel()).reload(parent);
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ public abstract class MoveScopeAction extends AnAction {
|
||||
final InspectionConfigTreeNode[] nodes = myTree.getSelectedNodes(InspectionConfigTreeNode.class, null);
|
||||
if (nodes.length > 0) {
|
||||
final InspectionConfigTreeNode treeNode = nodes[0];
|
||||
if (treeNode.getScope() != null && !treeNode.isByDefault()) {
|
||||
if (treeNode.getScope(getEventProject(e)) != null && !treeNode.isByDefault()) {
|
||||
final TreeNode parent = treeNode.getParent();
|
||||
final int index = parent.getIndex(treeNode);
|
||||
presentation.setEnabled(isEnabledFor(index, (InspectionConfigTreeNode)parent));
|
||||
@@ -69,7 +69,7 @@ public abstract class MoveScopeAction extends AnAction {
|
||||
final Descriptor descriptor = node.getDescriptor();
|
||||
final TreeNode parent = node.getParent();
|
||||
final int index = parent.getIndex(node);
|
||||
getSelectedProfile().moveScope(descriptor.getKey().toString(), index, myDir);
|
||||
getSelectedProfile().moveScope(descriptor.getKey().toString(), index, myDir, e.getProject());
|
||||
node.removeFromParent();
|
||||
((InspectionConfigTreeNode)parent).insert(node, index + myDir);
|
||||
((DefaultTreeModel)myTree.getModel()).reload(parent);
|
||||
|
||||
@@ -20,9 +20,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionManagerEx;
|
||||
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;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import junit.framework.Assert;
|
||||
@@ -127,11 +125,13 @@ expected:
|
||||
return Comparing.equal(reportedFile.getName(), expectedProblem.getChildText("file"));
|
||||
}
|
||||
|
||||
public static void compareToolResults(InspectionToolWrapper toolWrapper, boolean checkRange, String testDir) {
|
||||
public static void compareToolResults(@NotNull InspectionToolWrapper toolWrapper, boolean checkRange, String testDir) {
|
||||
final Element root = new Element("problems");
|
||||
final Document doc = new Document(root);
|
||||
toolWrapper.updateContent(); //e.g. dead code need check for reachables
|
||||
toolWrapper.exportResults(root);
|
||||
InspectionToolPresentation presentation = ((GlobalInspectionContextImpl)toolWrapper.getContext()).getPresentation(toolWrapper);
|
||||
|
||||
presentation.updateContent(); //e.g. dead code need check for reachables
|
||||
presentation.exportResults(root);
|
||||
|
||||
File file = new File(testDir + "/expected.xml");
|
||||
try {
|
||||
@@ -154,11 +154,6 @@ expected:
|
||||
HighlightDisplayKey.register(shortName);
|
||||
}
|
||||
|
||||
((ProgressManagerImpl)ProgressManager.getInstance()).executeProcessUnderProgress(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
globalContext.performInspectionsWithProgress(scope, inspectionManager);
|
||||
}
|
||||
}, new EmptyProgressIndicator());
|
||||
globalContext.doInspections(scope, inspectionManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,8 +466,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
enableInspectionTool(myAvailableInspectionTools, wrapper);
|
||||
}
|
||||
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
|
||||
//assert !(tool instanceof InspectionToolWrapper) : tool;
|
||||
enableInspectionTool(myAvailableInspectionTools, InspectionToolRegistrar.wrapTool(tool));
|
||||
InspectionToolWrapper toolWrapper = tool instanceof InspectionTool ? new CommonInspectionToolWrapper((InspectionTool)tool) : InspectionToolRegistrar.wrapTool(tool);
|
||||
enableInspectionTool(myAvailableInspectionTools, toolWrapper);
|
||||
}
|
||||
|
||||
private static void enableInspectionTool(@NotNull Map<String, InspectionToolWrapper> availableLocalTools, @NotNull InspectionToolWrapper wrapper) {
|
||||
|
||||
+38
-52
@@ -329,17 +329,15 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final boolean checkInfos,
|
||||
final boolean checkWeakWarnings,
|
||||
final String... filePaths) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
if (filePaths.length > 0) {
|
||||
configureByFilesInner(filePaths);
|
||||
}
|
||||
try {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
return collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,15 +357,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final boolean checkInfos,
|
||||
final boolean checkWeakWarnings,
|
||||
@NonNls final VirtualFile... files) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration, files);
|
||||
return duration.get().longValue();
|
||||
return collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, files);
|
||||
}
|
||||
|
||||
private void collectAndCheckHighlightings(final boolean checkWarnings,
|
||||
private long collectAndCheckHighlightings(final boolean checkWarnings,
|
||||
final boolean checkInfos,
|
||||
final boolean checkWeakWarnings,
|
||||
final Ref<Long> duration,
|
||||
final VirtualFile[] files) {
|
||||
final List<Trinity<PsiFile, Editor, ExpectedHighlightingData>> datas =
|
||||
ContainerUtil.map2List(files, new Function<VirtualFile, Trinity<PsiFile, Editor, ExpectedHighlightingData>>() {
|
||||
@@ -382,23 +377,23 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return Trinity.create(psiFile, createEditor(file), data);
|
||||
}
|
||||
});
|
||||
long elapsed = 0;
|
||||
for (Trinity<PsiFile, Editor, ExpectedHighlightingData> trinity : datas) {
|
||||
myEditor = trinity.second;
|
||||
myFile = trinity.first;
|
||||
collectAndCheckHighlightings(trinity.third, duration);
|
||||
elapsed += collectAndCheckHighlightings(trinity.third);
|
||||
}
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long checkHighlighting(final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
try {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
return collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -416,15 +411,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final boolean checkInfos,
|
||||
final boolean checkWeakWarnings,
|
||||
final VirtualFile file) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
openFileInEditor(file);
|
||||
try {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
return collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -436,7 +429,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
ExpectedHighlightingData data = new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
if (checkSymbolNames) data.checkSymbolNames();
|
||||
data.init();
|
||||
collectAndCheckHighlightings(data, Ref.create(0L));
|
||||
collectAndCheckHighlightings(data);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
@@ -461,19 +454,19 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
InspectionTestUtil.compareToolResults(toolWrapper, false, new File(getTestDataPath(), testDir).getPath());
|
||||
}
|
||||
|
||||
public static GlobalInspectionContextImpl createGlobalContextForTool(AnalysisScope scope,
|
||||
final Project project,
|
||||
final InspectionManagerEx inspectionManager,
|
||||
final InspectionToolWrapper ... toolWrappers) {
|
||||
|
||||
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", toolWrappers);
|
||||
GlobalInspectionContextImpl globalContext = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
|
||||
@NotNull
|
||||
public static GlobalInspectionContextImpl createGlobalContextForTool(@NotNull AnalysisScope scope,
|
||||
@NotNull final Project project,
|
||||
@NotNull InspectionManagerEx inspectionManager,
|
||||
@NotNull final InspectionToolWrapper ... toolWrappers) {
|
||||
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", project, toolWrappers);
|
||||
GlobalInspectionContextImpl context = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) {
|
||||
@Override
|
||||
protected List<Tools> getUsedTools() {
|
||||
try {
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = true;
|
||||
for (InspectionToolWrapper tool : toolWrappers) {
|
||||
profile.enableTool(tool.getShortName());
|
||||
profile.enableTool(tool.getShortName(), project);
|
||||
}
|
||||
return profile.getAllEnabledInspectionTools(project);
|
||||
}
|
||||
@@ -482,8 +475,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
}
|
||||
};
|
||||
globalContext.setCurrentScope(scope);
|
||||
return globalContext;
|
||||
context.setCurrentScope(scope);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -935,7 +929,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
|
||||
final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText);
|
||||
result.setResult(PsiManager.getInstance(getProject()).findFile(file));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result.setResult(((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText));
|
||||
}
|
||||
}
|
||||
@@ -1141,16 +1136,15 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
|
||||
private void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
|
||||
assert !(tool instanceof InspectionToolWrapper) : tool;
|
||||
InspectionToolWrapper wrapper = InspectionToolRegistrar.wrapTool(tool);
|
||||
InspectionToolWrapper toolWrapper = tool instanceof InspectionTool ? new CommonInspectionToolWrapper((InspectionTool)tool) : InspectionToolRegistrar.wrapTool(tool);
|
||||
final String shortName = tool.getShortName();
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
|
||||
|
||||
if (key == null) {
|
||||
String id = tool instanceof LocalInspectionTool ? ((LocalInspectionTool)tool).getID() : shortName;
|
||||
HighlightDisplayKey.register(shortName, wrapper.getDisplayName(), id);
|
||||
HighlightDisplayKey.register(shortName, toolWrapper.getDisplayName(), id);
|
||||
}
|
||||
myAvailableTools.put(shortName, wrapper);
|
||||
myAvailableTools.put(shortName, toolWrapper);
|
||||
}
|
||||
|
||||
private void configureInspections(@NotNull InspectionProfileEntry[] tools) {
|
||||
@@ -1186,7 +1180,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public List<Tools> getAllEnabledInspectionTools(Project project) {
|
||||
List<Tools> result = new ArrayList<Tools>();
|
||||
for (InspectionToolWrapper toolWrapper : getInspectionTools(null)) {
|
||||
for (InspectionToolWrapper toolWrapper : getInspectionTools(getFile())) {
|
||||
result.add(new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true));
|
||||
}
|
||||
return result;
|
||||
@@ -1198,14 +1192,14 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionToolWrapper getInspectionTool(@NotNull String shortName) {
|
||||
public InspectionToolWrapper getInspectionTool(@NotNull String shortName, Project project) {
|
||||
return myAvailableTools.get(shortName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, PsiElement element) {
|
||||
final InspectionProfileEntry entry = myAvailableTools.get(key.toString());
|
||||
return entry != null ? entry.getDefaultLevel() : HighlightDisplayLevel.WARNING;
|
||||
final InspectionToolWrapper toolWrapper = myAvailableTools.get(key.toString());
|
||||
return toolWrapper == null ? HighlightDisplayLevel.WARNING : toolWrapper.getDefaultLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1309,10 +1303,6 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return PsiDocumentManager.getInstance(getProject()).getDocument(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePath
|
||||
* @throws IOException
|
||||
*/
|
||||
private PsiFile configureByFileInner(@NonNls String filePath) {
|
||||
assertInitialized();
|
||||
final VirtualFile file = copyFileToProject(filePath);
|
||||
@@ -1403,15 +1393,15 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return instance.openTextEditor(new OpenFileDescriptor(project, file, 0), false);
|
||||
}
|
||||
|
||||
private void collectAndCheckHighlightings(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, Ref<Long> duration)
|
||||
private long collectAndCheckHighlightings(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings)
|
||||
throws Exception {
|
||||
ExpectedHighlightingData data =
|
||||
new ExpectedHighlightingData(myEditor.getDocument(), checkWarnings, checkWeakWarnings, checkInfos, myFile);
|
||||
data.init();
|
||||
collectAndCheckHighlightings(data, duration);
|
||||
return collectAndCheckHighlightings(data);
|
||||
}
|
||||
|
||||
private void collectAndCheckHighlightings(final ExpectedHighlightingData data, final Ref<Long> duration) {
|
||||
private long collectAndCheckHighlightings(final ExpectedHighlightingData data) {
|
||||
final Project project = getProject();
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
@@ -1423,24 +1413,23 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
|
||||
List<HighlightInfo> infos;
|
||||
final long start = System.currentTimeMillis();
|
||||
try {
|
||||
((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(myJavaFilesFilter);
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
// ProfilingUtil.startCPUProfiling();
|
||||
infos = doHighlighting();
|
||||
removeDuplicatedRangesForInjected(infos);
|
||||
final long elapsed = System.currentTimeMillis() - start;
|
||||
duration.set(duration.isNull() ? elapsed : duration.get().longValue() + elapsed);
|
||||
// ProfilingUtil.captureCPUSnapshot("testing");
|
||||
}
|
||||
finally {
|
||||
((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
}
|
||||
|
||||
final long elapsed = System.currentTimeMillis() - start;
|
||||
|
||||
data.checkResult(infos, myEditor.getDocument().getText());
|
||||
hardRefToFileElement.hashCode(); // use it so gc won't collect it
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
private static void removeDuplicatedRangesForInjected(List<HighlightInfo> infos) {
|
||||
@@ -1745,12 +1734,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
selStartLine == selStartLineActual &&
|
||||
selEndCol == selEndColActual &&
|
||||
selEndLine == selEndLineActual;
|
||||
Assert.assertTrue("selection in " +
|
||||
expectedFile +
|
||||
" differs. Expected " +
|
||||
genSelectionPresentation(selStartLine, selStartCol, selEndLine, selEndCol) +
|
||||
". Actual " +
|
||||
genSelectionPresentation(selStartLineActual, selStartColActual, selEndLineActual, selEndColActual),
|
||||
Assert.assertTrue("selection in " + expectedFile +
|
||||
" differs. Expected " + genSelectionPresentation(selStartLine, selStartCol, selEndLine, selEndCol) +
|
||||
". Actual " + genSelectionPresentation(selStartLineActual, selStartColActual, selEndLineActual, selEndColActual),
|
||||
selectionEquals);
|
||||
}
|
||||
else if (myEditor != null) {
|
||||
|
||||
@@ -1354,6 +1354,7 @@
|
||||
|
||||
<applicationService serviceInterface="com.intellij.profile.codeInspection.InspectionProfileManager"
|
||||
serviceImplementation="com.intellij.profile.codeInspection.JavaAwareInspectionProfileManager"/>
|
||||
<applicationService serviceImplementation="com.intellij.codeInspection.ex.SpecialToolsManager"/>
|
||||
|
||||
<resolveScopeEnlarger implementation="com.intellij.psi.NonClasspathResolveScopeEnlarger"/>
|
||||
|
||||
|
||||
+2
-7
@@ -22,7 +22,6 @@ 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;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -273,9 +272,9 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
|
||||
Class rootType = fileElement.getRootElementClass();
|
||||
final InspectionProfile profile = getInspectionProfile(fileElement);
|
||||
final List<DomElementsInspection> inspections = new SmartList<DomElementsInspection>();
|
||||
for (final InspectionToolWrapper toolWrapper : (InspectionToolWrapper[])profile.getInspectionTools(fileElement.getFile())) {
|
||||
for (final InspectionToolWrapper toolWrapper : profile.getInspectionTools(fileElement.getFile())) {
|
||||
if (!enabledOnly || profile.isToolEnabled(HighlightDisplayKey.find(toolWrapper.getShortName()), fileElement.getFile())) {
|
||||
ContainerUtil.addIfNotNull(getSuitableInspection(toolWrapper, rootType), inspections);
|
||||
ContainerUtil.addIfNotNull(getSuitableInspection(toolWrapper.getTool(), rootType), inspections);
|
||||
}
|
||||
}
|
||||
return inspections;
|
||||
@@ -287,10 +286,6 @@ public class DomElementAnnotationsManagerImpl extends DomElementAnnotationsManag
|
||||
|
||||
@Nullable
|
||||
private static DomElementsInspection getSuitableInspection(InspectionProfileEntry entry, Class rootType) {
|
||||
if (entry instanceof LocalInspectionToolWrapper) {
|
||||
return getSuitableInspection(((LocalInspectionToolWrapper)entry).getTool(), rootType);
|
||||
}
|
||||
|
||||
if (entry instanceof DomElementsInspection) {
|
||||
if (((DomElementsInspection)entry).getDomClasses().contains(rootType)) {
|
||||
return (DomElementsInspection) entry;
|
||||
|
||||
@@ -22,7 +22,7 @@ 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.codeInspection.ex.SpecialToolsManager;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.mock.MockInspectionProfile;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
@@ -54,9 +54,9 @@ public class DomHighlightingLiteTest extends DomTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
final InspectionToolRegistrar registrar = new InspectionToolRegistrar(SearchableOptionsRegistrar.getInstance());
|
||||
final InspectionToolRegistrar registrar = new InspectionToolRegistrar();
|
||||
registrar.registerTools(new InspectionToolProvider[0]);
|
||||
final InspectionProfileManager inspectionProfileManager = new InspectionProfileManagerImpl(registrar, new MockSchemesManagerFactory());
|
||||
final InspectionProfileManager inspectionProfileManager = new InspectionProfileManagerImpl(registrar, new MockSchemesManagerFactory(), new SpecialToolsManager(registrar));
|
||||
myInspectionProfile = new MockInspectionProfile();
|
||||
myAnnotationsManager = new DomElementAnnotationsManagerImpl(getProject()) {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.intellij.xml.impl;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.Validator;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.ide.highlighter.XHtmlFileType;
|
||||
import com.intellij.ide.highlighter.XmlFileType;
|
||||
import com.intellij.lang.Language;
|
||||
@@ -112,6 +112,7 @@ public class ExternalDocumentValidator {
|
||||
final List<ValidationInfo> results = new LinkedList<ValidationInfo>();
|
||||
|
||||
myHost = new Validator.ValidationHost() {
|
||||
@Override
|
||||
public void addMessage(PsiElement context, String message, int type) {
|
||||
final ValidationInfo o = new ValidationInfo();
|
||||
|
||||
@@ -121,19 +122,23 @@ public class ExternalDocumentValidator {
|
||||
o.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(final PsiElement context, final String message, final ErrorType type) {
|
||||
addMessage(context, message, type.ordinal());
|
||||
}
|
||||
};
|
||||
|
||||
myHandler.setErrorReporter(new ErrorReporter(myHandler) {
|
||||
@Override
|
||||
public boolean isStopOnUndeclaredResource() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(final SAXParseException e, final ValidateXmlActionHandler.ProblemType warning) {
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (e.getPublicId() != null) {
|
||||
return;
|
||||
@@ -341,7 +346,7 @@ public class ExternalDocumentValidator {
|
||||
if (containingFile.getViewProvider() instanceof TemplateLanguageFileViewProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final FileType fileType = containingFile.getViewProvider().getVirtualFile().getFileType();
|
||||
if (fileType != XmlFileType.INSTANCE && fileType != XHtmlFileType.INSTANCE) {
|
||||
return;
|
||||
@@ -360,7 +365,7 @@ public class ExternalDocumentValidator {
|
||||
final Project project = document.getProject();
|
||||
|
||||
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
final InspectionProfileEntry toolWrapper =
|
||||
final InspectionToolWrapper toolWrapper =
|
||||
profile.getInspectionTool(INSPECTION_SHORT_NAME, containingFile);
|
||||
|
||||
if (toolWrapper == null) return;
|
||||
|
||||
Reference in New Issue
Block a user