7 package com
.intellij
.codeInspection
.ex
;
9 import com
.intellij
.codeInspection
.*;
10 import com
.intellij
.codeInspection
.lang
.InspectionExtensionsFactory
;
11 import com
.intellij
.ide
.impl
.ContentManagerWatcher
;
12 import com
.intellij
.openapi
.application
.ApplicationManager
;
13 import com
.intellij
.openapi
.components
.ProjectComponent
;
14 import com
.intellij
.openapi
.extensions
.Extensions
;
15 import com
.intellij
.openapi
.project
.Project
;
16 import com
.intellij
.openapi
.util
.*;
17 import com
.intellij
.openapi
.wm
.ToolWindow
;
18 import com
.intellij
.openapi
.wm
.ToolWindowAnchor
;
19 import com
.intellij
.openapi
.wm
.ToolWindowId
;
20 import com
.intellij
.openapi
.wm
.ToolWindowManager
;
21 import com
.intellij
.profile
.codeInspection
.InspectionProfileManager
;
22 import com
.intellij
.profile
.codeInspection
.InspectionProjectProfileManager
;
23 import com
.intellij
.psi
.PsiElement
;
24 import com
.intellij
.ui
.content
.ContentFactory
;
25 import com
.intellij
.ui
.content
.ContentManager
;
26 import com
.intellij
.ui
.content
.TabbedPaneContentUI
;
27 import org
.jdom
.Element
;
28 import org
.jetbrains
.annotations
.NonNls
;
29 import org
.jetbrains
.annotations
.NotNull
;
30 import org
.jetbrains
.annotations
.Nullable
;
32 import java
.util
.HashSet
;
35 public class InspectionManagerEx
extends InspectionManager
implements JDOMExternalizable
, ProjectComponent
{
36 private GlobalInspectionContextImpl myGlobalInspectionContext
= null;
37 private final Project myProject
;
38 @NonNls private String myCurrentProfileName
;
39 private ContentManager myContentManager
= null;
41 private final Set
<GlobalInspectionContextImpl
> myRunningContexts
= new HashSet
<GlobalInspectionContextImpl
>();
43 public InspectionManagerEx(Project project
) {
48 public Project
getProject() {
53 public void initComponent() {
56 public void disposeComponent() {
59 public void projectOpened() {
60 myContentManager
= ContentFactory
.SERVICE
.getInstance().createContentManager(new TabbedPaneContentUI(), true, myProject
);
61 if (!ApplicationManager
.getApplication().isHeadlessEnvironment()) { //headless environment
62 ToolWindowManager toolWindowManager
= ToolWindowManager
.getInstance(myProject
);
63 ToolWindow toolWindow
=
64 toolWindowManager
.registerToolWindow(ToolWindowId
.INSPECTION
, myContentManager
.getComponent(), ToolWindowAnchor
.BOTTOM
);
65 toolWindow
.setIcon(IconLoader
.getIcon("/general/toolWindowInspection.png"));
66 new ContentManagerWatcher(toolWindow
, myContentManager
);
71 public void projectClosed() {
72 if (ApplicationManager
.getApplication().isHeadlessEnvironment()) return;
73 ToolWindowManager
.getInstance(myProject
).unregisterToolWindow(ToolWindowId
.INSPECTION
);
77 public void readExternal(@NonNls Element element
) throws InvalidDataException
{
78 DefaultJDOMExternalizer
.readExternal(this, element
);
81 public void writeExternal(Element element
) throws WriteExternalException
{
82 DefaultJDOMExternalizer
.writeExternal(this, element
);
86 public CommonProblemDescriptor
createProblemDescriptor(@NotNull String descriptionTemplate
, QuickFix
... fixes
) {
87 return new CommonProblemDescriptorImpl(fixes
, descriptionTemplate
);
91 public ProblemDescriptor
createProblemDescriptor(@NotNull PsiElement psiElement
,
92 @NotNull String descriptionTemplate
,
94 ProblemHighlightType highlightType
) {
95 LocalQuickFix
[] quickFixes
= fix
!= null ?
new LocalQuickFix
[]{fix
} : null;
96 return createProblemDescriptor(psiElement
, descriptionTemplate
, quickFixes
, highlightType
);
100 public ProblemDescriptor
createProblemDescriptor(@NotNull PsiElement psiElement
,
101 @NotNull String descriptionTemplate
,
102 LocalQuickFix
[] fixes
,
103 ProblemHighlightType highlightType
) {
104 return createProblemDescriptor(psiElement
, descriptionTemplate
, fixes
, highlightType
, false);
108 public ProblemDescriptor
createProblemDescriptor(@NotNull PsiElement psiElement
,
109 @NotNull String descriptionTemplate
,
110 LocalQuickFix
[] fixes
,
111 ProblemHighlightType highlightType
,
112 boolean isAfterEndOfLine
) {
113 return new ProblemDescriptorImpl(psiElement
, psiElement
, descriptionTemplate
, fixes
, highlightType
, isAfterEndOfLine
, null);
117 public ProblemDescriptor
createProblemDescriptor(@NotNull PsiElement startElement
,
118 @NotNull PsiElement endElement
,
119 @NotNull String descriptionTemplate
,
120 ProblemHighlightType highlightType
,
121 LocalQuickFix
... fixes
) {
122 return new ProblemDescriptorImpl(startElement
, endElement
, descriptionTemplate
, fixes
, highlightType
, false, null);
125 public ProblemDescriptor
createProblemDescriptor(@NotNull final PsiElement psiElement
,
126 final TextRange rangeInElement
,
127 @NotNull final String descriptionTemplate
,
128 final ProblemHighlightType highlightType
,
129 final LocalQuickFix
... fixes
) {
130 return new ProblemDescriptorImpl(psiElement
, psiElement
, descriptionTemplate
, fixes
, highlightType
, false, rangeInElement
);
133 public ProblemDescriptor
createProblemDescriptor(@NotNull final PsiElement psiElement
, @NotNull final String descriptionTemplate
, final ProblemHighlightType highlightType
,
134 @Nullable final HintAction hintAction
,
135 final LocalQuickFix
... fixes
) {
137 return new ProblemDescriptorImpl(psiElement
, psiElement
, descriptionTemplate
, fixes
, highlightType
, false, null, hintAction
);
142 public String
getComponentName() {
143 return "InspectionManager";
146 public GlobalInspectionContextImpl
createNewGlobalContext(boolean reuse
) {
148 if (myGlobalInspectionContext
== null) {
149 myGlobalInspectionContext
= new GlobalInspectionContextImpl(myProject
, myContentManager
);
151 myRunningContexts
.add(myGlobalInspectionContext
);
152 return myGlobalInspectionContext
;
154 final GlobalInspectionContextImpl inspectionContext
= new GlobalInspectionContextImpl(myProject
, myContentManager
);
155 myRunningContexts
.add(inspectionContext
);
156 return inspectionContext
;
159 public void setProfile(final String name
) {
160 myCurrentProfileName
= name
;
163 public String
getCurrentProfile() {
164 if (myCurrentProfileName
== null) {
165 final InspectionProjectProfileManager profileManager
= InspectionProjectProfileManager
.getInstance(myProject
);
166 if (profileManager
.useProjectLevelProfileSettings()) {
167 myCurrentProfileName
= profileManager
.getProjectProfile();
169 if (myCurrentProfileName
== null) {
170 myCurrentProfileName
= InspectionProfileManager
.getInstance().getRootProfile().getName();
173 return myCurrentProfileName
;
176 public void closeRunningContext(GlobalInspectionContextImpl globalInspectionContext
){
177 myRunningContexts
.remove(globalInspectionContext
);
180 public Set
<GlobalInspectionContextImpl
> getRunningContexts() {
181 return myRunningContexts
;
184 public static boolean inspectionResultSuppressed(PsiElement place
, LocalInspectionTool tool
) {
185 if (tool
instanceof CustomSuppressableInspectionTool
) {
186 return ((CustomSuppressableInspectionTool
)tool
).isSuppressedFor(place
);
188 return isSuppressed(place
, tool
.getID());
191 public static boolean canRunInspections(final Project project
, final boolean online
) {
192 for (InspectionExtensionsFactory factory
: Extensions
.getExtensions(InspectionExtensionsFactory
.EP_NAME
)) {
193 if (!factory
.isProjectConfiguredToRunInspections(project
, online
)) {
200 public static boolean isSuppressed(PsiElement psiElement
, String id
) {
201 for (InspectionExtensionsFactory factory
: Extensions
.getExtensions(InspectionExtensionsFactory
.EP_NAME
)) {
202 if (!factory
.isToCheckMember(psiElement
, id
)) {