Ejemplo n.º 1
0
 public void disableTool(@NotNull PsiElement element) {
   final Project project = element.getProject();
   final DependencyValidationManager validationManager =
       DependencyValidationManager.getInstance(project);
   if (myTools != null) {
     for (ScopeToolState state : myTools) {
       final NamedScope scope = state.getScope(project);
       if (scope != null) {
         final PackageSet packageSet = scope.getValue();
         if (packageSet != null) {
           final PsiFile file = element.getContainingFile();
           if (file != null) {
             if (packageSet.contains(file, validationManager)) {
               state.setEnabled(false);
               return;
             }
           } else {
             if (packageSet instanceof PackageSetBase
                 && ((PackageSetBase) packageSet)
                     .contains(PsiUtilCore.getVirtualFile(element), project, validationManager)) {
               state.setEnabled(false);
               return;
             }
           }
         }
       }
     }
     myDefaultState.setEnabled(false);
   } else {
     myDefaultState.setEnabled(false);
     setEnabled(false);
   }
 }
Ejemplo n.º 2
0
 public void setDefaultState(
     @NotNull InspectionToolWrapper toolWrapper,
     boolean enabled,
     @NotNull HighlightDisplayLevel level) {
   myDefaultState.setTool(toolWrapper);
   myDefaultState.setLevel(level);
   myDefaultState.setEnabled(enabled);
 }
Ejemplo n.º 3
0
 public void disableTool(NamedScope namedScope, Project project) {
   if (myTools != null) {
     for (ScopeToolState state : myTools) {
       if (Comparing.equal(state.getScope(project), namedScope)) {
         state.setEnabled(false);
       }
     }
   }
 }
Ejemplo n.º 4
0
  void readExternal(
      @NotNull Element toolElement,
      @NotNull InspectionProfile profile,
      Map<String, List<String>> dependencies)
      throws InvalidDataException {
    final String levelName = toolElement.getAttributeValue(LEVEL_ATTRIBUTE);
    final ProfileManager profileManager = profile.getProfileManager();
    final SeverityRegistrar registrar =
        ((SeverityProvider) profileManager).getOwnSeverityRegistrar();
    HighlightDisplayLevel level =
        levelName != null ? HighlightDisplayLevel.find(registrar.getSeverity(levelName)) : null;
    if (level == null) {
      level = HighlightDisplayLevel.WARNING;
    }
    myDefaultState.setLevel(level);
    final String enabled = toolElement.getAttributeValue(ENABLED_ATTRIBUTE);
    final boolean isEnabled = enabled != null && Boolean.parseBoolean(enabled);

    final String enabledTool = toolElement.getAttributeValue(ENABLED_BY_DEFAULT_ATTRIBUTE);
    myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled);
    final InspectionToolWrapper toolWrapper = myDefaultState.getTool();

    final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
    final List<String> scopeNames = new ArrayList<String>();
    for (Object sO : scopeElements) {
      final Element scopeElement = (Element) sO;
      final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
      if (scopeName == null) {
        continue;
      }
      final NamedScopesHolder scopesHolder = profileManager.getScopesManager();
      NamedScope namedScope = null;
      if (scopesHolder != null) {
        namedScope = scopesHolder.getScope(scopeName);
      }
      final String errorLevel = scopeElement.getAttributeValue(LEVEL_ATTRIBUTE);
      final String enabledInScope = scopeElement.getAttributeValue(ENABLED_ATTRIBUTE);
      final InspectionToolWrapper copyToolWrapper = toolWrapper.createCopy();
      // check if unknown children exists
      if (scopeElement.getAttributes().size() > 3 || !scopeElement.getChildren().isEmpty()) {
        copyToolWrapper.getTool().readSettings(scopeElement);
      }
      HighlightDisplayLevel scopeLevel =
          errorLevel != null ? HighlightDisplayLevel.find(registrar.getSeverity(errorLevel)) : null;
      if (scopeLevel == null) {
        scopeLevel = level;
      }
      if (namedScope != null) {
        addTool(
            namedScope,
            copyToolWrapper,
            enabledInScope != null && Boolean.parseBoolean(enabledInScope),
            scopeLevel);
      } else {
        addTool(
            scopeName,
            copyToolWrapper,
            enabledInScope != null && Boolean.parseBoolean(enabledInScope),
            scopeLevel);
      }

      scopeNames.add(scopeName);
    }

    for (int i = 0; i < scopeNames.size(); i++) {
      String scopeName = scopeNames.get(i);
      List<String> order = dependencies.get(scopeName);
      if (order == null) {
        order = new ArrayList<String>();
        dependencies.put(scopeName, order);
      }
      for (int j = i + 1; j < scopeNames.size(); j++) {
        order.add(scopeNames.get(j));
      }
    }

    // check if unknown children exists
    if (toolElement.getAttributes().size() > 4
        || toolElement.getChildren().size() > scopeElements.size()) {
      toolWrapper.getTool().readSettings(toolElement);
    }

    myEnabled = isEnabled;
  }