|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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 |
---|
void checkClass(@NonNull ClassContext context, @NonNull org.objectweb.asm.tree.ClassNode classNode)
context
- the context of the lint check, pointing to for example
the fileclassNode
- the root class node@Nullable int[] getApplicableAsmNodeTypes()
AbstractInsnNode
class) that this scanner applies to. The
checkInstruction(ClassContext, ClassNode, MethodNode, AbstractInsnNode)
method will be called for each match.
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)
context
- the context of the lint check, pointing to for example
the fileclassNode
- the root class nodemethod
- the method node containing the callinstruction
- the actual instruction@Nullable java.util.List<java.lang.String> getApplicableCallNames()
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.
@Nullable java.util.List<java.lang.String> getApplicableCallOwners()
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.
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)
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()
.
context
- the context of the lint check, pointing to for example
the fileclassNode
- the root class nodemethod
- the method node containing the callcall
- the actual method call node
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |