cleanup (inspection "Java | Class structure | Utility class is not 'final'")
[idea/community.git] / platform / platform-impl / src / com / intellij / remote / CredentialsTypeUtil.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.remote;
3
4 import com.intellij.remote.ext.CredentialsLanguageContribution;
5 import com.intellij.remote.ext.CredentialsManager;
6 import com.intellij.remote.ui.CredentialsEditorProvider;
7 import com.intellij.util.ObjectUtils;
8 import com.intellij.util.containers.ContainerUtil;
9 import com.intellij.util.containers.FilteringIterator;
10 import org.jetbrains.annotations.NotNull;
11
12 import java.util.List;
13
14 public final class CredentialsTypeUtil {
15   private CredentialsTypeUtil() {
16   }
17
18   public static boolean isCredentialsTypeSupportedForLanguage(@NotNull CredentialsType<?> credentialsType,
19                                                               @NotNull Class<?> languageContributionMarkerClass) {
20     // TODO add language contributors for Python and Node JS
21     for (CredentialsType<?> type : CredentialsManager.getInstance().getAllTypes()) {
22       if (credentialsType.equals(type)) {
23         CredentialsEditorProvider editorProvider = ObjectUtils.tryCast(type, CredentialsEditorProvider.class);
24         if (editorProvider != null) {
25           List<CredentialsLanguageContribution> contributions = getContributions(languageContributionMarkerClass);
26           if (!contributions.isEmpty()) {
27             for (CredentialsLanguageContribution contribution : contributions) {
28               if (contribution.getType() == type && editorProvider.isAvailable(contribution)) {
29                 return true;
30               }
31             }
32           }
33         }
34       }
35     }
36     return false;
37   }
38
39   @NotNull
40   public static <T> List<CredentialsLanguageContribution> getContributions(@NotNull Class<T> languageContributionMarkerInterface) {
41     return ContainerUtil.filter(CredentialsLanguageContribution.EP_NAME.getExtensions(),
42                                 FilteringIterator.instanceOf(languageContributionMarkerInterface));
43   }
44 }