IntelliJ Platform Plugin SDK Help

2. Language and File Type

The IntelliJ Platform determines file type by examining the name of a file. Each language has Language and LanguageFileType objects defining the language. Register the LanguageFileType with the IntelliJ Platform in the plugin configuration file.

Define the Language

The language implemented in this tutorial is named "Simple" - note the case of the name. The SimpleLanguage class is defined in the org.intellij.sdk.language package of the simple_language_plugin code sample:

public class SimpleLanguage extends Language { public static final SimpleLanguage INSTANCE = new SimpleLanguage(); private SimpleLanguage() { super("Simple"); } }

Define an Icon

The icon for the Simple Language is defined by the SimpleIcons class. Please see Working with Icons for details on how to define and use icons.

public class SimpleIcons { public static final Icon FILE = IconLoader.getIcon("/icons/jar-gray.png", SimpleIcons.class); }

Define a File Type

The SimpleFileType is defined by subclassing LanguageFileType:

public final class SimpleFileType extends LanguageFileType { public static final SimpleFileType INSTANCE = new SimpleFileType(); private SimpleFileType() { super(SimpleLanguage.INSTANCE); } @NotNull @Override public String getName() { return "Simple File"; } @NotNull @Override public String getDescription() { return "Simple language file"; } @NotNull @Override public String getDefaultExtension() { return "simple"; } @Override public Icon getIcon() { return SimpleIcons.FILE; } }

Register the File Type

The Simple Language file type is registered via the com.intellij.fileType extension point in plugin.xml and registered with *.simple extension:

<extensions defaultExtensionNs="com.intellij"> <fileType name="Simple File" implementationClass="org.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE" language="Simple" extensions="simple"/> </extensions>

Run the Project

Run the plugin by using the Gradle runIde task.

Create an empty file with the extension .simple, and IntelliJ IDEA automatically associates it with our language. Note the appearance of the Simple Language file icon next to the test.simple file in the Project Tool Window, and the editor tab for the file.

File Type Factory
Last modified: 09 April 2024