Package net.sourceforge.pmd.lang
Interface Language
- All Superinterfaces:
Comparable<Language>
- All Known Subinterfaces:
CpdCapableLanguage,PmdCapableLanguage
- All Known Implementing Classes:
CpdOnlyLanguageModuleBase,LanguageModuleBase,PlainTextLanguage,SimpleDialectLanguageModuleBase,SimpleLanguageModuleBase
Represents a language module, and provides access to language-specific
functionality. You can get a language instance from a
LanguageRegistry,
see LanguageRegistry.PMD for instance.
Language instances are extensions to the core of PMD. They can be registered with a service file so that PMD automatically finds them on the classpath.
Instances of this interface are stateless and immutable after construction. They mostly provide metadata about the language, like ID, name and different versions that are supported.
Languages should implement the interfaces PmdCapableLanguage
or CpdCapableLanguage to be usable by PMD or CPD, respectively.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable StringIf this is a dialect of another language, returns the base language.@NonNull LanguageVersionReturns the default language version for this language.Returns a set of the IDs of languages that this language instance depends on.Returns the list of file extensions associated with this language.getId()Returns the ID of this language.default LanguageVersionReturns the latest language version.getName()Returns the full name of this Language.Returns the short name of this language.default @Nullable LanguageVersiongetVersion(String version) Returns the language version with the given version string.Returns a complete set of supported version names for this language including all aliases.Returns an ordered list of supported versions for this language.default booleanhasExtension(String extensionWithoutDot) Returns whether this language handles the given file extension.default booleanhasVersion(String version) Returns true if a language version with the given version string is registered.default booleanisDialectOf(Language language) Return true if this language is a dialect of the given language.default LanguagePropertyBundleCreates a new bundle of properties that will serve to configure theLanguageProcessorfor this language.Methods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
getName
String getName()Returns the full name of this Language. This is generally the name of this language without the use of acronyms, but possibly some capital letters, eg"Java". It's suitable for displaying in a GUI.- Returns:
- The full name of this language.
-
getShortName
String getShortName()Returns the short name of this language. This is the commonly used short form of this language's name, perhaps an acronym, but possibly with special characters.- Returns:
- The short name of this language.
-
getId
String getId()Returns the ID of this language. This is a short, alphanumeric, lowercase name, eg"java". It's used to identify the language in the ruleset XML, and is also in the package name of the language module.- Returns:
- The ID of this language.
-
getBaseLanguageId
If this is a dialect of another language, returns the base language. Dialects are for example different flavors of XML. Dialects must share the same AST as their base language. This makes it so that rules written for the base language can be applied files of all dialects uniformly.- Experimental Status:
- Since 7.13.0. See [core] Support language dialects #5438.
-
isDialectOf
Return true if this language is a dialect of the given language.- Experimental Status:
- Since 7.13.0. See [core] Support language dialects #5438.
- Parameters:
language- A language (not null)
-
getExtensions
Returns the list of file extensions associated with this language. This list is unmodifiable. Extensions do not have a '.' prefix.- Returns:
- A list of file extensions.
-
hasExtension
Returns whether this language handles the given file extension. The comparison is done ignoring case.- Parameters:
extensionWithoutDot- A file extension (without '.' prefix)- Returns:
trueif this language handles the extension,falseotherwise.
-
getVersions
List<LanguageVersion> getVersions()Returns an ordered list of supported versions for this language.- Returns:
- All supported language versions.
-
getLatestVersion
Returns the latest language version. May not be the default.- Returns:
- The latest language version
-
getVersionNamesAndAliases
Returns a complete set of supported version names for this language including all aliases.- Returns:
- All supported language version names and aliases.
-
hasVersion
Returns true if a language version with the given version string is registered. Then,getVersionwill return a non-null value.- Parameters:
version- A version string- Returns:
- True if the version string is known
-
getVersion
Returns the language version with the given version string. Returns null if no such version exists.- Parameters:
version- A language version string.- Returns:
- The corresponding LanguageVersion,
nullif the version string is not recognized.
-
getDefaultVersion
@NonNull LanguageVersion getDefaultVersion()Returns the default language version for this language. This is an arbitrary choice made by the PMD product, and can change between PMD releases. Every language has a default version.- Returns:
- The current default language version for this language.
-
newPropertyBundle
Creates a new bundle of properties that will serve to configure theLanguageProcessorfor this language. The returned bundle must have all supported properties already declared. SeePmdCapableLanguageandCpdCapableLanguagefor sites where properties are passed back to the language with user-provided values.- Returns:
- A new set of properties
-
getDependencies
Returns a set of the IDs of languages that this language instance depends on. Whenever this language is loaded into aLanguageProcessorRegistry, those dependencies need to be loaded as well.
-