Package net.sourceforge.pmd.lang
Class BaseLanguageModule
- java.lang.Object
-
- net.sourceforge.pmd.lang.BaseLanguageModule
-
- All Implemented Interfaces:
Comparable<Language>,Language
public abstract class BaseLanguageModule extends Object implements Language
Created by christoferdutz on 21.09.14.
-
-
Field Summary
Fields Modifier and Type Field Description protected LanguageVersiondefaultVersionprotected List<String>extensionsprotected Stringnameprotected Class<?>ruleChainVisitorClassprotected StringshortNameprotected StringterseNameprotected Map<String,LanguageVersion>versions-
Fields inherited from interface net.sourceforge.pmd.lang.Language
LANGUAGE_MODULES_CLASS_NAMES_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description BaseLanguageModule(String name, String shortName, String terseName, Class<?> ruleChainVisitorClass, String... extensions)Deprecated.Use the other constructor.BaseLanguageModule(String name, String shortName, String terseName, String firstExtension, String... otherExtensions)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddDefaultVersion(String version, LanguageVersionHandler languageVersionHandler, String... versionAliases)Adds a version with the given identifier, and sets it as the default.protected voidaddVersion(String version, LanguageVersionHandler languageVersionHandler, boolean isDefault)protected voidaddVersion(String version, LanguageVersionHandler languageVersionHandler, String... versionAliases)Adds a non-default version with the given identifier.intcompareTo(Language o)booleanequals(Object obj)LanguageVersiongetDefaultVersion()Returns the default language version for this language.List<String>getExtensions()Returns the list of file extensions associated with this language.StringgetName()Returns the full name of this Language.Class<?>getRuleChainVisitorClass()Get the RuleChainVisitor implementation class used when visiting the AST structure for this Rules for this Language.StringgetShortName()Returns the short name of this language.StringgetTerseName()Returns the terse name of this language.LanguageVersiongetVersion(String versionName)Returns the language version with the given version string.List<LanguageVersion>getVersions()Returns an ordered list of supported versions for this language.booleanhasExtension(String extensionWithoutDot)Returns whether this language handles the given file extension.inthashCode()booleanhasVersion(String version)Returns true if a language version with the given version string is registered.StringtoString()
-
-
-
Field Detail
-
name
protected String name
-
shortName
protected String shortName
-
terseName
protected String terseName
-
ruleChainVisitorClass
protected Class<?> ruleChainVisitorClass
-
versions
protected Map<String,LanguageVersion> versions
-
defaultVersion
protected LanguageVersion defaultVersion
-
-
Constructor Detail
-
BaseLanguageModule
@Deprecated public BaseLanguageModule(String name, String shortName, String terseName, Class<?> ruleChainVisitorClass, String... extensions)
Deprecated.Use the other constructor. It doesn't require a rulechain visitor class, but forces you to mention at least one file extension.
-
-
Method Detail
-
addVersion
protected void addVersion(String version, LanguageVersionHandler languageVersionHandler, String... versionAliases)
Adds a non-default version with the given identifier.- Throws:
IllegalArgumentException- If the string key or any of the aliases conflict with other already recorded versions
-
addDefaultVersion
protected void addDefaultVersion(String version, LanguageVersionHandler languageVersionHandler, String... versionAliases)
Adds a version with the given identifier, and sets it as the default.- Throws:
IllegalStateException- If the default version is already setIllegalArgumentException- If the string key or any of the aliases conflict with other already recorded versions
-
addVersion
@Deprecated protected void addVersion(String version, LanguageVersionHandler languageVersionHandler, boolean isDefault)
-
getName
public String getName()
Description copied from interface:LanguageReturns 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.
-
getShortName
public String getShortName()
Description copied from interface:LanguageReturns 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.- Specified by:
getShortNamein interfaceLanguage- Returns:
- The short name of this language.
-
getTerseName
public String getTerseName()
Description copied from interface:LanguageReturns 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.- Specified by:
getTerseNamein interfaceLanguage- Returns:
- The terse name of this language.
-
getRuleChainVisitorClass
public Class<?> getRuleChainVisitorClass()
Description copied from interface:LanguageGet the RuleChainVisitor implementation class used when visiting the AST structure for this Rules for this Language.- Specified by:
getRuleChainVisitorClassin interfaceLanguage- Returns:
- The RuleChainVisitor class.
- See Also:
RuleChainVisitor
-
getExtensions
public List<String> getExtensions()
Description copied from interface:LanguageReturns the list of file extensions associated with this language. This list is unmodifiable. Extensions do not have a '.' prefix.- Specified by:
getExtensionsin interfaceLanguage- Returns:
- A list of file extensions.
-
hasExtension
public boolean hasExtension(String extensionWithoutDot)
Description copied from interface:LanguageReturns whether this language handles the given file extension. The comparison is done ignoring case.- Specified by:
hasExtensionin interfaceLanguage- Parameters:
extensionWithoutDot- A file extension (without '.' prefix)- Returns:
trueif this language handles the extension,falseotherwise.
-
getVersions
public List<LanguageVersion> getVersions()
Description copied from interface:LanguageReturns an ordered list of supported versions for this language.- Specified by:
getVersionsin interfaceLanguage- Returns:
- All supported language versions.
-
hasVersion
public boolean hasVersion(String version)
Description copied from interface:LanguageReturns true if a language version with the given version string is registered. Then,getVersionwill return a non-null value.- Specified by:
hasVersionin interfaceLanguage- Parameters:
version- A version string- Returns:
- True if the version string is known
-
getVersion
public LanguageVersion getVersion(String versionName)
Description copied from interface:LanguageReturns the language version with the given version string. Returns null if no such version exists.- Specified by:
getVersionin interfaceLanguage- Parameters:
versionName- A language version string.- Returns:
- The corresponding LanguageVersion,
nullif the version string is not recognized.
-
getDefaultVersion
public LanguageVersion getDefaultVersion()
Description copied from interface:LanguageReturns 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.- Specified by:
getDefaultVersionin interfaceLanguage- Returns:
- The current default language version for this language.
-
compareTo
public int compareTo(Language o)
- Specified by:
compareToin interfaceComparable<Language>
-
-