ru.saidgadjiev.proxymaker.ProxyRuntimeHelper Maven / Gradle / Ivy
package ru.saidgadjiev.proxymaker;
import java.lang.reflect.Method;
import static ru.saidgadjiev.proxymaker.ProxyFactoryHelper.*;
/**
* Runtime support routines that the classes generated by ProxyFactory use.
*/
public final class ProxyRuntimeHelper {
/**
* Utils class can't be instantiated.
*/
private ProxyRuntimeHelper() { }
/**
* Find method in {@code className} via reflection and return method reference {@link Method}.
* @param className target class name
* @param name target method name
* @param parametrTypeClassNames target method fully qualified paramentr type names
* @return method reference {@link Method}
*/
public static Method findMethod(String className, String name, String[] parametrTypeClassNames) {
try {
Class[] parametrTypes = new Class[parametrTypeClassNames.length];
int i = 0;
for (String parametrTypeClassName: parametrTypeClassNames) {
if (isPrimitive(parametrTypeClassName)) {
parametrTypes[i++] = PRIMITIVE_TYPES[typeIndex(parametrTypeClassName)];
} else {
parametrTypes[i++] = Class.forName(parametrTypeClassName);
}
}
return Class.forName(className).getMethod(name, parametrTypes);
} catch (NoSuchMethodException e) {
throw new NoSuchMethodError(e.getMessage());
} catch (ClassNotFoundException e) {
throw new NoClassDefFoundError(e.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy