All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.gradle_plugins.dsl.utils.isAnnotatedBy.kt Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package name.remal.gradle_plugins.dsl.utils

import name.remal.ASM_API
import org.objectweb.asm.AnnotationVisitor
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassReader.*
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.Type

fun isAnnotatedBy(bytecode: ByteArray, annotationDesc: String): Boolean {
    var result = false
    val visitor = object : ClassVisitor(ASM_API) {
        override fun visitAnnotation(desc: String?, visible: Boolean): AnnotationVisitor? {
            if (annotationDesc == desc) result = true
            return null
        }
    }
    ClassReader(bytecode).accept(visitor, SKIP_DEBUG or SKIP_FRAMES or SKIP_CODE)
    return result
}

fun isAnnotatedBy(bytecode: ByteArray, annotationClass: Class<*>) = isAnnotatedBy(bytecode, Type.getDescriptor(annotationClass))




© 2015 - 2024 Weber Informatics LLC | Privacy Policy