[core] extract #getAllBaseLanguageIdsWithAny into CompletionExtension

This commit is contained in:
Daniil Ovchinnikov
2018-03-22 21:38:33 +03:00
parent a2ab5482a2
commit 8f1b015e5d
4 changed files with 47 additions and 65 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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.
/*
* @author max
@@ -22,12 +8,14 @@ package com.intellij.lang;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.KeyedExtensionCollector;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public class LanguageExtension<T> extends KeyedExtensionCollector<T, Language> {
private final T myDefaultImplementation;
@@ -123,19 +111,4 @@ public class LanguageExtension<T> extends KeyedExtensionCollector<T, Language> {
protected Key<T> getLanguageCache() {
return IN_LANGUAGE_CACHE;
}
@NotNull
protected Set<String> getAllBaseLanguageIdsWithAny(@NotNull Language key) {
Set<String> allowed = new THashSet<>();
while (key != null) {
allowed.add(keyToString(key));
key = key.getBaseLanguage();
}
allowed.add("any");
for (MetaLanguage metaLanguage : MetaLanguage.all()) {
allowed.add(metaLanguage.getID());
}
return allowed;
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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.
package com.intellij.codeInsight.completion;
import com.intellij.lang.Language;
@@ -26,13 +12,7 @@ import java.util.List;
* @author peter
*/
public class CompletionConfidenceEP extends LanguageExtensionPoint<CompletionConfidence> {
private static final LanguageExtension<CompletionConfidence> INSTANCE = new LanguageExtension<CompletionConfidence>("com.intellij.completion.confidence") {
@NotNull
@Override
protected List<CompletionConfidence> buildExtensions(@NotNull String stringKey, @NotNull Language key) {
return buildExtensions(getAllBaseLanguageIdsWithAny(key));
}
};
private static final LanguageExtension<CompletionConfidence> INSTANCE = new CompletionExtension<>("com.intellij.completion.confidence");
public static List<CompletionConfidence> forLanguage(@NotNull Language language) {
return INSTANCE.allForLanguage(language);
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2018 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.
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
@@ -236,12 +234,5 @@ public abstract class CompletionContributor {
return DumbService.getInstance(project).filterByDumbAwareness(forLanguage(language));
}
private static final LanguageExtension<CompletionContributor> INSTANCE = new LanguageExtension<CompletionContributor>("com.intellij.completion.contributor") {
@NotNull
@Override
protected List<CompletionContributor> buildExtensions(@NotNull String stringKey, @NotNull Language key) {
return buildExtensions(getAllBaseLanguageIdsWithAny(key));
}
};
private static final LanguageExtension<CompletionContributor> INSTANCE = new CompletionExtension<>("com.intellij.completion.contributor");
}
@@ -0,0 +1,38 @@
// Copyright 2000-2018 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.
package com.intellij.codeInsight.completion;
import com.intellij.lang.Language;
import com.intellij.lang.LanguageExtension;
import com.intellij.lang.MetaLanguage;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Set;
class CompletionExtension<T> extends LanguageExtension<T> {
CompletionExtension(String epName) {
super(epName);
}
@NotNull
@Override
protected List<T> buildExtensions(@NotNull String stringKey, @NotNull Language key) {
return buildExtensions(getAllBaseLanguageIdsWithAny(key));
}
@NotNull
private Set<String> getAllBaseLanguageIdsWithAny(@NotNull Language key) {
Set<String> allowed = new THashSet<>();
while (key != null) {
allowed.add(keyToString(key));
key = key.getBaseLanguage();
}
allowed.add("any");
for (MetaLanguage metaLanguage : MetaLanguage.all()) {
allowed.add(metaLanguage.getID());
}
return allowed;
}
}