private boolean initialize() {
    if (myBaseProfile != null) {
      myBaseProfile.initInspectionTools();
    }

    final List<InspectionTool> tools;
    try {
      tools = myRegistrar.createTools();
    } catch (ProcessCanceledException e) {
      return false;
    }
    for (InspectionTool tool : tools) {
      final String shortName = tool.getShortName();
      HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
      if (key == null) {
        if (tool instanceof LocalInspectionToolWrapper) {
          key =
              HighlightDisplayKey.register(
                  shortName,
                  tool.getDisplayName(),
                  ((LocalInspectionToolWrapper) tool).getID(),
                  ((LocalInspectionToolWrapper) tool).getAlternativeID());
        } else {
          key = HighlightDisplayKey.register(shortName, tool.getDisplayName());
        }
      }

      LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
      final ToolsImpl toolsList =
          new ToolsImpl(
              tool,
              myBaseProfile != null ? myBaseProfile.getErrorLevel(key) : tool.getDefaultLevel(),
              !myLockedProfile
                  && (myBaseProfile != null
                      ? myBaseProfile.isToolEnabled(key)
                      : tool.isEnabledByDefault()));
      final Element element = myDeinstalledInspectionsSettings.remove(tool.getShortName());
      if (element != null) {
        try {
          toolsList.readExternal(element, this);
        } catch (InvalidDataException e) {
          LOG.error(e);
        }
      }
      myTools.put(tool.getShortName(), toolsList);
    }
    if (mySource != null) {
      copyToolsConfigurations(mySource);
    }
    return true;
  }
  public InspectionProfileImpl(InspectionProfileImpl inspectionProfile) {
    super(inspectionProfile.getName());

    myRegistrar = inspectionProfile.myRegistrar;
    myTools = new HashMap<String, ToolsImpl>();
    myDeinstalledInspectionsSettings =
        new LinkedHashMap<String, Element>(inspectionProfile.myDeinstalledInspectionsSettings);

    myBaseProfile = inspectionProfile.myBaseProfile;
    myLocal = inspectionProfile.myLocal;
    myLockedProfile = inspectionProfile.myLockedProfile;
    mySource = inspectionProfile;
    setProfileManager(inspectionProfile.getProfileManager());
    copyFrom(inspectionProfile);
    initInspectionTools();
  }
 private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key) {
   final ToolsImpl tools = getTools(key.toString());
   LOG.assertTrue(
       tools != null,
       "profile name: "
           + myName
           + " base profile: "
           + (myBaseProfile != null ? myBaseProfile.getName() : "-")
           + " key: "
           + key);
   return tools != null ? tools.getLevel() : HighlightDisplayLevel.WARNING;
 }
 public void convert(Element element) {
   initInspectionTools();
   final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
   if (scopes != null) {
     final List children = scopes.getChildren(SCOPE);
     if (children != null) {
       for (Object s : children) {
         Element scopeElement = (Element) s;
         final String profile =
             scopeElement.getAttributeValue(DefaultProjectProfileManager.PROFILE);
         if (profile != null) {
           final InspectionProfileImpl inspectionProfile =
               (InspectionProfileImpl) getProfileManager().getProfile(profile);
           if (inspectionProfile != null) {
             final NamedScope scope =
                 getProfileManager()
                     .getScopesManager()
                     .getScope(scopeElement.getAttributeValue(NAME));
             if (scope != null) {
               for (InspectionProfileEntry entry : inspectionProfile.getInspectionTools(null)) {
                 final HighlightDisplayKey key = HighlightDisplayKey.find(entry.getShortName());
                 try {
                   getTools(entry.getShortName())
                       .addTool(
                           scope,
                           copyToolSettings((InspectionTool) entry),
                           inspectionProfile.isToolEnabled(key),
                           inspectionProfile.getErrorLevel(key, (NamedScope) null));
                 } catch (Exception e) {
                   LOG.error(e);
                 }
               }
             }
           }
         }
       }
       reduceConvertedScopes();
     }
   }
 }
  private void commit(InspectionProfileImpl inspectionProfile) {
    myName = inspectionProfile.myName;
    myLocal = inspectionProfile.myLocal;
    myLockedProfile = inspectionProfile.myLockedProfile;
    myDisplayLevelMap = inspectionProfile.myDisplayLevelMap;
    myBaseProfile = inspectionProfile.myBaseProfile;
    myTools = inspectionProfile.myTools;
    myProfileManager = inspectionProfile.myProfileManager;

    myExternalInfo.copy(inspectionProfile.getExternalInfo());

    InspectionProfileManager.getInstance().fireProfileChanged(inspectionProfile);
  }
 public boolean isProperSetting(HighlightDisplayKey key) {
   final Map<String, Boolean> diffMap = getDisplayLevelMap();
   if (diffMap != null) {
     final ToolsImpl tools = myBaseProfile.getTools(key.toString());
     final ToolsImpl currentTools = myTools.get(key.toString());
     if (tools != null && currentTools != null) {
       diffMap.put(key.toString(), tools.equalTo(currentTools));
     } else {
       diffMap.put(key.toString(), tools == currentTools);
     }
     return !diffMap.get(key.toString()).booleanValue();
   }
   return false;
 }
 // invoke when isChanged() == true
 public void commit() throws IOException {
   LOG.assertTrue(mySource != null);
   mySource.commit(this);
   getProfileManager().updateProfile(mySource);
   mySource = null;
 }
 public String getBaseProfileName() {
   if (myBaseProfile == null) return null;
   return myBaseProfile.getName();
 }