Package net.sourceforge.pmd.lang
Class LanguageRegistry
java.lang.Object
net.sourceforge.pmd.lang.LanguageRegistry
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final LanguageRegistryContains the languages that support CPD and are found on the classpath of the classloader of this class.static final LanguageRegistryContains the languages that support PMD and are found on the classpath of the classloader of this class. -
Constructor Summary
ConstructorsConstructorDescriptionLanguageRegistry(Set<? extends Language> languages) Create a new registry that contains the given set of languages. -
Method Summary
Modifier and TypeMethodDescription@NonNull StringcommaSeparatedList(Function<? super Language, String> languageToString) Formats the set of languages with the given formatter, sort and join everything with commas.Create a new registry with the languages that satisfy the predicate.getDependenciesOf(Language lang) Creates a language registry containing the given language and its dependencies, fetched from this language registry or the parameter.@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").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").iterator()static @NonNull LanguageRegistryloadLanguages(ClassLoader classLoader) Create a new registry by loading the languages registered viaServiceLoaderon the classpath of the given classloader.static LanguageRegistryCreates a language registry containing a single language.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
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
Contains the languages that support CPD and are found on the classpath of the classloader of this class.
-
-
Constructor Details
-
LanguageRegistry
Create a new registry that contains the given set of languages.- Throws:
NullPointerException- If the parameter is null
-
-
Method Details
-
filter
Create a new registry with the languages that satisfy the predicate. -
singleton
Creates a language registry containing a single language. Note that this may be inconvertible to aLanguageProcessorRegistryif the language depends on other languages. -
getDependenciesOf
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.
-
iterator
-
loadLanguages
Create a new registry by loading the languages registered viaServiceLoaderon the classpath of the given classloader.- Parameters:
classLoader- A classloader
-
getLanguages
Returns a set of all the known languages. The ordering of the languages is by terse name. -
getLanguageById
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
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
Formats the set of languages with the given formatter, sort and join everything with commas. Convenience method. -
toString
-