com.android.tools.lint.checks
Class TypoDetector
java.lang.Object
com.android.tools.lint.detector.api.Detector
com.android.tools.lint.detector.api.ResourceXmlDetector
com.android.tools.lint.checks.TypoDetector
- All Implemented Interfaces:
- com.android.tools.lint.detector.api.Detector.XmlScanner
public class TypoDetector
- extends com.android.tools.lint.detector.api.ResourceXmlDetector
Check which looks for likely typos in Strings.
TODO:
- Add check of Java String literals too!
- Add support for additional languages. The typo detector is now
multilingual and looks for typos-*locale*.txt files to use. However,
we need to seed it with additional typo databases. I did some searching
and came up with some alternatives. Here's the strategy I used:
Used Google Translate to translate "Wikipedia Common Misspellings", and
then I went to google.no, google.fr etc searching with that translation, and
came up with what looks like wikipedia language local lists of typos.
This is how I found the Norwegian one for example:
http://no.wikipedia.org/wiki/Wikipedia:Liste_over_alminnelige_stavefeil/Maskinform
Here are some additional possibilities not yet processed:
- French: http://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Liste_de_fautes_d'orthographe_courantes
(couldn't find a machine-readable version there?)
- Swedish:
http://sv.wikipedia.org/wiki/Wikipedia:Lista_%C3%B6ver_vanliga_spr%C3%A5kfel
(couldn't find a machine-readable version there?)
- German
http://de.wikipedia.org/wiki/Wikipedia:Liste_von_Tippfehlern/F%C3%BCr_Maschinen
- Consider also digesting files like
http://sv.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Typos
See http://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/User_manual.
Nested classes/interfaces inherited from class com.android.tools.lint.detector.api.Detector |
com.android.tools.lint.detector.api.Detector.BinaryResourceScanner, com.android.tools.lint.detector.api.Detector.ClassScanner, com.android.tools.lint.detector.api.Detector.GradleScanner, com.android.tools.lint.detector.api.Detector.JavaScanner, com.android.tools.lint.detector.api.Detector.OtherFileScanner, com.android.tools.lint.detector.api.Detector.ResourceFolderScanner, com.android.tools.lint.detector.api.Detector.XmlScanner |
Field Summary |
static com.android.tools.lint.detector.api.Issue |
ISSUE
The main issue discovered by this detector |
Fields inherited from interface com.android.tools.lint.detector.api.Detector.XmlScanner |
ALL |
Constructor Summary |
TypoDetector()
Constructs a new detector |
Method Summary |
boolean |
appliesTo(com.android.resources.ResourceFolderType folderType)
|
void |
beforeCheckFile(com.android.tools.lint.detector.api.Context context)
|
java.util.Collection<java.lang.String> |
getApplicableElements()
|
static com.android.utils.Pair<java.lang.String,java.lang.String> |
getLocale(java.lang.String parent)
Returns the locale for the given parent folder. |
static com.android.utils.Pair<java.lang.String,java.lang.String> |
getLocale(com.android.tools.lint.detector.api.XmlContext context)
Returns the locale for the given context. |
com.android.tools.lint.detector.api.Speed |
getSpeed()
|
static java.util.List<java.lang.String> |
getSuggestions(java.lang.String errorMessage,
com.android.tools.lint.detector.api.TextFormat format)
Returns the suggested replacements, if any, for the given typo. |
static java.lang.String |
getTypo(java.lang.String errorMessage,
com.android.tools.lint.detector.api.TextFormat format)
Returns the typo word in the error message from this detector |
void |
visitElement(com.android.tools.lint.detector.api.XmlContext context,
org.w3c.dom.Element element)
|
Methods inherited from class com.android.tools.lint.detector.api.ResourceXmlDetector |
appliesTo, run |
Methods inherited from class com.android.tools.lint.detector.api.Detector |
afterCheckFile, afterCheckLibraryProject, afterCheckProject, applicableSuperClasses, appliesToFolder, appliesToResourceRefs, beforeCheckLibraryProject, beforeCheckProject, checkBinaryResource, checkCall, checkClass, checkClass, checkFolder, checkInstruction, createJavaVisitor, getApplicableAsmNodeTypes, getApplicableAttributes, getApplicableCallNames, getApplicableCallOwners, getApplicableFiles, getApplicableMethodNames, getApplicableNodeTypes, getSpeed, visitAttribute, visitBuildScript, visitDocument, visitElementAfter, visitMethod, visitResourceReference |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.android.tools.lint.detector.api.Detector.XmlScanner |
getApplicableAttributes, visitAttribute, visitDocument, visitElementAfter |
ISSUE
public static final com.android.tools.lint.detector.api.Issue ISSUE
- The main issue discovered by this detector
TypoDetector
public TypoDetector()
- Constructs a new detector
appliesTo
public boolean appliesTo(@NonNull
com.android.resources.ResourceFolderType folderType)
- Overrides:
appliesTo
in class com.android.tools.lint.detector.api.ResourceXmlDetector
getLocale
@Nullable
public static com.android.utils.Pair<java.lang.String,java.lang.String> getLocale(@NonNull
java.lang.String parent)
- Returns the locale for the given parent folder.
- Parameters:
parent
- the name of the parent folder
- Returns:
- null if the locale is not known, or a pair of language and region
where one or the other but not both can be null
getLocale
@Nullable
public static com.android.utils.Pair<java.lang.String,java.lang.String> getLocale(@NonNull
com.android.tools.lint.detector.api.XmlContext context)
- Returns the locale for the given context.
- Parameters:
context
- the context to look up the locale for
- Returns:
- null if the locale is not known, or a pair of language and region
where one or the other but not both can be null
beforeCheckFile
public void beforeCheckFile(@NonNull
com.android.tools.lint.detector.api.Context context)
- Overrides:
beforeCheckFile
in class com.android.tools.lint.detector.api.Detector
getSpeed
@NonNull
public com.android.tools.lint.detector.api.Speed getSpeed()
- Overrides:
getSpeed
in class com.android.tools.lint.detector.api.Detector
getApplicableElements
public java.util.Collection<java.lang.String> getApplicableElements()
- Specified by:
getApplicableElements
in interface com.android.tools.lint.detector.api.Detector.XmlScanner
- Overrides:
getApplicableElements
in class com.android.tools.lint.detector.api.Detector
visitElement
public void visitElement(@NonNull
com.android.tools.lint.detector.api.XmlContext context,
@NonNull
org.w3c.dom.Element element)
- Specified by:
visitElement
in interface com.android.tools.lint.detector.api.Detector.XmlScanner
- Overrides:
visitElement
in class com.android.tools.lint.detector.api.Detector
getSuggestions
@Nullable
public static java.util.List<java.lang.String> getSuggestions(@NonNull
java.lang.String errorMessage,
@NonNull
com.android.tools.lint.detector.api.TextFormat format)
- Returns the suggested replacements, if any, for the given typo. The error
message must be one supplied by lint.
- Parameters:
errorMessage
- the error messageformat
- the format of the error message
- Returns:
- a list of replacement words suggested by the error message
getTypo
@Nullable
public static java.lang.String getTypo(@NonNull
java.lang.String errorMessage,
@NonNull
com.android.tools.lint.detector.api.TextFormat format)
- Returns the typo word in the error message from this detector
- Parameters:
errorMessage
- the error message produced earlier by this detectorformat
- the format of the error message
- Returns:
- the typo