cleanup (inspection "Java | Class structure | Utility class is not 'final'")
[idea/community.git] / platform / analysis-impl / src / com / intellij / psi / search / scope / impl / CustomScopesAggregator.java
1 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.psi.search.scope.impl;
3
4 import com.intellij.diagnostic.PluginException;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.psi.search.scope.packageSet.CustomScopesProvider;
7 import com.intellij.psi.search.scope.packageSet.NamedScope;
8 import org.jetbrains.annotations.NotNull;
9
10 import java.util.ArrayList;
11 import java.util.LinkedHashSet;
12 import java.util.List;
13 import java.util.Set;
14
15 public final class CustomScopesAggregator {
16   @NotNull
17   public static List<NamedScope> getAllCustomScopes(@NotNull Project project) {
18     Set<NamedScope> allScopes = new LinkedHashSet<>();
19     for (CustomScopesProvider scopesProvider : CustomScopesProvider.CUSTOM_SCOPES_PROVIDER.getExtensions(project)) {
20       List<NamedScope> customScopes = scopesProvider.getFilteredScopes();
21       if (customScopes.contains(null)) {
22         throw PluginException.createByClass("CustomScopesProvider::getFilteredScopes() must not return null scopes, got: " + customScopes + "; provider: " + scopesProvider + " (" + scopesProvider.getClass() + ")", null, scopesProvider.getClass());
23       }
24       allScopes.addAll(customScopes);
25     }
26     return new ArrayList<>(allScopes);
27   }
28 }