ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / ex / InspectionProfileImpl.java
blobef4b3fc1a99e6ec112b871ddb1706d6e38b0662a
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.lang.annotation.HighlightSeverity;
27 import com.intellij.openapi.application.ApplicationManager;
28 import com.intellij.openapi.application.ModalityState;
29 import com.intellij.openapi.diagnostic.Logger;
30 import com.intellij.openapi.options.ExternalInfo;
31 import com.intellij.openapi.options.ExternalizableScheme;
32 import com.intellij.openapi.progress.ProcessCanceledException;
33 import com.intellij.openapi.project.Project;
34 import com.intellij.openapi.ui.Messages;
35 import com.intellij.openapi.util.InvalidDataException;
36 import com.intellij.openapi.util.WriteExternalException;
37 import com.intellij.profile.DefaultProjectProfileManager;
38 import com.intellij.profile.ProfileEx;
39 import com.intellij.profile.ProfileManager;
40 import com.intellij.profile.codeInspection.InspectionProfileManager;
41 import com.intellij.profile.codeInspection.SeverityProvider;
42 import com.intellij.psi.PsiElement;
43 import com.intellij.psi.search.scope.packageSet.NamedScope;
44 import org.jdom.Document;
45 import org.jdom.Element;
46 import org.jdom.JDOMException;
47 import org.jetbrains.annotations.NonNls;
48 import org.jetbrains.annotations.NotNull;
49 import org.jetbrains.annotations.Nullable;
51 import java.io.IOException;
52 import java.util.*;
53 import java.util.concurrent.atomic.AtomicBoolean;
55 /**
56 * @author max
58 public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, InspectionProfile, ExternalizableScheme {
59 @NonNls private static InspectionProfileImpl DEFAULT_PROFILE;
61 private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
62 @NonNls private static final String VALID_VERSION = "1.0";
64 private Map<String, ToolsImpl> myTools = new HashMap<String, ToolsImpl>();
66 private Map<String, Boolean> myDisplayLevelMap;
67 private Map<String, Element> myDeinstalledInspectionsSettings = new TreeMap<String, Element>();
68 private boolean myLockedProfile = false;
70 protected InspectionProfileImpl mySource;
71 private InspectionProfileImpl myBaseProfile = null;
72 @NonNls private static final String VERSION_TAG = "version";
73 @NonNls private static final String INSPECTION_TOOL_TAG = "inspection_tool";
74 @NonNls static final String ENABLED_TAG = "enabled";
75 @NonNls static final String LEVEL_TAG = "level";
76 @NonNls private static final String CLASS_TAG = "class";
77 @NonNls private static final String PROFILE_NAME_TAG = "profile_name";
78 @NonNls private static final String ROOT_ELEMENT_TAG = "inspections";
79 @NonNls static final String SCOPE = "scope";
81 private String myEnabledTool = null;
82 @NonNls private static final String USED_LEVELS = "used_levels";
84 final InspectionToolRegistrar myRegistrar;
85 @NonNls private static final String IS_LOCKED = "is_locked";
86 private final ExternalInfo myExternalInfo = new ExternalInfo();
87 static final String NAME = "name";
88 public static boolean INIT_INSPECTIONS = false;
90 //private String myBaseProfileName;
92 public void setModified(final boolean modified) {
93 myModified = modified;
96 private boolean myModified = false;
97 private final AtomicBoolean myInitialized = new AtomicBoolean(false);
99 private VisibleTreeState myVisibleTreeState = new VisibleTreeState();
101 public InspectionProfileImpl(InspectionProfileImpl inspectionProfile) {
102 super(inspectionProfile.getName());
104 myRegistrar = inspectionProfile.myRegistrar;
105 myTools = new HashMap<String, ToolsImpl>();
106 myVisibleTreeState = new VisibleTreeState(inspectionProfile.myVisibleTreeState);
107 myDeinstalledInspectionsSettings = new LinkedHashMap<String, Element>(inspectionProfile.myDeinstalledInspectionsSettings);
109 myBaseProfile = inspectionProfile.myBaseProfile;
110 myLocal = inspectionProfile.myLocal;
111 myLockedProfile = inspectionProfile.myLockedProfile;
112 mySource = inspectionProfile;
113 setProfileManager(inspectionProfile.getProfileManager());
114 copyFrom(inspectionProfile);
115 initInspectionTools();
118 public InspectionProfileImpl(final String inspectionProfile,
119 final InspectionToolRegistrar registrar,
120 final ProfileManager profileManager) {
121 super(inspectionProfile);
122 myRegistrar = registrar;
123 myBaseProfile = getDefaultProfile();
124 setProfileManager(profileManager);
127 public InspectionProfileImpl(@NonNls String name) {
128 super(name);
129 myRegistrar = InspectionToolRegistrar.getInstance();
130 setProfileManager(InspectionProfileManager.getInstance());
133 public InspectionProfile getParentProfile() {
134 return mySource;
137 @Override
138 public void setProfileManager(@NotNull ProfileManager profileManager) {
139 super.setProfileManager(profileManager);
140 /*final NamedScopesHolder scopesHolder = profileManager.getScopesManager();
141 if (scopesHolder != null) {
142 scopesHolder.addScopeListener(new NamedScopesHolder.ScopeListener() {//todo scopes change tracking
143 public void scopesChanged() {
149 public String getBaseProfileName() {
150 if (myBaseProfile == null) return null;
151 return myBaseProfile.getName();
154 public void setBaseProfile(InspectionProfile profile) {
155 myBaseProfile = (InspectionProfileImpl)profile;
158 @SuppressWarnings({"SimplifiableIfStatement"})
159 public boolean isChanged() {
160 if (mySource != null && mySource.myLockedProfile != myLockedProfile) return true;
161 return myModified;
164 public VisibleTreeState getExpandedNodes() {
165 return myVisibleTreeState;
168 private static boolean toolSettingsAreEqual(String toolName, InspectionProfileImpl profile1, InspectionProfileImpl profile2) {
169 final ToolsImpl toolList1 = profile1.myTools.get(toolName);
170 final ToolsImpl toolList2 = profile2.myTools.get(toolName);
172 if (toolList1 == null && toolList2 == null) {
173 return true;
175 if (toolList1 != null && toolList2 != null) {
176 return toolList1.equalTo(toolList2);
178 return false;
181 public boolean isProperSetting(HighlightDisplayKey key) {
182 final Map<String, Boolean> diffMap = getDisplayLevelMap();
183 if (diffMap != null) {
184 final ToolsImpl tools = myBaseProfile.getTools(key.toString());
185 final ToolsImpl currentTools = myTools.get(key.toString());
186 if (tools != null && currentTools != null) {
187 diffMap.put(key.toString(), tools.equalTo(currentTools));
188 } else {
189 diffMap.put(key.toString(), tools == currentTools);
191 return !diffMap.get(key.toString()).booleanValue();
193 return false;
196 public void resetToBase() {
197 copyToolsConfigurations(myBaseProfile);
198 myDisplayLevelMap = null;
201 public void resetToEmpty() {
202 final InspectionProfileEntry[] profileEntries = getInspectionTools(null);
203 for (InspectionProfileEntry entry : profileEntries) {
204 disableTool(entry.getShortName());
208 public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) {
209 final ToolsImpl tools = getTools(inspectionToolKey.toString());
210 HighlightDisplayLevel level = tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
211 if (!((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().isSeverityValid(level.getSeverity().toString())) {
212 level = HighlightDisplayLevel.WARNING;
213 setErrorLevel(inspectionToolKey, level);
215 return level;
219 public void readExternal(Element element) throws InvalidDataException {
220 super.readExternal(element);
221 final String locked = element.getAttributeValue(IS_LOCKED);
222 if (locked != null) {
223 myLockedProfile = Boolean.parseBoolean(locked);
225 myBaseProfile = getDefaultProfile();
226 final String version = element.getAttributeValue(VERSION_TAG);
227 if (version == null || !version.equals(VALID_VERSION)) {
228 try {
229 element = InspectionProfileConvertor.convertToNewFormat(element, this);
231 catch (IOException e) {
232 LOG.error(e);
234 catch (JDOMException e) {
235 LOG.error(e);
239 final Element highlightElement = element.getChild(USED_LEVELS);
240 if (highlightElement != null) { //from old profiles
241 ((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().readExternal(highlightElement);
244 for (final Object o : element.getChildren(INSPECTION_TOOL_TAG)) {
245 Element toolElement = (Element)o;
247 String toolClassName = toolElement.getAttributeValue(CLASS_TAG);
249 myDeinstalledInspectionsSettings.put(toolClassName, toolElement);
253 public Set<HighlightSeverity> getUsedSeverities() {
254 LOG.assertTrue(myInitialized.get());
255 final Set<HighlightSeverity> result = new HashSet<HighlightSeverity>();
256 for (ToolsImpl tools : myTools.values()) {
257 for (ScopeToolState state : tools.getTools()) {
258 result.add(state.getLevel().getSeverity());
261 return result;
265 public void writeExternal(Element element) throws WriteExternalException {
266 super.writeExternal(element);
267 element.setAttribute(VERSION_TAG, VALID_VERSION);
268 element.setAttribute(IS_LOCKED, String.valueOf(myLockedProfile));
270 if (!myInitialized.get()) {
271 for (Element el : myDeinstalledInspectionsSettings.values()) {
272 element.addContent((Element)el.clone());
274 return;
277 Map<String, Boolean> diffMap = getDisplayLevelMap();
278 if (diffMap != null) {
280 diffMap = new TreeMap<String, Boolean>(diffMap);
281 for (String toolName : myDeinstalledInspectionsSettings.keySet()) {
282 diffMap.put(toolName, false);
285 for (final String toolName : diffMap.keySet()) {
286 if (!myLockedProfile && diffMap.get(toolName).booleanValue()) continue;
287 final Element toolElement = myDeinstalledInspectionsSettings.get(toolName);
288 if (toolElement == null) {
289 final ToolsImpl toolList = myTools.get(toolName);
290 LOG.assertTrue(toolList != null);
291 final Element inspectionElement = new Element(INSPECTION_TOOL_TAG);
292 inspectionElement.setAttribute(CLASS_TAG, toolName);
293 toolList.writeExternal(inspectionElement);
294 element.addContent(inspectionElement);
296 else {
297 element.addContent((Element)toolElement.clone());
303 public InspectionProfileEntry getInspectionTool(@NotNull String shortName, @NotNull PsiElement element) {
304 final Tools toolList = getTools(shortName);
305 return toolList != null ? toolList.getInspectionTool(element) : null;
308 public InspectionProfileEntry getInspectionTool(@NotNull String shortName) {
309 return getTools(shortName).getTool();
312 public InspectionProfileEntry getToolById(String id, PsiElement element) {
313 initInspectionTools();
314 for (Tools toolList : myTools.values()) {
315 final InspectionProfileEntry tool = toolList.getInspectionTool(element);
316 String toolId =
317 tool instanceof LocalInspectionToolWrapper ? ((LocalInspectionToolWrapper)tool).getTool().getID() : tool.getShortName();
318 if (id.equals(toolId)) return tool;
320 return null;
323 public void save() throws IOException {
325 if (isLocal()) {
326 if (myName.compareTo("Default") == 0 && myElement == null){
327 myElement = new Element(ROOT_ELEMENT_TAG);
329 if (myElement != null) {
330 try {
331 myElement = new Element(ROOT_ELEMENT_TAG);
332 myElement.setAttribute(PROFILE_NAME_TAG, myName);
333 writeExternal(myElement);
334 myVisibleTreeState.writeExternal(myElement);
336 catch (WriteExternalException e) {
337 LOG.error(e);
342 InspectionProfileManager.getInstance().fireProfileChanged(this);
345 public boolean isEditable() {
346 return myEnabledTool == null;
349 @NotNull
350 public String getDisplayName() {
351 return isEditable() ? getName() : myEnabledTool;
354 public void setEditable(final String displayName) {
355 myEnabledTool = displayName;
358 public void load(Element element) {
359 try {
360 readExternal(element);
362 catch (Exception e) {
363 ApplicationManager.getApplication().invokeLater(new Runnable() {
364 public void run() {
365 Messages.showErrorDialog(InspectionsBundle.message("inspection.error.loading.message", 0, getName()),
366 InspectionsBundle.message("inspection.errors.occured.dialog.title"));
368 }, ModalityState.NON_MODAL);
372 public boolean isDefault() {
373 final Map<String, Boolean> map = getDisplayLevelMap();
374 if (map != null) {
375 for (Boolean def : map.values()) {
376 if (!def.booleanValue()) return false;
379 return true;
382 public boolean isProfileLocked() {
383 return myLockedProfile;
386 public void lockProfile(boolean isLocked) {
387 for (Tools toolList : myTools.values()) {
388 final String key = toolList.getShortName();
389 if (isLocked) {
390 myDisplayLevelMap.put(key, Boolean.FALSE);
393 myLockedProfile = isLocked;
396 @NotNull
397 public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
398 initInspectionTools();
399 ArrayList<InspectionProfileEntry> result = new ArrayList<InspectionProfileEntry>();
400 for (Tools toolList : myTools.values()) {
401 result.add(toolList.getInspectionTool(element));
403 return result.toArray(new InspectionTool[result.size()]);
406 public List<ToolsImpl> getAllEnabledInspectionTools() {
407 initInspectionTools();
408 final ArrayList<ToolsImpl> result = new ArrayList<ToolsImpl>();
409 for (final ToolsImpl toolList : myTools.values()) {
410 if (toolList.isEnabled()) {
411 result.add(toolList);
414 return result;
417 public void disableTool(String toolId, PsiElement element) {
418 getTools(toolId).disableTool(element);
421 public void disableToolByDefault(String toolId) {
422 getTools(toolId).getDefaultState().setEnabled(false);
425 public void enableToolByDefault(String toolId) {
426 getTools(toolId).getDefaultState().setEnabled(true);
429 public boolean wasInitialized() {
430 return myInitialized.get();
433 public void initInspectionTools() {
434 if (!ApplicationManager.getApplication().isUnitTestMode() || INIT_INSPECTIONS) {
435 synchronized (myInitialized) {
436 if (!myInitialized.getAndSet(true)) {
437 if (myBaseProfile != null) {
438 myBaseProfile.initInspectionTools();
441 final InspectionTool[] tools;
442 try {
443 tools = myRegistrar.createTools();
445 catch (ProcessCanceledException e) {
446 myInitialized.set(false);
447 return;
449 for (InspectionTool tool : tools) {
450 final String shortName = tool.getShortName();
451 HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
452 if (key == null) {
453 if (tool instanceof LocalInspectionToolWrapper) {
454 key = HighlightDisplayKey.register(shortName, tool.getDisplayName(), ((LocalInspectionToolWrapper)tool).getTool().getID(),
455 ((LocalInspectionToolWrapper)tool).getTool().getAlternativeID());
457 else {
458 key = HighlightDisplayKey.register(shortName);
462 LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
463 final ToolsImpl toolsList =
464 new ToolsImpl(tool, myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : tool.getDefaultLevel(),
465 !myLockedProfile && (myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : tool.isEnabledByDefault()));
466 final Element element = myDeinstalledInspectionsSettings.remove(tool.getShortName());
467 if (element != null) {
468 try {
469 toolsList.readExternal(element, this);
471 catch (InvalidDataException e) {
472 LOG.error(e);
475 myTools.put(tool.getShortName(), toolsList);
477 if (mySource != null) {
478 copyToolsConfigurations(mySource);
485 private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key) {
486 final ToolsImpl tools = getTools(key.toString());
487 LOG.assertTrue(tools != null, "profile name: " + myName + " base profile: " + (myBaseProfile != null ? myBaseProfile.getName() : "-") + " key: " + key);
488 return tools != null ? tools.getLevel() : HighlightDisplayLevel.WARNING;
491 @NotNull
492 public ModifiableModel getModifiableModel() {
493 InspectionProfileImpl modifiableModel = new InspectionProfileImpl(this);
494 modifiableModel.myExternalInfo.copy(myExternalInfo);
495 return modifiableModel;
498 public void copyFrom(InspectionProfile profile) {
499 super.copyFrom(profile);
500 final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)profile;
501 myBaseProfile = inspectionProfile.myBaseProfile;
504 public void copyToolsConfigurations(InspectionProfileImpl profile) {
505 try {
506 initInspectionTools();
507 for (ToolsImpl toolList : profile.myTools.values()) {
508 final ToolsImpl tools = myTools.get(toolList.getShortName());
509 final ScopeToolState defaultState = toolList.getDefaultState();
510 tools.setDefaultState(copyToolSettings((InspectionTool)defaultState.getTool()), defaultState.isEnabled(), defaultState.getLevel());
511 tools.removeAllScopes();
512 tools.setEnabled(toolList.isEnabled());
513 final List<ScopeToolState> nonDefaultToolStates = toolList.getNonDefaultTools();
514 if (nonDefaultToolStates != null) {
515 for (ScopeToolState state : nonDefaultToolStates) {
516 final InspectionTool inspectionTool = copyToolSettings((InspectionTool)state.getTool());
517 if (state.getScope() != null) {
518 tools.addTool(state.getScope(), inspectionTool, state.isEnabled(), state.getLevel());
519 } else {
520 tools.addTool(state.getScopeName(), inspectionTool, state.isEnabled(), state.getLevel());
526 catch (WriteExternalException e) {
527 LOG.error(e);
529 catch (InvalidDataException e) {
530 LOG.error(e);
536 private InspectionTool copyToolSettings(InspectionTool tool)
537 throws WriteExternalException, InvalidDataException {
538 @NonNls String tempRoot = "config";
539 Element config = new Element(tempRoot);
540 tool.writeSettings(config);
541 final InspectionTool inspectionTool = myRegistrar.createInspectionTool(tool.getShortName(), tool);
542 inspectionTool.readSettings(config);
543 return inspectionTool;
546 public void cleanup(Project project) {
547 for (final ToolsImpl toolList : myTools.values()) {
548 if (toolList.isEnabled()) {
549 for (InspectionProfileEntry tool : toolList.getAllTools()) {
550 tool.projectClosed(project);
551 if (((InspectionTool)tool).getContext() != null) {
552 ((InspectionTool)tool).cleanup();
559 public void enableTool(String inspectionTool) {
560 final ToolsImpl tools = getTools(inspectionTool);
561 tools.setEnabled(true);
562 if (tools.getNonDefaultTools() == null) {
563 tools.getDefaultState().setEnabled(true);
567 public void enableTool(String inspectionTool, NamedScope namedScope) {
568 getTools(inspectionTool).enableTool(namedScope);
571 public void disableTool(String inspectionTool, NamedScope namedScope) {
572 getTools(inspectionTool).disableTool(namedScope);
576 public void disableTool(String inspectionTool) {
577 final ToolsImpl tools = getTools(inspectionTool);
578 tools.setEnabled(false);
579 if (tools.getNonDefaultTools() == null) {
580 tools.getDefaultState().setEnabled(false);
584 public void setErrorLevel(HighlightDisplayKey key, HighlightDisplayLevel level) {
585 getTools(key.toString()).setLevel(level);
588 public boolean isToolEnabled(HighlightDisplayKey key, PsiElement element) {
589 if (key == null) {
590 return false;
592 final Tools toolState = getTools(key.toString());
593 return toolState != null && toolState.isEnabled(element);
596 public boolean isToolEnabled(HighlightDisplayKey key) {
597 final Tools toolState = getTools(key.toString());
598 return toolState != null && toolState.isEnabled();
601 public boolean isExecutable() {
602 initInspectionTools();
603 for (ToolsImpl tools : myTools.values()) {
604 if (tools.isEnabled()) return true;
606 return false;
609 //invoke when isChanged() == true
610 public void commit() throws IOException {
611 LOG.assertTrue(mySource != null);
612 mySource.commit(this);
613 getProfileManager().updateProfile(mySource);
614 mySource = null;
617 private void commit(InspectionProfileImpl inspectionProfile) {
618 myName = inspectionProfile.myName;
619 myLocal = inspectionProfile.myLocal;
620 myLockedProfile = inspectionProfile.myLockedProfile;
621 myDisplayLevelMap = inspectionProfile.myDisplayLevelMap;
622 myVisibleTreeState = inspectionProfile.myVisibleTreeState;
623 myBaseProfile = inspectionProfile.myBaseProfile;
624 myTools = inspectionProfile.myTools;
625 myProfileMananger = inspectionProfile.myProfileMananger;
627 myExternalInfo.copy(inspectionProfile.getExternalInfo());
629 InspectionProfileManager.getInstance().fireProfileChanged(inspectionProfile);
632 public static synchronized InspectionProfileImpl getDefaultProfile() {
633 if (DEFAULT_PROFILE == null) {
634 DEFAULT_PROFILE = new InspectionProfileImpl("Default");
636 return DEFAULT_PROFILE;
639 public Document saveToDocument() throws WriteExternalException {
640 if (isLocal()) {
641 Element root = new Element(ROOT_ELEMENT_TAG);
642 root.setAttribute(PROFILE_NAME_TAG, myName);
643 writeExternal(root);
644 //myVisibleTreeState.writeExternal(root);
645 return new Document(root);
647 else {
648 return null;
653 public VisibleTreeState getVisibleTreeState() {
654 return myVisibleTreeState;
657 public void setVisibleTreeState(final VisibleTreeState state) {
658 myVisibleTreeState = state;
661 public void convert(Element element) {
662 initInspectionTools();
663 final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
664 if (scopes != null) {
665 final List children = scopes.getChildren(SCOPE);
666 if (children != null) {
667 for (Object s : children) {
668 Element scopeElement = (Element)s;
669 final String profile = scopeElement.getAttributeValue(DefaultProjectProfileManager.PROFILE);
670 if (profile != null) {
671 final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)getProfileManager().getProfile(profile);
672 if (inspectionProfile != null) {
673 final NamedScope scope = getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME));
674 if (scope != null) {
675 for (InspectionProfileEntry entry : inspectionProfile.getInspectionTools(null)) {
676 final HighlightDisplayKey key = HighlightDisplayKey.find(entry.getShortName());
677 try {
678 getTools(entry.getShortName())
679 .addTool(scope, copyToolSettings((InspectionTool)entry), inspectionProfile.isToolEnabled(key), inspectionProfile.getErrorLevel(key, (NamedScope)null));
681 catch (Exception e) {
682 LOG.error(e);
689 reduceConvertedScopes();
694 private void reduceConvertedScopes() {
695 for (ToolsImpl tools : myTools.values()) {
696 final ScopeToolState toolState = tools.getDefaultState();
697 final List<ScopeToolState> nonDefaultTools = tools.getNonDefaultTools();
698 if (nonDefaultTools != null) {
699 boolean equal = true;
700 boolean isEnabled = toolState.isEnabled();
701 for (ScopeToolState state : nonDefaultTools) {
702 isEnabled |= state.isEnabled();
703 if (!state.equalTo(toolState)) {
704 equal = false;
707 tools.setEnabled(isEnabled);
708 if (equal) {
709 tools.removeAllScopes();
715 @NotNull
716 public ExternalInfo getExternalInfo() {
717 return myExternalInfo;
720 public List<ScopeToolState> getAllTools() {
721 initInspectionTools();
722 final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
723 for (Tools tools : myTools.values()) {
724 result.addAll(tools.getTools());
726 return result;
729 public List<ScopeToolState> getDefaultStates() {
730 initInspectionTools();
731 final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
732 for (Tools tools : myTools.values()) {
733 result.add(tools.getDefaultState());
735 return result;
738 public List<ScopeToolState> getNonDefaultTools(String shortName) {
739 final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
740 final List<ScopeToolState> nonDefaultTools = getTools(shortName).getNonDefaultTools();
741 if (nonDefaultTools != null) {
742 result.addAll(nonDefaultTools);
744 return result;
747 public boolean isToolEnabled(HighlightDisplayKey key, NamedScope namedScope) {
748 return getTools(key.toString()).isEnabled(namedScope);
751 public void removeScope(String toolId, int scopeIdx) {
752 getTools(toolId).removeScope(scopeIdx);
755 public void removeAllScopes(String toolId) {
756 getTools(toolId).removeAllScopes();
759 public void setScope(String toolId, int idx, NamedScope namedScope) {
760 getTools(toolId).setScope(idx, namedScope);
763 public void moveScope(String toolId, int idx, int dir) {
764 getTools(toolId).moveScope(idx, dir);
767 @Nullable
768 private Map<String, Boolean> getDisplayLevelMap() {
769 if (myBaseProfile == null) return null;
770 if (myDisplayLevelMap == null) {
771 initInspectionTools();
772 myDisplayLevelMap = new TreeMap<String, Boolean>();
773 for (String toolId : myTools.keySet()) {
774 myDisplayLevelMap.put(toolId, toolSettingsAreEqual(toolId, myBaseProfile, this));
777 return myDisplayLevelMap;
780 public HighlightDisplayLevel getErrorLevel(HighlightDisplayKey key, NamedScope scope) {
781 final ToolsImpl tools = getTools(key.toString());
782 return tools != null ? tools.getLevel(scope) : HighlightDisplayLevel.WARNING;
785 public ScopeToolState addScope(InspectionProfileEntry tool, NamedScope scope, HighlightDisplayLevel level, boolean enabled) {
786 return getTools(tool.getShortName()).prependTool(scope, tool, enabled, level);
790 public void setErrorLevel(HighlightDisplayKey key, HighlightDisplayLevel level, int scopeIdx) {
791 getTools(key.toString()).setLevel(level, scopeIdx);
794 private ToolsImpl getTools(String toolId) {
795 initInspectionTools();
796 return myTools.get(toolId);