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

top.hendrixshen.magiclib.util.ASMUtil Maven / Gradle / Ivy

package top.hendrixshen.magiclib.util;

import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import top.hendrixshen.magiclib.util.collect.ValueContainer;

import java.lang.annotation.Annotation;
import java.util.List;

public class ASMUtil {
    public static @NotNull ValueContainer getInVisibleAnnotations(
            @NotNull MethodNode methodNode, Class annotationClass) {
        return ASMUtil.getAnnotations(methodNode.invisibleAnnotations, Type.getDescriptor(annotationClass));
    }

    public static @NotNull ValueContainer getVisibleAnnotations(
            @NotNull MethodNode methodNode, Class annotationClass) {
        return ASMUtil.getAnnotations(methodNode.visibleAnnotations, Type.getDescriptor(annotationClass));
    }

    public static @NotNull ValueContainer getInvisibleAnnotations(
            @NotNull ClassNode classNode, Class annotationClass) {
        return ASMUtil.getAnnotations(classNode.invisibleAnnotations, Type.getDescriptor(annotationClass));
    }

    public static @NotNull ValueContainer getVisibleAnnotations(
            @NotNull ClassNode classNode, Class annotationClass) {
        return ASMUtil.getAnnotations(classNode.visibleAnnotations, Type.getDescriptor(annotationClass));
    }

    public static @NotNull ValueContainer getAnnotations(List annotations,
                                                                         String annotationType) {
        if (annotations == null) {
            return ValueContainer.empty();
        }

        for (AnnotationNode annotation : annotations) {
            if (annotationType.equals(annotation.desc)) {
                return ValueContainer.of(annotation);
            }
        }

        return ValueContainer.empty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy