
com.github.houbb.asm.tool.reflection.AsmMethods Maven / Gradle / Ivy
package com.github.houbb.asm.tool.reflection;
import com.github.houbb.asm.tool.reflection.method.core.impl.AsmMethodParamName;
import com.github.houbb.asm.tool.vo.MethodMeta;
import com.github.houbb.heaven.support.instance.impl.Instances;
import com.github.houbb.heaven.util.common.ArgUtil;
import com.github.houbb.heaven.util.lang.reflect.ReflectMethodUtil;
import org.objectweb.asm.Type;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
/**
* Ams 方法工具类
* @author binbin.hou
* @since 0.0.1
*/
public final class AsmMethods {
private AsmMethods(){}
/**
* 根据注解获取对应的参数名称
* @param method 方法信息
* @return 方法列表
* @since 0.0.1
*/
public static List getParamNamesByAnnotation(final Method method) {
ArgUtil.notNull(method, "method");
return ReflectMethodUtil.getParamNames(method);
}
/**
* 根据注解获取对应的参数名称
* @param method 方法信息
* @return 方法列表
* @since 0.0.1
*/
public static List getParamNamesByAsm(final Method method) {
ArgUtil.notNull(method, "method");
final boolean statics = Modifier.isStatic(method.getModifiers());
final String name = method.getName();
final String descriptor = Type.getMethodDescriptor(method);
final Class[] parameterTypes = method.getParameterTypes();
final Class clazz = method.getDeclaringClass();
MethodMeta methodMeta = new MethodMeta();
methodMeta.statics(statics).name(name)
.declaringClass(clazz).descriptor(descriptor)
.paramTypes(parameterTypes);
return Instances.singleton(AsmMethodParamName.class).getParamNames(methodMeta);
}
/**
* 根据注解获取对应的参数名称
* @param constructor 构造器
* @return 方法列表
* @since 0.0.2
*/
public static List getParamNamesByAnnotation(final Constructor constructor) {
ArgUtil.notNull(constructor, "constructor");
Annotation[][] annotations = constructor.getParameterAnnotations();
return ReflectMethodUtil.getParamNames(annotations);
}
/**
* 根据注解获取对应的参数名称
* @param constructor 构造器
* @return 方法列表
* @since 0.0.2
*/
public static List getParamNamesByAsm(final Constructor constructor) {
ArgUtil.notNull(constructor, "constructor");
final boolean statics = Modifier.isStatic(constructor.getModifiers());
final String name = "";
final String descriptor = Type.getConstructorDescriptor(constructor);
final Class[] parameterTypes = constructor.getParameterTypes();
final Class clazz = constructor.getDeclaringClass();
MethodMeta methodMeta = new MethodMeta();
methodMeta.statics(statics).name(name)
.declaringClass(clazz).descriptor(descriptor)
.paramTypes(parameterTypes);
return Instances.singleton(AsmMethodParamName.class).getParamNames(methodMeta);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy