Package net.sourceforge.pmd.lang
Class LanguageVersionDiscoverer
- java.lang.Object
-
- net.sourceforge.pmd.lang.LanguageVersionDiscoverer
-
public class LanguageVersionDiscoverer extends Object
This class can discover the LanguageVersion of a source file. Further, every Language has a default LanguageVersion, which can be temporarily overridden here.
-
-
Constructor Summary
Constructors Constructor Description LanguageVersionDiscoverer(LanguageRegistry registry)
Build a new instance with no forced version.LanguageVersionDiscoverer(LanguageRegistry registry, LanguageVersion forcedVersion)
Build a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LanguageVersion
getDefaultLanguageVersion(Language language)
Get the current default LanguageVersion for the given Language.LanguageVersion
getDefaultLanguageVersionForFile(File sourceFile)
Get the default LanguageVersion for the first Language of a given source file.@Nullable LanguageVersion
getDefaultLanguageVersionForFile(String fileName)
Get the LanguageVersion for the first Language of a source file with the given name.LanguageVersion
getForcedVersion()
List<Language>
getLanguagesForFile(String fileName)
Get the Languages of a given source file.void
onlyRecognizeLanguages(LanguageRegistry lang)
Make it so that the only extensions that are considered are those of the given language.LanguageVersion
setDefaultLanguageVersion(LanguageVersion languageVersion)
Set the given LanguageVersion as the current default for it's Language.void
setForcedVersion(LanguageVersion forceLanguageVersion)
String
toString()
-
-
-
Constructor Detail
-
LanguageVersionDiscoverer
public LanguageVersionDiscoverer(LanguageRegistry registry, LanguageVersion forcedVersion)
Build a new instance.- Parameters:
forcedVersion
- If non-null, all files should be assigned this version. The methods of this class still work as usual and do not care about the forced language version.
-
LanguageVersionDiscoverer
public LanguageVersionDiscoverer(LanguageRegistry registry)
Build a new instance with no forced version.
-
-
Method Detail
-
setDefaultLanguageVersion
public LanguageVersion setDefaultLanguageVersion(LanguageVersion languageVersion)
Set the given LanguageVersion as the current default for it's Language.- Parameters:
languageVersion
- The new default for the Language.- Returns:
- The previous default version for the language.
-
getDefaultLanguageVersion
public LanguageVersion getDefaultLanguageVersion(Language language)
Get the current default LanguageVersion for the given Language.- Parameters:
language
- The Language.- Returns:
- The current default version for the language.
-
getDefaultLanguageVersionForFile
public LanguageVersion getDefaultLanguageVersionForFile(File sourceFile)
Get the default LanguageVersion for the first Language of a given source file.- Parameters:
sourceFile
- The file.- Returns:
- The currently configured LanguageVersion for the source file, or
null
if there are no supported Languages for the file.
-
getDefaultLanguageVersionForFile
public @Nullable LanguageVersion getDefaultLanguageVersionForFile(String fileName)
Get the LanguageVersion for the first Language of a source file with the given name.- Parameters:
fileName
- The file name.- Returns:
- The currently configured LanguageVersion for the source file or
null
if there are no supported Languages for the file.
-
getForcedVersion
public LanguageVersion getForcedVersion()
-
setForcedVersion
public void setForcedVersion(LanguageVersion forceLanguageVersion)
-
getLanguagesForFile
public List<Language> getLanguagesForFile(String fileName)
Get the Languages of a given source file.- Parameters:
fileName
- The file name.- Returns:
- The Languages for the source file, may be empty.
-
onlyRecognizeLanguages
public void onlyRecognizeLanguages(LanguageRegistry lang)
Make it so that the only extensions that are considered are those of the given language. This is different fromsetForcedVersion(LanguageVersion)
. because that one will assign the given language version to all files irrespective of extension. This method, on the other hand, will ignore files that do not match the given language.- Parameters:
lang
- A language
-
-