IntelliJ Platform SDK DevGuide

Edit page

2. Language and File Type

2.1. Define a language

Note the case of the name of the language - Simple.

package com.simpleplugin; import com.intellij.lang.Language; public class SimpleLanguage extends Language { public static final SimpleLanguage INSTANCE = new SimpleLanguage(); private SimpleLanguage() { super("Simple"); } }

2.2. Define an icon

Copy the icon to com.simpleplugin.icons package.

package com.simpleplugin; import com.intellij.openapi.util.IconLoader; import javax.swing.*; public class SimpleIcons { public static final Icon FILE = IconLoader.getIcon("/com/simpleplugin/icons/jar-gray.png"); }

2.3. Define a file type

package com.simpleplugin; import com.intellij.openapi.fileTypes.LanguageFileType; import org.jetbrains.annotations.*; import javax.swing.*; public 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"; } @Nullable @Override public Icon getIcon() { return SimpleIcons.FILE; } }

2.4. Define a file type factory

package com.simpleplugin; import com.intellij.openapi.fileTypes.*; import org.jetbrains.annotations.NotNull; public class SimpleFileTypeFactory extends FileTypeFactory { @Override public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { fileTypeConsumer.consume(SimpleFileType.INSTANCE); } }

2.5. Register the file type factory

In plugin.xml add:

<extensions defaultExtensionNs="com.intellij"> <fileTypeFactory implementation="com.simpleplugin.SimpleFileTypeFactory"/> </extensions>

2.6. Run the project

Create a file with extension .simple and IntelliJ IDEA will automatically associate it with our language.

File Type Factory

Last modified: 21 October 2017