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

name.remal.org.objectweb.asm.tree.MethodNode.kt Maven / Gradle / Ivy

package name.remal

import org.objectweb.asm.tree.*

val MethodNode.unusedLabelNodes: Set
    get() {
        val instructions = this.instructions ?: return emptySet()
        return buildSet {
            instructions.forEach { if (it is LabelNode) add(it) }

            if (isNotEmpty()) {
                tryCatchBlocks?.forEach { remove(it.start); remove(it.end); remove(it.handler) }
                localVariables?.forEach { remove(it.start); remove(it.end) }
                visibleLocalVariableAnnotations?.forEach { it.start?.let(this::removeAll); it.end?.let(this::removeAll) }
                invisibleLocalVariableAnnotations?.forEach { it.start?.let(this::removeAll); it.end?.let(this::removeAll) }
                instructions.forEach {
                    if (it is JumpInsnNode) remove(it.label)
                    if (it is LookupSwitchInsnNode) {
                        remove(it.dflt)
                        it.labels?.let(this::removeAll)
                    }
                    if (it is TableSwitchInsnNode) {
                        remove(it.dflt)
                        it.labels?.let(this::removeAll)
                    }
                }
            }
        }
    }


data class InstructionNodeContext(
    val node: T,
    val previousNode: AbstractInsnNode?,
    val nextNode: AbstractInsnNode?
)

data class InstructionNodeFilter(
    val nodeType: Class,
    val predicate: ((context: InstructionNodeContext) -> Boolean)? = null
)

fun  Class.toInstructionNodeFilter() = InstructionNodeFilter(this)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy