|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.android.tools.lint.detector.api.Detector
@Beta public abstract class Detector
A detector is able to find a particular problem. It might also be thought of as enforcing a rule, but "rule" is a bit overloaded in ADT terminology since ViewRules are used in the Rules API to allow views to specify designtime behavior in the graphical layout editor.
Each detector provides information about the issues it can find, such as an explanation of how to fix the issue, the priority, the category, etc. It also has an id which is used to persistently identify a particular type of error.
Detectors will be called in a predefined order:
LintDriver.requestRepeat(com.android.tools.lint.detector.api.Detector, java.util.EnumSet)
.
NOTE: Detectors might be constructed just once and shared between lint runs, so any per-detector state should be initialized and reset via the before/after methods.
NOTE: This is not a public or final API; if you rely on this be prepared to adjust your code for the next tools release.
Nested Class Summary | |
---|---|
static interface |
Detector.BinaryResourceScanner
Specialized interface for detectors that scan binary resource files |
static interface |
Detector.ClassScanner
Specialized interface for detectors that scan Java class files |
static interface |
Detector.GradleScanner
Specialized interface for detectors that scan Gradle files |
static interface |
Detector.JavaScanner
Specialized interface for detectors that scan Java source file parse trees |
static interface |
Detector.OtherFileScanner
Specialized interface for detectors that scan other files |
static interface |
Detector.ResourceFolderScanner
Specialized interface for detectors that scan resource folders (the folder directory itself, not the individual files within it |
static interface |
Detector.XmlScanner
Specialized interface for detectors that scan XML files |
Constructor Summary | |
---|---|
Detector()
|
Method Summary | |
---|---|
void |
afterCheckFile(Context context)
Analysis has just been finished for a specific file, perform any cleanup or report issues found |
void |
afterCheckLibraryProject(Context context)
Analysis has just been finished for the given library project, perform any cleanup or report issues that require library-project-wide analysis. |
void |
afterCheckProject(Context context)
Analysis has just been finished for the whole project, perform any cleanup or report issues that require project-wide analysis. |
java.util.List<java.lang.String> |
applicableSuperClasses()
|
boolean |
appliesTo(Context context,
java.io.File file)
Returns true if this detector applies to the given file |
boolean |
appliesTo(com.android.resources.ResourceFolderType folderType)
|
boolean |
appliesToFolder(Scope scope,
com.android.resources.ResourceFolderType folderType)
|
boolean |
appliesToResourceRefs()
|
void |
beforeCheckFile(Context context)
Analysis is about to be performed on a specific file, perform any setup steps. |
void |
beforeCheckLibraryProject(Context context)
Analysis is about to begin for the given library project, perform any setup steps. |
void |
beforeCheckProject(Context context)
Analysis is about to begin, perform any setup steps. |
void |
checkBinaryResource(ResourceContext context)
|
void |
checkCall(ClassContext context,
org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.MethodInsnNode call)
|
void |
checkClass(ClassContext context,
org.objectweb.asm.tree.ClassNode classNode)
|
void |
checkClass(JavaContext context,
lombok.ast.ClassDeclaration node,
JavaParser.ResolvedClass resolvedClass)
|
void |
checkFolder(ResourceContext context,
java.lang.String folderName)
|
void |
checkInstruction(ClassContext context,
org.objectweb.asm.tree.ClassNode classNode,
org.objectweb.asm.tree.MethodNode method,
org.objectweb.asm.tree.AbstractInsnNode instruction)
|
lombok.ast.AstVisitor |
createJavaVisitor(JavaContext context)
|
int[] |
getApplicableAsmNodeTypes()
|
java.util.Collection<java.lang.String> |
getApplicableAttributes()
|
java.util.List<java.lang.String> |
getApplicableCallNames()
|
java.util.List<java.lang.String> |
getApplicableCallOwners()
|
java.util.Collection<java.lang.String> |
getApplicableElements()
|
java.util.EnumSet<Scope> |
getApplicableFiles()
|
java.util.List<java.lang.String> |
getApplicableMethodNames()
|
java.util.List<java.lang.Class<? extends lombok.ast.Node>> |
getApplicableNodeTypes()
|
Speed |
getSpeed()
Returns the expected speed of this detector |
Speed |
getSpeed(Issue issue)
Returns the expected speed of this detector. |
void |
run(Context context)
Runs the detector. |
void |
visitAttribute(XmlContext context,
org.w3c.dom.Attr attribute)
|
void |
visitBuildScript(Context context,
java.util.Map<java.lang.String,java.lang.Object> sharedData)
|
void |
visitDocument(XmlContext context,
org.w3c.dom.Document document)
|
void |
visitElement(XmlContext context,
org.w3c.dom.Element element)
|
void |
visitElementAfter(XmlContext context,
org.w3c.dom.Element element)
|
void |
visitMethod(JavaContext context,
lombok.ast.AstVisitor visitor,
lombok.ast.MethodInvocation node)
|
void |
visitResourceReference(JavaContext context,
lombok.ast.AstVisitor visitor,
lombok.ast.Node node,
java.lang.String type,
java.lang.String name,
boolean isFramework)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Detector()
Method Detail |
---|
public void run(@NonNull Context context)
Detector.XmlScanner
and Detector.JavaScanner
, where
there are specialized analysis methods instead such as
Detector.XmlScanner.visitElement(XmlContext, Element)
.
context
- the context describing the work to be donepublic boolean appliesTo(@NonNull Context context, @NonNull java.io.File file)
context
- the context to checkfile
- the file in the context to check
public void beforeCheckProject(@NonNull Context context)
context
- the context for the check referencing the project, lint
client, etcpublic void afterCheckProject(@NonNull Context context)
context
- the context for the check referencing the project, lint
client, etcpublic void beforeCheckLibraryProject(@NonNull Context context)
context
- the context for the check referencing the project, lint
client, etcpublic void afterCheckLibraryProject(@NonNull Context context)
context
- the context for the check referencing the project, lint
client, etcpublic void beforeCheckFile(@NonNull Context context)
Note: When this method is called at the beginning of checking an XML
file, the context is guaranteed to be an instance of XmlContext
,
and similarly for a Java source file, the context will be a
JavaContext
and so on.
context
- the context for the check referencing the file to be
checked, the project, etc.public void afterCheckFile(@NonNull Context context)
Note: When this method is called at the end of checking an XML
file, the context is guaranteed to be an instance of XmlContext
,
and similarly for a Java source file, the context will be a
JavaContext
and so on.
context
- the context for the check referencing the file to be
checked, the project, etc.@NonNull public Speed getSpeed()
@NonNull public Speed getSpeed(@NonNull Issue issue)
getSpeed()
instead.
issue
- the issue to look up the analysis speed for
public void visitDocument(@NonNull XmlContext context, @NonNull org.w3c.dom.Document document)
public void visitElement(@NonNull XmlContext context, @NonNull org.w3c.dom.Element element)
public void visitElementAfter(@NonNull XmlContext context, @NonNull org.w3c.dom.Element element)
public void visitAttribute(@NonNull XmlContext context, @NonNull org.w3c.dom.Attr attribute)
@Nullable public java.util.Collection<java.lang.String> getApplicableElements()
@Nullable public java.util.Collection<java.lang.String> getApplicableAttributes()
@Nullable public java.util.List<java.lang.String> getApplicableMethodNames()
@Nullable public lombok.ast.AstVisitor createJavaVisitor(@NonNull JavaContext context)
@Nullable public java.util.List<java.lang.Class<? extends lombok.ast.Node>> getApplicableNodeTypes()
public void visitMethod(@NonNull JavaContext context, @Nullable lombok.ast.AstVisitor visitor, @NonNull lombok.ast.MethodInvocation node)
public boolean appliesToResourceRefs()
public void visitResourceReference(@NonNull JavaContext context, @Nullable lombok.ast.AstVisitor visitor, @NonNull lombok.ast.Node node, @NonNull java.lang.String type, @NonNull java.lang.String name, boolean isFramework)
@Nullable public java.util.List<java.lang.String> applicableSuperClasses()
public void checkClass(@NonNull JavaContext context, @NonNull lombok.ast.ClassDeclaration node, @NonNull JavaParser.ResolvedClass resolvedClass)
public void checkClass(@NonNull ClassContext context, @NonNull org.objectweb.asm.tree.ClassNode classNode)
@Nullable public java.util.List<java.lang.String> getApplicableCallNames()
@Nullable public java.util.List<java.lang.String> getApplicableCallOwners()
public void checkCall(@NonNull ClassContext context, @NonNull org.objectweb.asm.tree.ClassNode classNode, @NonNull org.objectweb.asm.tree.MethodNode method, @NonNull org.objectweb.asm.tree.MethodInsnNode call)
@Nullable public int[] getApplicableAsmNodeTypes()
public void checkInstruction(@NonNull ClassContext context, @NonNull org.objectweb.asm.tree.ClassNode classNode, @NonNull org.objectweb.asm.tree.MethodNode method, @NonNull org.objectweb.asm.tree.AbstractInsnNode instruction)
public boolean appliesToFolder(@NonNull Scope scope, @Nullable com.android.resources.ResourceFolderType folderType)
@NonNull public java.util.EnumSet<Scope> getApplicableFiles()
public void visitBuildScript(@NonNull Context context, java.util.Map<java.lang.String,java.lang.Object> sharedData)
public void checkFolder(@NonNull ResourceContext context, @NonNull java.lang.String folderName)
public void checkBinaryResource(@NonNull ResourceContext context)
public boolean appliesTo(@NonNull com.android.resources.ResourceFolderType folderType)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |