Пример #1
0
 public void setLevel(
     @NotNull HighlightDisplayLevel level, @Nullable String scopeName, Project project) {
   if (scopeName == null) {
     myDefaultState.setLevel(level);
   } else {
     if (myTools == null) {
       return;
     }
     ScopeToolState scopeToolState = null;
     int index = -1;
     for (int i = 0; i < myTools.size(); i++) {
       ScopeToolState tool = myTools.get(i);
       if (scopeName.equals(tool.getScopeName())) {
         scopeToolState = tool;
         myTools.remove(tool);
         index = i;
         break;
       }
     }
     if (index < 0) {
       throw new IllegalStateException("Scope " + scopeName + " not found");
     }
     final InspectionToolWrapper toolWrapper = scopeToolState.getTool();
     final NamedScope scope = scopeToolState.getScope(project);
     if (scope != null) {
       myTools.add(
           index, new ScopeToolState(scope, toolWrapper, scopeToolState.isEnabled(), level));
     } else {
       myTools.add(
           index,
           new ScopeToolState(
               scopeToolState.getScopeName(), toolWrapper, scopeToolState.isEnabled(), level));
     }
   }
 }
 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);
   }
 }
Пример #3
0
 @Nullable
 @Override
 public InspectionToolWrapper getEnabledTool(
     @Nullable PsiElement element, boolean includeDoNotShow) {
   if (!myEnabled) return null;
   if (myTools != null && element != null) {
     final Project project = element.getProject();
     final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
     for (ScopeToolState state : myTools) {
       final NamedScope scope = state.getScope(project);
       if (scope != null) {
         final PackageSet set = scope.getValue();
         if (set != null && set.contains(element.getContainingFile(), manager)) {
           return state.isEnabled()
                   && (includeDoNotShow
                       || !HighlightDisplayLevel.DO_NOT_SHOW.equals(state.getLevel()))
               ? state.getTool()
               : null;
         }
       }
     }
   }
   return myDefaultState.isEnabled()
           && (includeDoNotShow
               || !HighlightDisplayLevel.DO_NOT_SHOW.equals(myDefaultState.getLevel()))
       ? myDefaultState.getTool()
       : null;
 }
Пример #4
0
 public boolean isEnabled(NamedScope namedScope, Project project) {
   if (!myEnabled) return false;
   if (namedScope != null && myTools != null) {
     for (ScopeToolState state : myTools) {
       if (Comparing.equal(namedScope, state.getScope(project))) return state.isEnabled();
     }
   }
   return myDefaultState.isEnabled();
 }
Пример #5
0
 @Override
 public boolean isEnabled(PsiElement element) {
   if (!myEnabled) return false;
   if (myTools == null || element == null) return myDefaultState.isEnabled();
   final Project project = element.getProject();
   final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
   for (ScopeToolState state : myTools) {
     final NamedScope scope = state.getScope(project);
     if (scope != null) {
       final PackageSet set = scope.getValue();
       if (set != null && set.contains(element.getContainingFile(), manager)) {
         return state.isEnabled();
       }
     }
   }
   return myDefaultState.isEnabled();
 }
Пример #6
0
 public void setScope(int idx, NamedScope namedScope) {
   if (myTools != null && myTools.size() > idx && idx >= 0) {
     final ScopeToolState scopeToolState = myTools.get(idx);
     InspectionToolWrapper toolWrapper = scopeToolState.getTool();
     myTools.remove(idx);
     myTools.add(
         idx,
         new ScopeToolState(
             namedScope, toolWrapper, scopeToolState.isEnabled(), scopeToolState.getLevel()));
   }
 }
Пример #7
0
 @NotNull
 private ScopeToolState insertTool(@NotNull final ScopeToolState scopeToolState, final int idx) {
   if (myTools == null) {
     myTools = new ArrayList<ScopeToolState>();
     if (scopeToolState.isEnabled()) {
       setEnabled(true);
     }
   }
   myTools.add(idx, scopeToolState);
   return scopeToolState;
 }
 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();
       }
     }
   }
 }
Пример #9
0
 public void writeExternal(@NotNull Element inspectionElement) throws WriteExternalException {
   if (myTools != null) {
     for (ScopeToolState state : myTools) {
       final Element scopeElement = new Element("scope");
       scopeElement.setAttribute("name", state.getScopeName());
       scopeElement.setAttribute(LEVEL_ATTRIBUTE, state.getLevel().getName());
       scopeElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(state.isEnabled()));
       InspectionToolWrapper toolWrapper = state.getTool();
       if (toolWrapper.isInitialized()) {
         toolWrapper.getTool().writeSettings(scopeElement);
       }
       inspectionElement.addContent(scopeElement);
     }
   }
   inspectionElement.setAttribute(ENABLED_ATTRIBUTE, Boolean.toString(isEnabled()));
   inspectionElement.setAttribute(LEVEL_ATTRIBUTE, getLevel().getName());
   inspectionElement.setAttribute(
       ENABLED_BY_DEFAULT_ATTRIBUTE, Boolean.toString(myDefaultState.isEnabled()));
   InspectionToolWrapper toolWrapper = myDefaultState.getTool();
   if (toolWrapper.isInitialized()) {
     toolWrapper.getTool().writeSettings(inspectionElement);
   }
 }
Пример #10
0
 private void checkToolsIsEmpty() {
   if (myTools.isEmpty()) {
     myTools = null;
     setEnabled(myDefaultState.isEnabled());
   }
 }