private List<String> getAvailableScopes(Project project, List<Descriptor> descriptors) {
    final ArrayList<NamedScope> scopes = new ArrayList<NamedScope>();
    for (NamedScopesHolder holder : NamedScopesHolder.getAllNamedScopeHolders(project)) {
      Collections.addAll(scopes, holder.getScopes());
    }
    scopes.remove(DefaultScopesProvider.getAllScope());

    CustomScopesProviderEx.filterNoSettingsScopes(project, scopes);

    final Set<NamedScope> used = new HashSet<NamedScope>();
    for (Descriptor descriptor : descriptors) {
      final List<ScopeToolState> nonDefaultTools =
          getSelectedProfile().getNonDefaultTools(descriptor.getKey().toString());
      if (nonDefaultTools != null) {
        for (ScopeToolState state : nonDefaultTools) {
          used.add(state.getScope(project));
        }
      }
    }
    scopes.removeAll(used);

    final List<String> availableScopes = new ArrayList<String>();
    for (NamedScope scope : scopes) {
      availableScopes.add(scope.getName());
    }
    return availableScopes;
  }
 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);
   }
 }
 @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;
 }
 @NotNull
 @Override
 public InspectionToolWrapper getInspectionTool(PsiElement element) {
   if (myTools != null) {
     final PsiFile containingFile = element == null ? null : element.getContainingFile();
     final Project project = containingFile == null ? null : containingFile.getProject();
     for (ScopeToolState state : myTools) {
       if (element == null) {
         return state.getTool();
       }
       NamedScope scope = state.getScope(project);
       if (scope != null) {
         final PackageSet packageSet = scope.getValue();
         if (packageSet != null) {
           if (containingFile != null
               && packageSet.contains(
                   containingFile, DependencyValidationManager.getInstance(project))) {
             return state.getTool();
           }
         }
       }
     }
   }
   return myDefaultState.getTool();
 }
  private static void initScopesDescriptors(
      @NotNull List<EditorSchemeAttributeDescriptor> descriptions, @NotNull MyColorScheme scheme) {
    Set<Pair<NamedScope, NamedScopesHolder>> namedScopes =
        new THashSet<Pair<NamedScope, NamedScopesHolder>>(
            new TObjectHashingStrategy<Pair<NamedScope, NamedScopesHolder>>() {
              @Override
              public int computeHashCode(
                  @NotNull final Pair<NamedScope, NamedScopesHolder> object) {
                return object.getFirst().getName().hashCode();
              }

              @Override
              public boolean equals(
                  @NotNull final Pair<NamedScope, NamedScopesHolder> o1,
                  @NotNull final Pair<NamedScope, NamedScopesHolder> o2) {
                return o1.getFirst().getName().equals(o2.getFirst().getName());
              }
            });
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
      DependencyValidationManagerImpl validationManager =
          (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(project);
      List<Pair<NamedScope, NamedScopesHolder>> cachedScopes =
          validationManager.getScopeBasedHighlightingCachedScopes();
      namedScopes.addAll(cachedScopes);
    }

    List<Pair<NamedScope, NamedScopesHolder>> list =
        new ArrayList<Pair<NamedScope, NamedScopesHolder>>(namedScopes);

    Collections.sort(
        list,
        new Comparator<Pair<NamedScope, NamedScopesHolder>>() {
          @Override
          public int compare(
              @NotNull final Pair<NamedScope, NamedScopesHolder> o1,
              @NotNull final Pair<NamedScope, NamedScopesHolder> o2) {
            return o1.getFirst().getName().compareToIgnoreCase(o2.getFirst().getName());
          }
        });
    for (Pair<NamedScope, NamedScopesHolder> pair : list) {
      NamedScope namedScope = pair.getFirst();
      String name = namedScope.getName();
      TextAttributesKey textAttributesKey = ScopeAttributesUtil.getScopeTextAttributeKey(name);
      if (scheme.getAttributes(textAttributesKey) == null) {
        scheme.setAttributes(textAttributesKey, new TextAttributes());
      }
      NamedScopesHolder holder = pair.getSecond();

      PackageSet value = namedScope.getValue();
      String toolTip = holder.getDisplayName() + (value == null ? "" : ": " + value.getText());
      addSchemedDescription(
          descriptions, name, SCOPES_GROUP, textAttributesKey, scheme, holder.getIcon(), toolTip);
    }
  }
 public HighlightDisplayLevel getLevel(PsiElement element) {
   if (myTools == null || element == null) return myDefaultState.getLevel();
   final Project project = element.getProject();
   final DependencyValidationManager manager = DependencyValidationManager.getInstance(project);
   for (ScopeToolState state : myTools) {
     final NamedScope scope = state.getScope(project);
     final PackageSet set = scope != null ? scope.getValue() : null;
     if (set != null && set.contains(element.getContainingFile(), manager)) {
       return state.getLevel();
     }
   }
   return myDefaultState.getLevel();
 }
    private Collection<String> getValidScopeNames() {
      List<String> result = new ArrayList<String>();
      result.add(SCOPE_PROJECT);
      result.add(SCOPE_TEST);
      result.add(SCOPE_ALL);
      result.add(SCOPE_CLASS);

      final NamedScopesHolder[] holders = NamedScopesHolder.getAllNamedScopeHolders(myProject);
      for (NamedScopesHolder holder : holders) {
        NamedScope[] scopes = holder.getEditableScopes(); // predefined scopes already included
        for (NamedScope scope : scopes) {
          result.add(scope.getName());
        }
      }
      return result;
    }
 @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();
 }