Add consistency checks for file type registration, fix found inconsistencies (IDEA-CR-50521)

GitOrigin-RevId: 6d7e927a3d55a34e74b5121b3bd3ef3ccc582bc8
This commit is contained in:
Dmitry Jemerov
2019-07-23 20:49:32 +03:00
committed by intellij-monorepo-bot
parent 1b985b2313
commit 56a956a1f0
7 changed files with 25 additions and 5 deletions
@@ -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);
}
@@ -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;
}
@@ -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 <fileType>, 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 <fileType> 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);
@@ -3,8 +3,8 @@
<module value="com.intellij.modules.json"/>
<extensions defaultExtensionNs="com.intellij">
<fileType name="JSON" extensions="json" implementationClass="com.intellij.json.JsonFileType" fieldName="INSTANCE"/>
<fileType name="JSON5" extensions="json5" implementationClass="com.intellij.json.json5.Json5FileType" fieldName="INSTANCE"/>
<fileType name="JSON" extensions="json" implementationClass="com.intellij.json.JsonFileType" fieldName="INSTANCE" language="JSON"/>
<fileType name="JSON5" extensions="json5" implementationClass="com.intellij.json.json5.Json5FileType" fieldName="INSTANCE" language="JSON5"/>
<fileIconProvider implementation="com.jetbrains.jsonSchema.JsonSchemaIconProvider"/>
<lang.parserDefinition language="JSON" implementationClass="com.intellij.json.JsonParserDefinition"/>
<lang.parserDefinition language="JSON5" implementationClass="com.intellij.json.json5.Json5ParserDefinition"/>
@@ -359,7 +359,7 @@
<fileType name="ARCHIVE" implementationClass="com.intellij.ide.highlighter.ArchiveFileType" fieldName="INSTANCE"
extensions="zip;jar;war;ear;swc;ane;egg;apk"/>
<fileType name="PLAIN_TEXT" implementationClass="com.intellij.openapi.fileTypes.PlainTextFileType" fieldName="INSTANCE"
<fileType name="PLAIN_TEXT" implementationClass="com.intellij.openapi.fileTypes.PlainTextFileType" fieldName="INSTANCE" language="TEXT"
extensions="txt;bat;cmd;policy;log;cgi;jad;jam;htaccess;opts;csv"/>
<fileType name="Native" implementationClass="com.intellij.openapi.fileTypes.NativeFileType" fieldName="INSTANCE"
extensions="doc;docx;xls;xlsx;ppt;pptx;mdb;vsd;pdf;hlp;chm;odt"/>
@@ -30,7 +30,7 @@ Includes the following features:</p>
</extensionPoints>
<extensions defaultExtensionNs="com.intellij">
<fileType name="Markdown" extensions="md;markdown"
<fileType name="Markdown" extensions="md;markdown" language="Markdown"
implementationClass="org.intellij.plugins.markdown.lang.MarkdownFileType" fieldName="INSTANCE"/>
<lang.fileViewProviderFactory language="Markdown" implementationClass="org.intellij.plugins.markdown.lang.MarkdownFileViewProviderFactory"/>
<lang.parserDefinition language="Markdown" implementationClass="org.intellij.plugins.markdown.lang.parser.MarkdownParserDefinition"/>
@@ -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"