Class LanguageVersionDiscoverer


  • public class LanguageVersionDiscoverer
    extends Object
    This class can discover the LanguageVersion of a source file. Further, every Language has a default LanguageVersion, which can be temporarily overridden here.
    • Constructor Detail

      • LanguageVersionDiscoverer

        public LanguageVersionDiscoverer​(LanguageRegistry registry,
                                         LanguageVersion forcedVersion)
        Build a new instance.
        Parameters:
        forcedVersion - If non-null, all files should be assigned this version. The methods of this class still work as usual and do not care about the forced language version.
      • LanguageVersionDiscoverer

        public LanguageVersionDiscoverer​(LanguageRegistry registry)
        Build a new instance with no forced version.
    • Method Detail

      • setDefaultLanguageVersion

        public LanguageVersion setDefaultLanguageVersion​(LanguageVersion languageVersion)
        Set the given LanguageVersion as the current default for it's Language.
        Parameters:
        languageVersion - The new default for the Language.
        Returns:
        The previous default version for the language.
      • getDefaultLanguageVersion

        public LanguageVersion getDefaultLanguageVersion​(Language language)
        Get the current default LanguageVersion for the given Language.
        Parameters:
        language - The Language.
        Returns:
        The current default version for the language.
      • getDefaultLanguageVersionForFile

        public LanguageVersion getDefaultLanguageVersionForFile​(File sourceFile)
        Get the default LanguageVersion for the first Language of a given source file.
        Parameters:
        sourceFile - The file.
        Returns:
        The currently configured LanguageVersion for the source file, or null if there are no supported Languages for the file.
      • getDefaultLanguageVersionForFile

        public @Nullable LanguageVersion getDefaultLanguageVersionForFile​(String fileName)
        Get the LanguageVersion for the first Language of a source file with the given name.
        Parameters:
        fileName - The file name.
        Returns:
        The currently configured LanguageVersion for the source file or null if there are no supported Languages for the file.
      • setForcedVersion

        public void setForcedVersion​(LanguageVersion forceLanguageVersion)
      • getLanguagesForFile

        public List<Language> getLanguagesForFile​(String fileName)
        Get the Languages of a given source file.
        Parameters:
        fileName - The file name.
        Returns:
        The Languages for the source file, may be empty.
      • onlyRecognizeLanguages

        public void onlyRecognizeLanguages​(LanguageRegistry lang)
        Make it so that the only extensions that are considered are those of the given language. This is different from setForcedVersion(LanguageVersion). because that one will assign the given language version to all files irrespective of extension. This method, on the other hand, will ignore files that do not match the given language.
        Parameters:
        lang - A language