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 LanguageRegistry
CPD
Contains the languages that support CPD and are found on the classpath of the classloader of this class.static LanguageRegistry
PMD
Contains the languages that support PMD and are found on the classpath of the classloader of this class.
-
Constructor Summary
Constructors Constructor Description LanguageRegistry(Set<? extends Language> languages)
Create a new registry that contains the given set of languages.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NonNull String
commaSeparatedList(Function<? super Language,String> languageToString)
Formats the set of languages with the given formatter, sort and join everything with commas.LanguageRegistry
filter(Predicate<Language> filterFun)
Create a new registry with the languages that satisfy the predicate.LanguageRegistry
getDependenciesOf(Language lang)
Creates a language registry containing the given language and its dependencies, fetched from this language registry or the parameter.@Nullable Language
getLanguageByFullName(String languageName)
Returns a language from its full name (eg"Java"
).@Nullable Language
getLanguageById(@Nullable String langId)
Returns a language from its ID (eg"java"
).Set<Language>
getLanguages()
Returns a set of all the known languages.@Nullable LanguageVersion
getLanguageVersionById(@Nullable String langId, @Nullable String version)
Returns a language version from its language ID (eg"java"
).@NonNull Iterator<Language>
iterator()
static @NonNull LanguageRegistry
loadLanguages(ClassLoader classLoader)
Create a new registry by loading the languages registered viaServiceLoader
on the classpath of the given classloader.static LanguageRegistry
singleton(Language l)
Creates a language registry containing a single language.String
toString()
-
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.
-
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
-
filter
public LanguageRegistry filter(Predicate<Language> filterFun)
Create a new registry with the languages that satisfy the predicate.
-
singleton
public static LanguageRegistry singleton(Language l)
Creates a language registry containing a single language. Note that this may be inconvertible to aLanguageProcessorRegistry
if 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 viaServiceLoader
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 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
-
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.
-
-