コード例 #1
0
 public boolean isExecutable() {
   initInspectionTools();
   for (ToolsImpl tools : myTools.values()) {
     if (tools.isEnabled()) return true;
   }
   return false;
 }
コード例 #2
0
 public void disableTool(String inspectionTool) {
   final ToolsImpl tools = getTools(inspectionTool);
   tools.setEnabled(false);
   if (tools.getNonDefaultTools() == null) {
     tools.getDefaultState().setEnabled(false);
   }
 }
コード例 #3
0
  private static boolean toolSettingsAreEqual(
      String toolName, InspectionProfileImpl profile1, InspectionProfileImpl profile2) {
    final ToolsImpl toolList1 = profile1.myTools.get(toolName);
    final ToolsImpl toolList2 = profile2.myTools.get(toolName);

    return toolList1 == null && toolList2 == null
        || toolList1 != null && toolList2 != null && toolList1.equalTo(toolList2);
  }
コード例 #4
0
 public List<ToolsImpl> getAllEnabledInspectionTools() {
   initInspectionTools();
   final ArrayList<ToolsImpl> result = new ArrayList<ToolsImpl>();
   for (final ToolsImpl toolList : myTools.values()) {
     if (toolList.isEnabled()) {
       result.add(toolList);
     }
   }
   return result;
 }
コード例 #5
0
 public Set<HighlightSeverity> getUsedSeverities() {
   LOG.assertTrue(myInitialized);
   final Set<HighlightSeverity> result = new HashSet<HighlightSeverity>();
   for (ToolsImpl tools : myTools.values()) {
     for (ScopeToolState state : tools.getTools()) {
       result.add(state.getLevel().getSeverity());
     }
   }
   return result;
 }
コード例 #6
0
 public void cleanup(Project project) {
   for (final ToolsImpl toolList : myTools.values()) {
     if (toolList.isEnabled()) {
       for (InspectionProfileEntry tool : toolList.getAllTools()) {
         tool.projectClosed(project);
         if (((InspectionTool) tool).getContext() != null) {
           ((InspectionTool) tool).cleanup();
         }
       }
     }
   }
 }
コード例 #7
0
 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;
 }
コード例 #8
0
 public HighlightDisplayLevel getErrorLevel(
     @NotNull HighlightDisplayKey inspectionToolKey, PsiElement element) {
   final ToolsImpl tools = getTools(inspectionToolKey.toString());
   HighlightDisplayLevel level =
       tools != null ? tools.getLevel(element) : HighlightDisplayLevel.WARNING;
   if (!((SeverityProvider) getProfileManager())
       .getOwnSeverityRegistrar()
       .isSeverityValid(level.getSeverity().toString())) {
     level = HighlightDisplayLevel.WARNING;
     setErrorLevel(inspectionToolKey, level);
   }
   return level;
 }
コード例 #9
0
  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;
  }
コード例 #10
0
 @Override
 public boolean equals(Object o) {
   ToolsImpl tools = (ToolsImpl) o;
   if (myEnabled != tools.myEnabled) return false;
   if (getTools().size() != tools.getTools().size()) return false;
   for (int i = 0; i < getTools().size(); i++) {
     final ScopeToolState state = getTools().get(i);
     final ScopeToolState toolState = tools.getTools().get(i);
     if (!state.equalTo(toolState)) {
       return false;
     }
   }
   return true;
 }
コード例 #11
0
 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;
 }
コード例 #12
0
 private void reduceConvertedScopes() {
   for (ToolsImpl tools : myTools.values()) {
     final ScopeToolState toolState = tools.getDefaultState();
     final List<ScopeToolState> nonDefaultTools = tools.getNonDefaultTools();
     if (nonDefaultTools != null) {
       boolean equal = true;
       boolean isEnabled = toolState.isEnabled();
       for (ScopeToolState state : nonDefaultTools) {
         isEnabled |= state.isEnabled();
         if (!state.equalTo(toolState)) {
           equal = false;
         }
       }
       tools.setEnabled(isEnabled);
       if (equal) {
         tools.removeAllScopes();
       }
     }
   }
 }
コード例 #13
0
  public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    element.setAttribute(VERSION_TAG, VALID_VERSION);
    element.setAttribute(IS_LOCKED, String.valueOf(myLockedProfile));

    if (!myInitialized) {
      for (Element el : myDeinstalledInspectionsSettings.values()) {
        element.addContent((Element) el.clone());
      }
      return;
    }

    Map<String, Boolean> diffMap = getDisplayLevelMap();
    if (diffMap != null) {

      diffMap = new TreeMap<String, Boolean>(diffMap);
      for (String toolName : myDeinstalledInspectionsSettings.keySet()) {
        diffMap.put(toolName, false);
      }

      for (final String toolName : diffMap.keySet()) {
        if (!myLockedProfile && diffMap.get(toolName).booleanValue()) continue;
        final Element toolElement = myDeinstalledInspectionsSettings.get(toolName);
        if (toolElement == null) {
          final ToolsImpl toolList = myTools.get(toolName);
          LOG.assertTrue(toolList != null);
          final Element inspectionElement = new Element(INSPECTION_TOOL_TAG);
          inspectionElement.setAttribute(CLASS_TAG, toolName);
          toolList.writeExternal(inspectionElement);
          element.addContent(inspectionElement);
        } else {
          element.addContent((Element) toolElement.clone());
        }
      }
    }
  }
コード例 #14
0
 public HighlightDisplayLevel getErrorLevel(HighlightDisplayKey key, NamedScope scope) {
   final ToolsImpl tools = getTools(key.toString());
   return tools != null ? tools.getLevel(scope) : HighlightDisplayLevel.WARNING;
 }
コード例 #15
0
 private void copyToolsConfigurations(InspectionProfileImpl profile) {
   try {
     for (ToolsImpl toolList : profile.myTools.values()) {
       final ToolsImpl tools = myTools.get(toolList.getShortName());
       final ScopeToolState defaultState = toolList.getDefaultState();
       tools.setDefaultState(
           copyToolSettings((InspectionTool) 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 InspectionTool inspectionTool =
               copyToolSettings((InspectionTool) state.getTool());
           if (state.getScope() != null) {
             tools.addTool(state.getScope(), inspectionTool, state.isEnabled(), state.getLevel());
           } else {
             tools.addTool(
                 state.getScopeName(), inspectionTool, state.isEnabled(), state.getLevel());
           }
         }
       }
     }
   } catch (WriteExternalException e) {
     LOG.error(e);
   } catch (InvalidDataException e) {
     LOG.error(e);
   }
 }