Class LanguageRegistry

  • All Implemented Interfaces:
    Iterable<Language>

    public final class LanguageRegistry
    extends Object
    implements Iterable<Language>
    A set of languages with convenient methods. In the PMD CLI, languages are loaded from the classloader of this class. These are in the registry PMD. You can otherwise create different registries with different languages, eg filter some out.
    • Field Detail

      • PMD

        public static final LanguageRegistry PMD
        Contains the languages that support PMD and are found on the classpath of the classloader of this class. This can be used as a "default" registry.
    • Constructor Detail

      • LanguageRegistry

        public LanguageRegistry​(Set<Language> languages)
        Create a new registry that contains the given set of languages.
        Throws:
        NullPointerException - If the parameter is null
    • Method Detail

      • getDependenciesOf

        public LanguageRegistry getDependenciesOf​(Language lang)
        Creates a language registry containing the given language and its dependencies, fetched from this language registry or the parameter.
        Throws:
        IllegalStateException - If dependencies cannot be fulfilled.
      • loadLanguages

        public static @NonNull LanguageRegistry loadLanguages​(ClassLoader classLoader)
        Create a new registry by loading the languages registered via ServiceLoader on the classpath of the given classloader.
        Parameters:
        classLoader - A classloader
      • getLanguages

        public Set<Language> getLanguages()
        Returns a set of all the known languages. The ordering of the languages is by terse name.
      • getLanguage

        @Deprecated
        public static Language getLanguage​(String languageName)
        Deprecated.
        Returns a language from its full name (eg "Java"). This is case sensitive.
        Parameters:
        languageName - Language name
        Returns:
        A language, or null if the name is unknown
      • getLanguageById

        public @Nullable Language getLanguageById​(@Nullable String langId)
        Returns a language from its ID (eg "java"). This is case-sensitive.
        Parameters:
        langId - Language ID
        Returns:
        A language, or null if the name is unknown, or the parameter is null
      • getLanguageVersionById

        public @Nullable LanguageVersion getLanguageVersionById​(@Nullable String langId,
                                                                @Nullable String version)
        Returns a language version from its language ID (eg "java"). This is case-sensitive.
        Parameters:
        langId - Language ID
        version - Version ID
        Returns:
        A language, or null if the name is unknown
      • getLanguageByFullName

        public @Nullable Language getLanguageByFullName​(String languageName)
        Returns a language from its full name (eg "Java"). This is case sensitive.
        Parameters:
        languageName - Language name
        Returns:
        A language, or null if the name is unknown
      • findLanguageByTerseName

        @Deprecated
        public static @Nullable Language findLanguageByTerseName​(@Nullable String terseName)
        Deprecated.
        Returns a language from its terse name (eg "java"). This is case sensitive.
        Parameters:
        terseName - Language terse name
        Returns:
        A language, or null if the name is unknown
      • findByExtension

        @Deprecated
        public static List<Language> findByExtension​(String extensionWithoutDot)
        Deprecated.
        Not replaced, extension will be extended to match full name in PMD 7.
        Returns all languages that support the given extension.
        Parameters:
        extensionWithoutDot - A file extension (without '.' prefix)
      • commaSeparatedList

        public @NonNull String commaSeparatedList​(Function<? super Language,​String> languageToString)
        Formats the set of languages with the given formatter, sort and join everything with commas. Convenience method.