From 8f1b015e5dce8d6fa6f98757ca7901add2b37d16 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 20 Mar 2018 20:23:01 +0300 Subject: [PATCH] [core] extract #getAllBaseLanguageIdsWithAny into CompletionExtension --- .../com/intellij/lang/LanguageExtension.java | 37 +++--------------- .../completion/CompletionConfidenceEP.java | 24 +----------- .../completion/CompletionContributor.java | 13 +------ .../completion/CompletionExtension.java | 38 +++++++++++++++++++ 4 files changed, 47 insertions(+), 65 deletions(-) create mode 100644 platform/lang-api/src/com/intellij/codeInsight/completion/CompletionExtension.java diff --git a/platform/core-api/src/com/intellij/lang/LanguageExtension.java b/platform/core-api/src/com/intellij/lang/LanguageExtension.java index a1c70265b47e..e5ebd9c7c74e 100644 --- a/platform/core-api/src/com/intellij/lang/LanguageExtension.java +++ b/platform/core-api/src/com/intellij/lang/LanguageExtension.java @@ -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 extends KeyedExtensionCollector { private final T myDefaultImplementation; @@ -123,19 +111,4 @@ public class LanguageExtension extends KeyedExtensionCollector { protected Key getLanguageCache() { return IN_LANGUAGE_CACHE; } - - @NotNull - protected Set getAllBaseLanguageIdsWithAny(@NotNull Language key) { - Set 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; - } - } diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidenceEP.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidenceEP.java index 6a9111c2f10f..d1d563d3eca1 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidenceEP.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionConfidenceEP.java @@ -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 { - private static final LanguageExtension INSTANCE = new LanguageExtension("com.intellij.completion.confidence") { - @NotNull - @Override - protected List buildExtensions(@NotNull String stringKey, @NotNull Language key) { - return buildExtensions(getAllBaseLanguageIdsWithAny(key)); - } - }; + private static final LanguageExtension INSTANCE = new CompletionExtension<>("com.intellij.completion.confidence"); public static List forLanguage(@NotNull Language language) { return INSTANCE.allForLanguage(language); diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java index 70bcdb30b948..f3f333a4f4e0 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java @@ -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 INSTANCE = new LanguageExtension("com.intellij.completion.contributor") { - @NotNull - @Override - protected List buildExtensions(@NotNull String stringKey, @NotNull Language key) { - return buildExtensions(getAllBaseLanguageIdsWithAny(key)); - } - }; - + private static final LanguageExtension INSTANCE = new CompletionExtension<>("com.intellij.completion.contributor"); } diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionExtension.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionExtension.java new file mode 100644 index 000000000000..39beeb75d0d3 --- /dev/null +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionExtension.java @@ -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 extends LanguageExtension { + + CompletionExtension(String epName) { + super(epName); + } + + @NotNull + @Override + protected List buildExtensions(@NotNull String stringKey, @NotNull Language key) { + return buildExtensions(getAllBaseLanguageIdsWithAny(key)); + } + + @NotNull + private Set getAllBaseLanguageIdsWithAny(@NotNull Language key) { + Set 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; + } +}