Package net.sourceforge.pmd.lang
Class LanguageVersion
- java.lang.Object
-
- net.sourceforge.pmd.lang.LanguageVersion
-
- All Implemented Interfaces:
Comparable<LanguageVersion>
public class LanguageVersion extends Object implements Comparable<LanguageVersion>
Represents a version of aLanguage
. Language instances provide a list of supported versions (Language.getVersions()
). Individual versions can be retrieved from their version number (Language.getVersion(String)
).Versions are used to limit some rules to operate on only a version range. For instance, a rule that suggests eliding local variable types in Java (replacing them with
var
) makes no sense if the codebase is not using Java 10 or later. This is determined byRule.getMinimumLanguageVersion()
andRule.getMaximumLanguageVersion()
. These should be set in the ruleset XML (they're attributes of the<rule>
element), and not overridden.Example usage:
Language javaLanguage = LanguageRegistry.
getLanguage
("Java"); LanguageVersion java11 = javaLanguage.getVersion
("11"); LanguageVersionHandler handler = java11.getLanguageVersionHandler(); Parser parser = handler.getParser(handler.getDefaultParserOptions()); // use parser
-
-
Constructor Summary
Constructors Constructor Description LanguageVersion(Language language, String version, LanguageVersionHandler languageVersionHandler)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(LanguageVersion o)
Language
getLanguage()
Returns the language that owns this version.LanguageVersionHandler
getLanguageVersionHandler()
Returns theLanguageVersionHandler
, which provides access to version-specific services, like the parser.String
getName()
Returns the name of this language version.String
getShortName()
Get the short name of this LanguageVersion.String
getTerseName()
Get the terse name of this LanguageVersion.String
getVersion()
Returns the version string.String
toString()
-
-
-
Constructor Detail
-
LanguageVersion
@Deprecated @InternalApi public LanguageVersion(Language language, String version, LanguageVersionHandler languageVersionHandler)
Deprecated.UseLanguage.getVersion(String)
. This is only supposed to be used when initializing aLanguage
instance.
-
-
Method Detail
-
getLanguage
public Language getLanguage()
Returns the language that owns this version.
-
getVersion
public String getVersion()
Returns the version string. This is usually a version number, e.g."1.7"
or"11"
. This is used byLanguage.getVersion(String)
.
-
getLanguageVersionHandler
public LanguageVersionHandler getLanguageVersionHandler()
Returns theLanguageVersionHandler
, which provides access to version-specific services, like the parser.
-
getName
public String getName()
Returns the name of this language version. This is the version string prefixed with the language name.- Returns:
- The name of this LanguageVersion.
-
getShortName
public String getShortName()
Get the short name of this LanguageVersion. This is Language short name appended with the LanguageVersion version if not an empty String.- Returns:
- The short name of this LanguageVersion.
-
getTerseName
public String getTerseName()
Get the terse name of this LanguageVersion. This is Language terse name appended with the LanguageVersion version if not an empty String.- Returns:
- The terse name of this LanguageVersion.
-
compareTo
public int compareTo(LanguageVersion o)
- Specified by:
compareTo
in interfaceComparable<LanguageVersion>
-
-