com.android.tools.lint.detector.api
Interface Detector.ClassScanner

Enclosing class:
Detector

public static interface Detector.ClassScanner

Specialized interface for detectors that scan Java class files


Method Summary
 void checkCall(ClassContext context, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.MethodInsnNode call)
          Process a given method call node, and register lint issues if applicable.
 void checkClass(ClassContext context, org.objectweb.asm.tree.ClassNode classNode)
          Checks the given class' bytecode for issues.
 void checkInstruction(ClassContext context, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode method, org.objectweb.asm.tree.AbstractInsnNode instruction)
          Process a given instruction node, and register lint issues if applicable.
 int[] getApplicableAsmNodeTypes()
          Returns the list of node types (corresponding to the constants in the AbstractInsnNode class) that this scanner applies to.
 java.util.List<java.lang.String> getApplicableCallNames()
          Return the list of method call names (in VM format, e.g.
 java.util.List<java.lang.String> getApplicableCallOwners()
          Just like Detector.getApplicableCallNames(), but for the owner field instead.
 

Method Detail

checkClass

void checkClass(@NonNull
                ClassContext context,
                @NonNull
                org.objectweb.asm.tree.ClassNode classNode)
Checks the given class' bytecode for issues.

Parameters:
context - the context of the lint check, pointing to for example the file
classNode - the root class node

getApplicableAsmNodeTypes

@Nullable
int[] getApplicableAsmNodeTypes()
Returns the list of node types (corresponding to the constants in the AbstractInsnNode class) that this scanner applies to. The checkInstruction(ClassContext, ClassNode, MethodNode, AbstractInsnNode) method will be called for each match.

Returns:
an array containing all the node types this detector should be called for, or null if none.

checkInstruction

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)
Process a given instruction node, and register lint issues if applicable.

Parameters:
context - the context of the lint check, pointing to for example the file
classNode - the root class node
method - the method node containing the call
instruction - the actual instruction

getApplicableCallNames

@Nullable
java.util.List<java.lang.String> getApplicableCallNames()
Return the list of method call names (in VM format, e.g. "" for constructors, etc) for method calls this detector is interested in, or null. T his will be used to dispatch calls to checkCall(ClassContext, ClassNode, MethodNode, MethodInsnNode) for only the method calls in owners that the detector is interested in.

NOTE: If you return non null from this method, then only checkCall(ClassContext, ClassNode, MethodNode, MethodInsnNode) will be called if a suitable method is found; checkClass(ClassContext, ClassNode) will not be called under any circumstances.

This makes it easy to write detectors that focus on some fixed calls, and allows lint to make a single pass over the bytecode over a class, and efficiently dispatch method calls to any detectors that are interested in it. Without this, each new lint check interested in a single method, would be doing a complete pass through all the bytecode instructions of the class via the checkClass(ClassContext, ClassNode) method, which would make each newly added lint check make lint slower. Now a single dispatch map is used instead, and for each encountered call in the single dispatch, it looks up in the map which if any detectors are interested in the given call name, and dispatches to each one in turn.

Returns:
a list of applicable method names, or null.

getApplicableCallOwners

@Nullable
java.util.List<java.lang.String> getApplicableCallOwners()
Just like Detector.getApplicableCallNames(), but for the owner field instead. The checkCall(ClassContext, ClassNode, MethodNode, MethodInsnNode) method will be called for all MethodInsnNode instances where the owner field matches any of the members returned in this node.

Note that if your detector provides both a name and an owner, the method will be called for any nodes matching either the name or the owner, not only where they match both. Note also that it will be called twice - once for the name match, and (at least once) for the owner match.

Returns:
a list of applicable owner names, or null.

checkCall

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)
Process a given method call node, and register lint issues if applicable. This is similar to the checkInstruction(ClassContext, ClassNode, MethodNode, AbstractInsnNode) method, but has the additional advantage that it is only called for known method names or method owners, according to getApplicableCallNames() and getApplicableCallOwners().

Parameters:
context - the context of the lint check, pointing to for example the file
classNode - the root class node
method - the method node containing the call
call - the actual method call node