Class MimeType

  • All Implemented Interfaces:

    
    public final class MimeType
    
                        

    Represents the language and dialect of a source snippet, as an RFC 2046 mime type.

    For example, a Kotlin source file may have the mime type text/kotlin. However, if it corresponds to a build.gradle.kts file, we'll also attach the mime parameter role=gradle, resulting in mime type text/kotlin; role=gradle.

    For XML resource files, we'll attach other attributes; for example role=manifest for Android manifest files and role=resource for XML resource files. For the latter we may also attach for example folderType=values, and for XML files in general, the root tag, such as text/xml; role=resource; folderType=layout; rootTag=LinearLayout.

    This class does not implement all aspects of the RFC; in particular, we don't treat attributes as case-insensitive, and we only support value tokens, not value strings -- neither of these are needed for our purposes.

    This is implemented using a value class, such that behind the scenes we're really just passing a String around. This also means we can't initialize related values such as the corresponding Markdown fenced block names, or IntelliJ language id's. Instead, these are looked up via when-tables. When adding a new language, update all lookup methods:

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class MimeType.Known
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      MimeType(String mimeType)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final String displayName()
      final MimeType base() Returns just the language portion of the mime type.
      String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MimeType

        MimeType(String mimeType)
    • Method Detail

      • base

         final MimeType base()

        Returns just the language portion of the mime type.

        For example, for text/kotlin; role=gradle this will return text/kotlin. For text/plain; charset=us-ascii this returns text/plain