Package net.sourceforge.pmd.lang
Interface Language
-
- All Superinterfaces:
Comparable<Language>
- All Known Implementing Classes:
LanguageModuleBase
,PlainTextLanguage
,SimpleLanguageModuleBase
public interface Language extends Comparable<Language>
Represents a language module, and provides access to language-specific functionality. You can get a language instance from aLanguageRegistry
.Language instances are extensions to the core of PMD. They can be registered with a service file so that the PMD CLI 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 can create a
LanguageProcessor
to actually run the analysis. That object can maintain analysis-global state, and has a proper lifecycle.- See Also:
LanguageVersion
,LanguageVersionDiscoverer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description LanguageProcessor
createProcessor(LanguagePropertyBundle bundle)
Create a newLanguageProcessor
for this language, given a property bundle with configuration.LanguageVersion
getDefaultVersion()
Returns the default language version for this language.Set<String>
getDependencies()
Returns a set of the IDs of languages that this language instance depends on.List<String>
getExtensions()
Returns the list of file extensions associated with this language.default String
getId()
Returns the ID of this language.String
getName()
Returns the full name of this Language.String
getShortName()
Returns the short name of this language.String
getTerseName()
Returns the terse name of this language.default LanguageVersion
getVersion(String version)
Returns the language version with the given version string.Set<String>
getVersionNamesAndAliases()
Returns a complete set of supported version names for this language including all aliases.List<LanguageVersion>
getVersions()
Returns an ordered list of supported versions for this language.default boolean
hasExtension(String extensionWithoutDot)
Returns whether this language handles the given file extension.default boolean
hasVersion(String version)
Returns true if a language version with the given version string is registered.default LanguagePropertyBundle
newPropertyBundle()
Creates a new bundle of properties that will serve to configure theLanguageProcessor
for this language.-
Methods inherited from interface java.lang.Comparable
compareTo
-
-
-
-
Method Detail
-
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.
-
getTerseName
String getTerseName()
Returns the terse name 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 terse name of this language.
-
getId
default 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.
-
getExtensions
List<String> 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
default boolean hasExtension(String extensionWithoutDot)
Returns whether this language handles the given file extension. The comparison is done ignoring case.- Parameters:
extensionWithoutDot
- A file extension (without '.' prefix)- Returns:
true
if this language handles the extension,false
otherwise.
-
getVersions
List<LanguageVersion> getVersions()
Returns an ordered list of supported versions for this language.- Returns:
- All supported language versions.
-
getVersionNamesAndAliases
Set<String> getVersionNamesAndAliases()
Returns a complete set of supported version names for this language including all aliases.- Returns:
- All supported language version names and aliases.
-
hasVersion
default boolean hasVersion(String version)
Returns true if a language version with the given version string is registered. Then,getVersion
will return a non-null value.- Parameters:
version
- A version string- Returns:
- True if the version string is known
-
getVersion
default LanguageVersion getVersion(String version)
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,
null
if the version string is not recognized.
-
getDefaultVersion
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
default LanguagePropertyBundle newPropertyBundle()
Creates a new bundle of properties that will serve to configure theLanguageProcessor
for this language. The returned bundle must have all relevant properties already declared.- Returns:
- A new set of properties
-
createProcessor
LanguageProcessor createProcessor(LanguagePropertyBundle bundle)
Create a newLanguageProcessor
for this language, given a property bundle with configuration. The bundle was created by this instance usingnewPropertyBundle()
. It can be assumed that the bundle will never be mutated anymore, and this method takes ownership of it.- Parameters:
bundle
- A bundle of properties created by this instance.- Returns:
- A new language processor
-
getDependencies
Set<String> 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.
-
-