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.
      • CPD

        public static final LanguageRegistry CPD
        Contains the languages that support CPD and are found on the classpath of the classloader of this class.
    • Constructor Detail

      • LanguageRegistry

        public LanguageRegistry​(Set<? extends 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.
      • 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
      • 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.