update copyrights
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / ex / InspectionProfileImpl.java
blob8c01d33801ea7dc1e9c8624d1f72cc760f9f3caa
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.codeInspection.ex;
19 import com.intellij.codeHighlighting.HighlightDisplayLevel;
20 import com.intellij.codeInsight.daemon.HighlightDisplayKey;
21 import com.intellij.codeInsight.daemon.InspectionProfileConvertor;
22 import com.intellij.codeInspection.InspectionProfile;
23 import com.intellij.codeInspection.InspectionProfileEntry;
24 import com.intellij.codeInspection.InspectionsBundle;
25 import com.intellij.codeInspection.ModifiableModel;
26 import com.intellij.openapi.application.ApplicationManager;
27 import com.intellij.openapi.application.ModalityState;
28 import com.intellij.openapi.diagnostic.Logger;
29 import com.intellij.openapi.options.ExternalInfo;
30 import com.intellij.openapi.options.ExternalizableScheme;
31 import com.intellij.openapi.progress.ProcessCanceledException;
32 import com.intellij.openapi.project.Project;
33 import com.intellij.openapi.ui.Messages;
34 import com.intellij.openapi.util.InvalidDataException;
35 import com.intellij.openapi.util.WriteExternalException;
36 import com.intellij.profile.DefaultProjectProfileManager;
37 import com.intellij.profile.ProfileEx;
38 import com.intellij.profile.ProfileManager;
39 import com.intellij.profile.codeInspection.InspectionProfileManager;
40 import com.intellij.profile.codeInspection.SeverityProvider;
41 import com.intellij.psi.PsiElement;
42 import com.intellij.psi.search.scope.packageSet.NamedScope;
43 import org.jdom.Document;
44 import org.jdom.Element;
45 import org.jdom.JDOMException;
46 import org.jetbrains.annotations.NonNls;
47 import org.jetbrains.annotations.NotNull;
48 import org.jetbrains.annotations.Nullable;
50 import java.io.IOException;
51 import java.util.*;
52 import java.util.concurrent.atomic.AtomicBoolean;
54 /**
55 * @author max
57 public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, InspectionProfile, ExternalizableScheme {
58 @NonNls private static InspectionProfileImpl DEFAULT_PROFILE;
60 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
61 @NonNls private static final String VALID_VERSION = "1.0";
63 private Map<String, ToolsImpl> myTools = new HashMap<String, ToolsImpl>();
65 private Map<String, Boolean> myDisplayLevelMap;
66 private Map<String, Element> myDeinstalledInspectionsSettings = new TreeMap<String, Element>();
67 private boolean myLockedProfile = false;
69 protected InspectionProfileImpl mySource;
70 private InspectionProfileImpl myBaseProfile = null;
71 @NonNls private static final String VERSION_TAG = "version";
72 @NonNls private static final String INSPECTION_TOOL_TAG = "inspection_tool";
73 @NonNls static final String ENABLED_TAG = "enabled";
74 @NonNls static final String LEVEL_TAG = "level";
75 @NonNls private static final String CLASS_TAG = "class";
76 @NonNls private static final String PROFILE_NAME_TAG = "profile_name";
77 @NonNls private static final String ROOT_ELEMENT_TAG = "inspections";
78 @NonNls static final String SCOPE = "scope";
80 private String myEnabledTool = null;
81 @NonNls private static final String USED_LEVELS = "used_levels";
83 final InspectionToolRegistrar myRegistrar;
84 @NonNls private static final String IS_LOCKED = "is_locked";
85 private final ExternalInfo myExternalInfo = new ExternalInfo();
86 static final String NAME = "name";
87 public static boolean INIT_INSPECTIONS = false;
89 //private String myBaseProfileName;
91 public void setModified(final boolean modified) {
92 myModified = modified;
95 private boolean myModified = false;
96 private final AtomicBoolean myInitialized = new AtomicBoolean(false);
98 private VisibleTreeState myVisibleTreeState = new VisibleTreeState();
100 public InspectionProfileImpl(InspectionProfileImpl inspectionProfile) {
101 super(inspectionProfile.getName());
103 myRegistrar = inspectionProfile.myRegistrar;
104 myTools = new HashMap<String, ToolsImpl>();
105 myVisibleTreeState = new VisibleTreeState(inspectionProfile.myVisibleTreeState);
106 myDeinstalledInspectionsSettings = new LinkedHashMap<String, Element>(inspectionProfile.myDeinstalledInspectionsSettings);
108 myBaseProfile = inspectionProfile.myBaseProfile;
109 myLocal = inspectionProfile.myLocal;
110 myLockedProfile = inspectionProfile.myLockedProfile;
111 mySource = inspectionProfile;
112 setProfileManager(inspectionProfile.getProfileManager());
113 copyFrom(inspectionProfile);
114 initInspectionTools();
117 public InspectionProfileImpl(final String inspectionProfile,
118 final InspectionToolRegistrar registrar,
119 final ProfileManager profileManager) {
120 super(inspectionProfile);
121 myRegistrar = registrar;
122 myBaseProfile = getDefaultProfile();
123 setProfileManager(profileManager);
126 public InspectionProfileImpl(@NonNls String name) {
127 super(name);
128 myRegistrar = InspectionToolRegistrar.getInstance();
129 setProfileManager(InspectionProfileManager.getInstance());
132 public InspectionProfile getParentProfile() {
133 return mySource;
136 @Override
137 public void setProfileManager(@NotNull ProfileManager profileManager) {
138 super.setProfileManager(profileManager);
139 /*final NamedScopesHolder scopesHolder = profileManager.getScopesManager();
140 if (scopesHolder != null) {
141 scopesHolder.addScopeListener(new NamedScopesHolder.ScopeListener() {//todo scopes change tracking
142 public void scopesChanged() {
148 public String getBaseProfileName() {
149 if (myBaseProfile == null) return null;
150 return myBaseProfile.getName();
153 public void setBaseProfile(InspectionProfile profile) {
154 myBaseProfile = (InspectionProfileImpl)profile;
157 @SuppressWarnings({"SimplifiableIfStatement"})
158 public boolean isChanged() {
159 if (mySource != null && mySource.myLockedProfile != myLockedProfile) return true;
160 return myModified;
163 public VisibleTreeState getExpandedNodes() {
164 return myVisibleTreeState;
167 private static boolean toolSettingsAreEqual(String toolName, InspectionProfileImpl profile1, InspectionProfileImpl profile2) {
168 final ToolsImpl toolList1 = profile1.myTools.get(toolName);
169 final ToolsImpl toolList2 = profile2.myTools.get(toolName);
171 if (toolList1 == null && toolList2 == null) {
172 return true;
174 if (toolList1 != null && toolList2 != null) {
175 return toolList1.equalTo(toolList2);
177 return false;
180 public boolean isProperSetting(HighlightDisplayKey key) {
181 final Map<String, Boolean> diffMap = getDisplayLevelMap();
182 if (diffMap != null) {
183 final ToolsImpl tools = myBaseProfile.getTools(key.toString());
184 final ToolsImpl currentTools = myTools.get(key.toString());
185 if (tools != null && currentTools != null) {
186 diffMap.put(key.toString(), tools.equalTo(currentTools));
187 } else {
188 diffMap.put(key.toString(), tools == currentTools);
190 return !diffMap.get(key.toString()).booleanValue();
192 return false;
195 public void resetToBase() {
196 copyToolsConfigurations(myBaseProfile);
197 myDisplayLevelMap = null;
200 public void resetToEmpty() {
201 final InspectionProfileEntry[] profileEntries = getInspectionTools(null);
202 for (InspectionProfileEntry entry : profileEntries) {
203 disableTool(entry.getShortName());
207 public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) {
208 final ToolsImpl tools = getTools(inspectionToolKey.toString());
209 HighlightDisplayLevel level = tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
210 if (!((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().isSeverityValid(level.getSeverity().toString())) {
211 level = HighlightDisplayLevel.WARNING;
212 setErrorLevel(inspectionToolKey, level);
214 return level;
218 public void readExternal(Element element) throws InvalidDataException {
219 super.readExternal(element);
220 final String locked = element.getAttributeValue(IS_LOCKED);
221 if (locked != null) {
222 myLockedProfile = Boolean.parseBoolean(locked);
224 myBaseProfile = getDefaultProfile();
225 final String version = element.getAttributeValue(VERSION_TAG);
226 if (version == null || !version.equals(VALID_VERSION)) {
227 try {
228 element = InspectionProfileConvertor.convertToNewFormat(element, this);
230 catch (IOException e) {
231 LOG.error(e);
233 catch (JDOMException e) {
234 LOG.error(e);
238 final Element highlightElement = element.getChild(USED_LEVELS);
239 if (highlightElement != null) { //from old profiles
240 ((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().readExternal(highlightElement);
243 for (final Object o : element.getChildren(INSPECTION_TOOL_TAG)) {
244 Element toolElement = (Element)o;
246 String toolClassName = toolElement.getAttributeValue(CLASS_TAG);
248 myDeinstalledInspectionsSettings.put(toolClassName, toolElement);
253 public void writeExternal(Element element) throws WriteExternalException {
254 super.writeExternal(element);
255 element.setAttribute(VERSION_TAG, VALID_VERSION);
256 element.setAttribute(IS_LOCKED, String.valueOf(myLockedProfile));
258 if (!myInitialized.get()) {
259 for (Element el : myDeinstalledInspectionsSettings.values()) {
260 element.addContent((Element)el.clone());
262 return;
265 Map<String, Boolean> diffMap = getDisplayLevelMap();
266 if (diffMap != null) {
268 diffMap = new TreeMap<String, Boolean>(diffMap);
269 for (String toolName : myDeinstalledInspectionsSettings.keySet()) {
270 diffMap.put(toolName, false);
273 for (final String toolName : diffMap.keySet()) {
274 if (!myLockedProfile && diffMap.get(toolName).booleanValue()) continue;
275 final Element toolElement = myDeinstalledInspectionsSettings.get(toolName);
276 if (toolElement == null) {
277 final ToolsImpl toolList = myTools.get(toolName);
278 LOG.assertTrue(toolList != null);
279 final Element inspectionElement = new Element(INSPECTION_TOOL_TAG);
280 inspectionElement.setAttribute(CLASS_TAG, toolName);
281 toolList.writeExternal(inspectionElement);
282 element.addContent(inspectionElement);
284 else {
285 element.addContent((Element)toolElement.clone());
291 public InspectionProfileEntry getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
292 final Tools toolList = getTools(shortName);
293 return toolList != null ? toolList.getInspectionTool(element) : null;
296 public InspectionProfileEntry getInspectionTool(@NotNull String shortName) {
297 return getTools(shortName).getTool();
300 public InspectionProfileEntry getToolById(String id, PsiElement element) {
301 initInspectionTools();
302 for (Tools toolList : myTools.values()) {
303 final InspectionProfileEntry tool = toolList.getInspectionTool(element);
304 String toolId =
305 tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getTool().getID() : tool.getShortName();
306 if (id.equals(toolId)) return tool;
308 return null;
311 public void save() throws IOException {
313 if (isLocal()) {
314 if (myName.compareTo("Default") == 0 && myElement == null){
315 myElement = new Element(ROOT_ELEMENT_TAG);
317 if (myElement != null) {
318 try {
319 myElement = new Element(ROOT_ELEMENT_TAG);
320 myElement.setAttribute(PROFILE_NAME_TAG, myName);
321 writeExternal(myElement);
322 myVisibleTreeState.writeExternal(myElement);
324 catch (WriteExternalException e) {
325 LOG.error(e);
330 InspectionProfileManager.getInstance().fireProfileChanged(this);
333 public boolean isEditable() {
334 return myEnabledTool == null;
337 @NotNull
338 public String getDisplayName() {
339 return isEditable() ? getName() : myEnabledTool;
342 public void setEditable(final String displayName) {
343 myEnabledTool = displayName;
346 public void load(Element element) {
347 try {
348 readExternal(element);
350 catch (Exception e) {
351 ApplicationManager.getApplication().invokeLater(new Runnable() {
352 public void run() {
353 Messages.showErrorDialog(InspectionsBundle.message("inspection.error.loading.message", 0, getName()),
354 InspectionsBundle.message("inspection.errors.occured.dialog.title"));
356 }, ModalityState.NON_MODAL);
360 public boolean isDefault() {
361 final Map<String, Boolean> map = getDisplayLevelMap();
362 if (map != null) {
363 for (Boolean def : map.values()) {
364 if (!def.booleanValue()) return false;
367 return true;
370 public boolean isProfileLocked() {
371 return myLockedProfile;
374 public void lockProfile(boolean isLocked) {
375 for (Tools toolList : myTools.values()) {
376 final String key = toolList.getShortName();
377 if (isLocked) {
378 myDisplayLevelMap.put(key, Boolean.FALSE);
381 myLockedProfile = isLocked;
384 @NotNull
385 public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
386 initInspectionTools();
387 ArrayList<InspectionProfileEntry> result = new ArrayList<InspectionProfileEntry>();
388 for (Tools toolList : myTools.values()) {
389 result.add(toolList.getInspectionTool(element));
391 return result.toArray(new InspectionTool[result.size()]);
394 public List<ToolsImpl> getAllEnabledInspectionTools() {
395 initInspectionTools();
396 final ArrayList<ToolsImpl> result = new ArrayList<ToolsImpl>();
397 for (final ToolsImpl toolList : myTools.values()) {
398 if (toolList.isEnabled()) {
399 result.add(toolList);
402 return result;
405 public void disableTool(String toolId, PsiElement element) {
406 getTools(toolId).disableTool(element);
409 public void disableToolByDefault(String toolId) {
410 getTools(toolId).getDefaultState().setEnabled(false);
413 public void enableToolByDefault(String toolId) {
414 getTools(toolId).getDefaultState().setEnabled(true);
417 public boolean wasInitialized() {
418 return myInitialized.get();
421 public void initInspectionTools() {
422 if (!ApplicationManager.getApplication().isUnitTestMode() || INIT_INSPECTIONS) {
423 synchronized (myInitialized) {
424 if (!myInitialized.getAndSet(true)) {
425 if (myBaseProfile != null) {
426 myBaseProfile.initInspectionTools();
429 final InspectionTool[] tools;
430 try {
431 tools = myRegistrar.createTools();
433 catch (ProcessCanceledException e) {
434 myInitialized.set(false);
435 return;
437 for (InspectionTool tool : tools) {
438 final String shortName = tool.getShortName();
439 HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
440 if (key == null) {
441 if (tool instanceof LocalInspectionToolWrapper) {
442 key = HighlightDisplayKey.register(shortName, tool.getDisplayName(), ((LocalInspectionToolWrapper)tool).getTool().getID(),
443 ((LocalInspectionToolWrapper)tool).getTool().getAlternativeID());
445 else {
446 key = HighlightDisplayKey.register(shortName);
450 LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
451 final ToolsImpl toolsList =
452 new ToolsImpl(tool, myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : tool.getDefaultLevel(),
453 !myLockedProfile && (myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : tool.isEnabledByDefault()));
454 final Element element = myDeinstalledInspectionsSettings.remove(tool.getShortName());
455 if (element != null) {
456 try {
457 toolsList.readExternal(element, this);
459 catch (InvalidDataException e) {
460 LOG.error(e);
463 myTools.put(tool.getShortName(), toolsList);
465 if (mySource != null) {
466 copyToolsConfigurations(mySource);
473 private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key) {
474 final ToolsImpl tools = getTools(key.toString());
475 LOG.assertTrue(tools != null, "profile name: " + myName + " base profile: " + (myBaseProfile != null ? myBaseProfile.getName() : "-") + " key: " + key);
476 return tools != null ? tools.getLevel() : HighlightDisplayLevel.WARNING;
479 @NotNull
480 public ModifiableModel getModifiableModel() {
481 InspectionProfileImpl modifiableModel = new InspectionProfileImpl(this);
482 modifiableModel.myExternalInfo.copy(myExternalInfo);
483 return modifiableModel;
486 public void copyFrom(InspectionProfile profile) {
487 super.copyFrom(profile);
488 final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)profile;
489 myBaseProfile = inspectionProfile.myBaseProfile;
492 public void copyToolsConfigurations(InspectionProfileImpl profile) {
493 try {
494 initInspectionTools();
495 for (ToolsImpl toolList : profile.myTools.values()) {
496 final ToolsImpl tools = myTools.get(toolList.getShortName());
497 final ScopeToolState defaultState = toolList.getDefaultState();
498 tools.setDefaultState(copyToolSettings((InspectionTool)defaultState.getTool()), defaultState.isEnabled(), defaultState.getLevel());
499 tools.removeAllScopes();
500 tools.setEnabled(toolList.isEnabled());
501 final List<ScopeToolState> nonDefaultToolStates = toolList.getNonDefaultTools();
502 if (nonDefaultToolStates != null) {
503 for (ScopeToolState state : nonDefaultToolStates) {
504 final InspectionTool inspectionTool = copyToolSettings((InspectionTool)state.getTool());
505 if (state.getScope() != null) {
506 tools.addTool(state.getScope(), inspectionTool, state.isEnabled(), state.getLevel());
507 } else {
508 tools.addTool(state.getScopeName(), inspectionTool, state.isEnabled(), state.getLevel());
514 catch (WriteExternalException e) {
515 LOG.error(e);
517 catch (InvalidDataException e) {
518 LOG.error(e);
524 private InspectionTool copyToolSettings(InspectionTool tool)
525 throws WriteExternalException, InvalidDataException {
526 @NonNls String tempRoot = "config";
527 Element config = new Element(tempRoot);
528 tool.writeSettings(config);
529 final InspectionTool inspectionTool = myRegistrar.createInspectionTool(tool.getShortName(), tool);
530 inspectionTool.readSettings(config);
531 return inspectionTool;
534 public void cleanup(Project project) {
535 for (final ToolsImpl toolList : myTools.values()) {
536 if (toolList.isEnabled()) {
537 for (InspectionProfileEntry tool : toolList.getAllTools()) {
538 tool.projectClosed(project);
539 if (((InspectionTool)tool).getContext() != null) {
540 ((InspectionTool)tool).cleanup();
547 public void enableTool(String inspectionTool) {
548 final ToolsImpl tools = getTools(inspectionTool);
549 tools.setEnabled(true);
550 if (tools.getNonDefaultTools() == null) {
551 tools.getDefaultState().setEnabled(true);
555 public void enableTool(String inspectionTool, NamedScope namedScope) {
556 getTools(inspectionTool).enableTool(namedScope);
559 public void disableTool(String inspectionTool, NamedScope namedScope) {
560 getTools(inspectionTool).disableTool(namedScope);
564 public void disableTool(String inspectionTool) {
565 final ToolsImpl tools = getTools(inspectionTool);
566 tools.setEnabled(false);
567 if (tools.getNonDefaultTools() == null) {
568 tools.getDefaultState().setEnabled(false);
572 public void setErrorLevel(HighlightDisplayKey key, HighlightDisplayLevel level) {
573 getTools(key.toString()).setLevel(level);
576 public boolean isToolEnabled(HighlightDisplayKey key, PsiElement element) {
577 if (key == null) {
578 return false;
580 final Tools toolState = getTools(key.toString());
581 return toolState != null && toolState.isEnabled(element);
584 public boolean isToolEnabled(HighlightDisplayKey key) {
585 final Tools toolState = getTools(key.toString());
586 return toolState != null && toolState.isEnabled();
589 public boolean isExecutable() {
590 initInspectionTools();
591 for (ToolsImpl tools : myTools.values()) {
592 if (tools.isEnabled()) return true;
594 return false;
597 //invoke when isChanged() == true
598 public void commit() throws IOException {
599 LOG.assertTrue(mySource != null);
600 mySource.commit(this);
601 getProfileManager().updateProfile(mySource);
602 mySource = null;
605 private void commit(InspectionProfileImpl inspectionProfile) {
606 myName = inspectionProfile.myName;
607 myLocal = inspectionProfile.myLocal;
608 myLockedProfile = inspectionProfile.myLockedProfile;
609 myDisplayLevelMap = inspectionProfile.myDisplayLevelMap;
610 myVisibleTreeState = inspectionProfile.myVisibleTreeState;
611 myBaseProfile = inspectionProfile.myBaseProfile;
612 myTools = inspectionProfile.myTools;
613 myProfileMananger = inspectionProfile.myProfileMananger;
615 myExternalInfo.copy(inspectionProfile.getExternalInfo());
617 InspectionProfileManager.getInstance().fireProfileChanged(inspectionProfile);
620 public static synchronized InspectionProfileImpl getDefaultProfile() {
621 if (DEFAULT_PROFILE == null) {
622 DEFAULT_PROFILE = new InspectionProfileImpl("Default");
624 return DEFAULT_PROFILE;
627 public Document saveToDocument() throws WriteExternalException {
628 if (isLocal()) {
629 Element root = new Element(ROOT_ELEMENT_TAG);
630 root.setAttribute(PROFILE_NAME_TAG, myName);
631 writeExternal(root);
632 //myVisibleTreeState.writeExternal(root);
633 return new Document(root);
635 else {
636 return null;
641 public VisibleTreeState getVisibleTreeState() {
642 return myVisibleTreeState;
645 public void setVisibleTreeState(final VisibleTreeState state) {
646 myVisibleTreeState = state;
649 public void convert(Element element) {
650 initInspectionTools();
651 final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
652 if (scopes != null) {
653 final List children = scopes.getChildren(SCOPE);
654 if (children != null) {
655 for (Object s : children) {
656 Element scopeElement = (Element)s;
657 final String profile = scopeElement.getAttributeValue(DefaultProjectProfileManager.PROFILE);
658 if (profile != null) {
659 final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)getProfileManager().getProfile(profile);
660 if (inspectionProfile != null) {
661 final NamedScope scope = getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
662 if (scope != null) {
663 for (InspectionProfileEntry entry : inspectionProfile.getInspectionTools(null)) {
664 final HighlightDisplayKey key = HighlightDisplayKey.find(entry.getShortName());
665 try {
666 getTools(entry.getShortName())
667 .addTool(scope, copyToolSettings((InspectionTool)entry), inspectionProfile.isToolEnabled(key), inspectionProfile.getErrorLevel(key, (NamedScope)null));
669 catch (Exception e) {
670 LOG.error(e);
677 reduceConvertedScopes();
682 private void reduceConvertedScopes() {
683 for (ToolsImpl tools : myTools.values()) {
684 final ScopeToolState toolState = tools.getDefaultState();
685 final List<ScopeToolState> nonDefaultTools = tools.getNonDefaultTools();
686 if (nonDefaultTools != null) {
687 boolean equal = true;
688 boolean isEnabled = toolState.isEnabled();
689 for (ScopeToolState state : nonDefaultTools) {
690 isEnabled |= state.isEnabled();
691 if (!state.equalTo(toolState)) {
692 equal = false;
695 tools.setEnabled(isEnabled);
696 if (equal) {
697 tools.removeAllScopes();
703 @NotNull
704 public ExternalInfo getExternalInfo() {
705 return myExternalInfo;
708 public List<ScopeToolState> getAllTools() {
709 initInspectionTools();
710 final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
711 for (Tools tools : myTools.values()) {
712 result.addAll(tools.getTools());
714 return result;
717 public List<ScopeToolState> getDefaultStates() {
718 initInspectionTools();
719 final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
720 for (Tools tools : myTools.values()) {
721 result.add(tools.getDefaultState());
723 return result;
726 public List<ScopeToolState> getNonDefaultTools(String shortName) {
727 final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
728 final List<ScopeToolState> nonDefaultTools = getTools(shortName).getNonDefaultTools();
729 if (nonDefaultTools != null) {
730 result.addAll(nonDefaultTools);
732 return result;
735 public boolean isToolEnabled(HighlightDisplayKey key, NamedScope namedScope) {
736 return getTools(key.toString()).isEnabled(namedScope);
739 public void removeScope(String toolId, int scopeIdx) {
740 getTools(toolId).removeScope(scopeIdx);
743 public void removeAllScopes(String toolId) {
744 getTools(toolId).removeAllScopes();
747 public void setScope(String toolId, int idx, NamedScope namedScope) {
748 getTools(toolId).setScope(idx, namedScope);
751 public void moveScope(String toolId, int idx, int dir) {
752 getTools(toolId).moveScope(idx, dir);
755 @Nullable
756 private Map<String, Boolean> getDisplayLevelMap() {
757 if (myBaseProfile == null) return null;
758 if (myDisplayLevelMap == null) {
759 initInspectionTools();
760 myDisplayLevelMap = new TreeMap<String, Boolean>();
761 for (String toolId : myTools.keySet()) {
762 myDisplayLevelMap.put(toolId, toolSettingsAreEqual(toolId, myBaseProfile, this));
765 return myDisplayLevelMap;
768 public HighlightDisplayLevel getErrorLevel(HighlightDisplayKey key, NamedScope scope) {
769 final ToolsImpl tools = getTools(key.toString());
770 return tools != null ? tools.getLevel(scope) : HighlightDisplayLevel.WARNING;
773 public ScopeToolState addScope(InspectionProfileEntry tool, NamedScope scope, HighlightDisplayLevel level, boolean enabled) {
774 return getTools(tool.getShortName()).prependTool(scope, tool, enabled, level);
778 public void setErrorLevel(HighlightDisplayKey key, HighlightDisplayLevel level, int scopeIdx) {
779 getTools(key.toString()).setLevel(level, scopeIdx);
782 private ToolsImpl getTools(String toolId) {
783 initInspectionTools();
784 return myTools.get(toolId);