Search in sources :

Example 1 with AnnotationNode

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

the class LintDriver method isSuppressed.

/**
     * Returns whether the given issue is suppressed in the given class.
     *
     * @param issue the issue to be checked, or null to just check for "all"
     * @param classNode the class containing the issue
     * @return true if there is a suppress annotation covering the specific
     *         issue in this class
     */
public boolean isSuppressed(@Nullable Issue issue, @NonNull ClassNode classNode) {
    if (classNode.invisibleAnnotations != null) {
        @SuppressWarnings("unchecked") List<AnnotationNode> annotations = classNode.invisibleAnnotations;
        return isSuppressed(issue, annotations);
    }
    if (classNode.outerClass != null && classNode.outerMethod == null && isAnonymousClass(classNode)) {
        ClassNode outer = getOuterClassNode(classNode);
        if (outer != null) {
            MethodNode m = findMethod(outer, CONSTRUCTOR_NAME, false);
            if (m != null) {
                MethodInsnNode call = findConstructorInvocation(m, classNode.name);
                if (call != null) {
                    if (isSuppressed(issue, outer, m, call)) {
                        return true;
                    }
                }
            }
            m = findMethod(outer, CLASS_CONSTRUCTOR, false);
            if (m != null) {
                MethodInsnNode call = findConstructorInvocation(m, classNode.name);
                if (call != null) {
                    if (isSuppressed(issue, outer, m, call)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : ClassNode(org.jetbrains.org.objectweb.asm.tree.ClassNode) MethodNode(org.jetbrains.org.objectweb.asm.tree.MethodNode) AnnotationNode(org.jetbrains.org.objectweb.asm.tree.AnnotationNode) MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)

Example 2 with AnnotationNode

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

the class LintDriver method isSuppressed.

// Unfortunately, ASMs nodes do not extend a common DOM node type with parent
// pointers, so we have to have multiple methods which pass in each type
// of node (class, method, field) to be checked.
/**
     * Returns whether the given issue is suppressed in the given method.
     *
     * @param issue the issue to be checked, or null to just check for "all"
     * @param classNode the class containing the issue
     * @param method the method containing the issue
     * @param instruction the instruction within the method, if any
     * @return true if there is a suppress annotation covering the specific
     *         issue on this method
     */
public boolean isSuppressed(@Nullable Issue issue, @NonNull ClassNode classNode, @NonNull MethodNode method, @Nullable AbstractInsnNode instruction) {
    if (method.invisibleAnnotations != null) {
        @SuppressWarnings("unchecked") List<AnnotationNode> annotations = method.invisibleAnnotations;
        return isSuppressed(issue, annotations);
    }
    // for members and <clinit> for static fields).
    if (instruction != null && method.name.charAt(0) == '<') {
        AbstractInsnNode next = LintUtils.getNextInstruction(instruction);
        if (next != null && next.getType() == AbstractInsnNode.FIELD_INSN) {
            FieldInsnNode fieldRef = (FieldInsnNode) next;
            FieldNode field = findField(classNode, fieldRef.owner, fieldRef.name);
            if (field != null && isSuppressed(issue, field)) {
                return true;
            }
        } else if (classNode.outerClass != null && classNode.outerMethod == null && isAnonymousClass(classNode)) {
            if (isSuppressed(issue, classNode)) {
                return true;
            }
        }
    }
    return false;
}
Also used : FieldNode(org.jetbrains.org.objectweb.asm.tree.FieldNode) AnnotationNode(org.jetbrains.org.objectweb.asm.tree.AnnotationNode) FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

AnnotationNode (org.jetbrains.org.objectweb.asm.tree.AnnotationNode)2 AbstractInsnNode (org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)1 ClassNode (org.jetbrains.org.objectweb.asm.tree.ClassNode)1 FieldInsnNode (org.jetbrains.org.objectweb.asm.tree.FieldInsnNode)1 FieldNode (org.jetbrains.org.objectweb.asm.tree.FieldNode)1 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)1 MethodNode (org.jetbrains.org.objectweb.asm.tree.MethodNode)1