Search in sources :

Example 16 with MethodNode

use of org.jetbrains.org.objectweb.asm.tree.MethodNode in project kotlin by JetBrains.

the class AsmVisitor method runClassDetectors.

// ASM API uses raw types
@SuppressWarnings("rawtypes")
void runClassDetectors(ClassContext context) {
    ClassNode classNode = context.getClassNode();
    for (Detector detector : mAllDetectors) {
        detector.beforeCheckFile(context);
    }
    for (Detector detector : mFullClassChecks) {
        Detector.ClassScanner scanner = (Detector.ClassScanner) detector;
        scanner.checkClass(context, classNode);
        detector.afterCheckFile(context);
    }
    if (!mMethodNameToChecks.isEmpty() || !mMethodOwnerToChecks.isEmpty() || mNodeTypeDetectors != null && mNodeTypeDetectors.length > 0) {
        List methodList = classNode.methods;
        for (Object m : methodList) {
            MethodNode method = (MethodNode) m;
            InsnList nodes = method.instructions;
            for (int i = 0, n = nodes.size(); i < n; i++) {
                AbstractInsnNode instruction = nodes.get(i);
                int type = instruction.getType();
                if (type == AbstractInsnNode.METHOD_INSN) {
                    MethodInsnNode call = (MethodInsnNode) instruction;
                    String owner = call.owner;
                    List<ClassScanner> scanners = mMethodOwnerToChecks.get(owner);
                    if (scanners != null) {
                        for (ClassScanner scanner : scanners) {
                            scanner.checkCall(context, classNode, method, call);
                        }
                    }
                    String name = call.name;
                    scanners = mMethodNameToChecks.get(name);
                    if (scanners != null) {
                        for (ClassScanner scanner : scanners) {
                            scanner.checkCall(context, classNode, method, call);
                        }
                    }
                }
                if (mNodeTypeDetectors != null && type < mNodeTypeDetectors.length) {
                    List<ClassScanner> scanners = mNodeTypeDetectors[type];
                    if (scanners != null) {
                        for (ClassScanner scanner : scanners) {
                            scanner.checkInstruction(context, classNode, method, instruction);
                        }
                    }
                }
            }
        }
    }
    for (Detector detector : mAllDetectors) {
        detector.afterCheckFile(context);
    }
}
Also used : ClassNode(org.jetbrains.org.objectweb.asm.tree.ClassNode) ClassScanner(com.android.tools.klint.detector.api.Detector.ClassScanner) InsnList(org.jetbrains.org.objectweb.asm.tree.InsnList) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode) Detector(com.android.tools.klint.detector.api.Detector) ClassScanner(com.android.tools.klint.detector.api.Detector.ClassScanner) MethodNode(org.jetbrains.org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode) ArrayList(java.util.ArrayList) List(java.util.List) InsnList(org.jetbrains.org.objectweb.asm.tree.InsnList)

Aggregations

MethodNode (org.jetbrains.org.objectweb.asm.tree.MethodNode)16 NotNull (org.jetbrains.annotations.NotNull)8 List (java.util.List)4 ClassNode (org.jetbrains.org.objectweb.asm.tree.ClassNode)4 DeserializedCallableMemberDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)3 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)3 AbstractInsnNode (org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)3 AnalyzerException (org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException)3 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 KotlinType (org.jetbrains.kotlin.types.KotlinType)2 ClassReader (org.jetbrains.org.objectweb.asm.ClassReader)2 Method (org.jetbrains.org.objectweb.asm.commons.Method)2 InsnList (org.jetbrains.org.objectweb.asm.tree.InsnList)2 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)2 Detector (com.android.tools.klint.detector.api.Detector)1 ClassScanner (com.android.tools.klint.detector.api.Detector.ClassScanner)1 Location (com.android.tools.klint.detector.api.Location)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1