From d2bc00755442386e53e296464e2adb3478d18fc8 Mon Sep 17 00:00:00 2001 From: Anton Lobov Date: Wed, 29 May 2019 13:58:41 +0200 Subject: [PATCH] json schema icon provider: compute only for files that can be schema files (json/yaml), not for the others GitOrigin-RevId: e4fbad64a029527d6c9b2da415dc186a565adaa7 --- .../jsonSchema/JsonSchemaIconProvider.java | 27 +++++++------------ .../extension/JsonSchemaEnabler.java | 4 +++ .../impl/JsonSchemaInJsonFilesEnabler.java | 5 ++++ .../yaml/schema/YamlJsonEnabler.java | 5 ++++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/json/src/com/jetbrains/jsonSchema/JsonSchemaIconProvider.java b/json/src/com/jetbrains/jsonSchema/JsonSchemaIconProvider.java index 78014791b25b..983cc5f5de66 100644 --- a/json/src/com/jetbrains/jsonSchema/JsonSchemaIconProvider.java +++ b/json/src/com/jetbrains/jsonSchema/JsonSchemaIconProvider.java @@ -1,24 +1,12 @@ -/* - * 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-2019 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.jetbrains.jsonSchema; import com.intellij.icons.AllIcons; import com.intellij.ide.IconProvider; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.jetbrains.jsonSchema.extension.JsonSchemaEnabler; import com.jetbrains.jsonSchema.ide.JsonSchemaService; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,8 +20,13 @@ public class JsonSchemaIconProvider extends IconProvider { @Nullable @Override public Icon getIcon(@NotNull PsiElement element, int flags) { - if (element instanceof PsiFile && JsonSchemaService.isSchemaFile((PsiFile)element)) { - return AllIcons.FileTypes.JsonSchema; + if (element instanceof PsiFile) { + VirtualFile virtualFile = ((PsiFile)element).getVirtualFile(); + if (virtualFile != null + && JsonSchemaEnabler.EXTENSION_POINT_NAME.getExtensionList().stream().anyMatch(e -> e.canBeSchemaFile(virtualFile)) + && JsonSchemaService.isSchemaFile((PsiFile)element)) { + return AllIcons.FileTypes.JsonSchema; + } } return null; } diff --git a/json/src/com/jetbrains/jsonSchema/extension/JsonSchemaEnabler.java b/json/src/com/jetbrains/jsonSchema/extension/JsonSchemaEnabler.java index f0926b2e5a75..6eb666a2b9b3 100644 --- a/json/src/com/jetbrains/jsonSchema/extension/JsonSchemaEnabler.java +++ b/json/src/com/jetbrains/jsonSchema/extension/JsonSchemaEnabler.java @@ -28,4 +28,8 @@ public interface JsonSchemaEnabler { default boolean shouldShowSwitcherWidget(VirtualFile file) { return true; } + + default boolean canBeSchemaFile(VirtualFile file) { + return false; + } } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaInJsonFilesEnabler.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaInJsonFilesEnabler.java index 998542b60e95..e3c3e8f0b705 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaInJsonFilesEnabler.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaInJsonFilesEnabler.java @@ -10,4 +10,9 @@ public class JsonSchemaInJsonFilesEnabler implements JsonSchemaEnabler { public boolean isEnabledForFile(VirtualFile file) { return JsonUtil.isJsonFile(file); } + + @Override + public boolean canBeSchemaFile(VirtualFile file) { + return isEnabledForFile(file); + } } diff --git a/plugins/yaml/src/org/jetbrains/yaml/schema/YamlJsonEnabler.java b/plugins/yaml/src/org/jetbrains/yaml/schema/YamlJsonEnabler.java index 0e8b3393d140..f8dbeb71fc26 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/schema/YamlJsonEnabler.java +++ b/plugins/yaml/src/org/jetbrains/yaml/schema/YamlJsonEnabler.java @@ -13,4 +13,9 @@ public class YamlJsonEnabler implements JsonSchemaEnabler { FileType type = file.getFileType(); return type instanceof LanguageFileType && ((LanguageFileType)type).getLanguage() instanceof YAMLLanguage; } + + @Override + public boolean canBeSchemaFile(VirtualFile file) { + return isEnabledForFile(file); + } }