From 56a956a1f0bf7ff209f45ed039aeba142372a491 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 23 Jul 2019 19:15:23 +0200 Subject: [PATCH] Add consistency checks for file type registration, fix found inconsistencies (IDEA-CR-50521) GitOrigin-RevId: 6d7e927a3d55a34e74b5121b3bd3ef3ccc582bc8 --- json/src/com/intellij/json/JsonFileType.java | 4 ++++ .../intellij/openapi/fileTypes/LanguageFileType.java | 4 ++++ .../openapi/fileTypes/impl/FileTypeManagerImpl.java | 12 ++++++++++++ .../platform-resources/src/META-INF/JsonPlugin.xml | 4 ++-- .../src/META-INF/PlatformExtensions.xml | 2 +- plugins/markdown/resource/META-INF/plugin.xml | 2 +- .../idea/maven/config/MavenConfigFileType.kt | 2 +- 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/json/src/com/intellij/json/JsonFileType.java b/json/src/com/intellij/json/JsonFileType.java index 9b8918002c3c..f6809ae363aa 100644 --- a/json/src/com/intellij/json/JsonFileType.java +++ b/json/src/com/intellij/json/JsonFileType.java @@ -19,6 +19,10 @@ public class JsonFileType extends LanguageFileType{ super(language); } + protected JsonFileType(Language language, boolean secondary) { + super(language, secondary); + } + public JsonFileType() { super(JsonLanguage.INSTANCE); } diff --git a/platform/core-api/src/com/intellij/openapi/fileTypes/LanguageFileType.java b/platform/core-api/src/com/intellij/openapi/fileTypes/LanguageFileType.java index 3e46199afe77..8256b04c1f99 100644 --- a/platform/core-api/src/com/intellij/openapi/fileTypes/LanguageFileType.java +++ b/platform/core-api/src/com/intellij/openapi/fileTypes/LanguageFileType.java @@ -69,6 +69,10 @@ public abstract class LanguageFileType implements FileType{ return false; } + /** + * If true, this language file type will never be returned as the associated file type for the language. + * (Used when a file type is reusing the language of another file type, e.g. XML). + */ public boolean isSecondary() { return mySecondary; } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index 3b775dce151f..de4d227ae6be 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -454,6 +454,18 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent LOG.error(e); return null; } + + if (!fileType.getName().equals(fileTypeBean.name)) { + LOG.error("Incorrect name specified in , should be " + fileType.getName() + ", actual " + fileTypeBean.name); + } + if (fileType instanceof LanguageFileType) { + final LanguageFileType languageFileType = (LanguageFileType)fileType; + String expectedLanguage = languageFileType.isSecondary() ? null : languageFileType.getLanguage().getID(); + if (!Comparing.equal(fileTypeBean.language, expectedLanguage)) { + LOG.error("Incorrect language specified in for " + fileType.getName() + ", should be " + expectedLanguage + ", actual " + fileTypeBean.language); + } + } + final StandardFileType standardFileType = new StandardFileType(fileType, fileTypeBean.getMatchers()); myStandardFileTypes.put(fileTypeBean.name, standardFileType); registerFileTypeWithoutNotification(standardFileType.fileType, standardFileType.matchers, true); diff --git a/platform/platform-resources/src/META-INF/JsonPlugin.xml b/platform/platform-resources/src/META-INF/JsonPlugin.xml index 2bc5e4c3bbbe..53cbff091b45 100644 --- a/platform/platform-resources/src/META-INF/JsonPlugin.xml +++ b/platform/platform-resources/src/META-INF/JsonPlugin.xml @@ -3,8 +3,8 @@ - - + + diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index f5207211b264..8462030f1fb0 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -359,7 +359,7 @@ - diff --git a/plugins/markdown/resource/META-INF/plugin.xml b/plugins/markdown/resource/META-INF/plugin.xml index 74bb2c6cfbb9..4a244a960887 100644 --- a/plugins/markdown/resource/META-INF/plugin.xml +++ b/plugins/markdown/resource/META-INF/plugin.xml @@ -30,7 +30,7 @@ Includes the following features:

- diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/config/MavenConfigFileType.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/config/MavenConfigFileType.kt index 29a6c2708559..9416d734d121 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/config/MavenConfigFileType.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/config/MavenConfigFileType.kt @@ -6,7 +6,7 @@ import com.intellij.openapi.fileTypes.PlainTextLanguage import icons.MavenIcons import javax.swing.Icon -class MavenConfigFileType : LanguageFileType(PlainTextLanguage.INSTANCE) { +class MavenConfigFileType : LanguageFileType(PlainTextLanguage.INSTANCE, true) { override fun getName(): String { return "MavenConfig"