Package net.sourceforge.pmd.lang
Class LanguageRegistry
- java.lang.Object
-
- net.sourceforge.pmd.lang.LanguageRegistry
-
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 registryPMD. You can otherwise create different registries with different languages, eg filter some out.
-
-
Field Summary
Fields Modifier and Type Field Description static LanguageRegistryPMDContains the languages that support PMD and are found on the classpath of the classloader of this class.
-
Constructor Summary
Constructors Constructor Description LanguageRegistry(Set<Language> languages)Create a new registry that contains the given set of languages.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description @NonNull StringcommaSeparatedList(Function<? super Language,String> languageToString)Formats the set of languages with the given formatter, sort and join everything with commas.static List<Language>findByExtension(String extensionWithoutDot)Deprecated.Not replaced, extension will be extended to match full name in PMD 7.static @Nullable LanguagefindLanguageByTerseName(@Nullable String terseName)Deprecated.LanguageRegistrygetDependenciesOf(Language lang)Creates a language registry containing the given language and its dependencies, fetched from this language registry or the parameter.static LanguagegetLanguage(String languageName)Deprecated.@Nullable LanguagegetLanguageByFullName(String languageName)Returns a language from its full name (eg"Java").@Nullable LanguagegetLanguageById(@Nullable String langId)Returns a language from its ID (eg"java").Set<Language>getLanguages()Returns a set of all the known languages.@Nullable LanguageVersiongetLanguageVersionById(@Nullable String langId, @Nullable String version)Returns a language version from its language ID (eg"java").@NonNull Iterator<Language>iterator()static @NonNull LanguageRegistryloadLanguages(ClassLoader classLoader)Create a new registry by loading the languages registered viaServiceLoaderon the classpath of the given classloader.static LanguageRegistrysingleton(Language l)Creates a language registry containing a single language.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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
-
singleton
public static LanguageRegistry singleton(Language l)
Creates a language registry containing a single language. Note that this may be inconvertible to aLanguageProcessorRegistryif the language depends on other languages.
-
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 viaServiceLoaderon 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 IDversion- 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.
-
-