package org.jruby.anno;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
public class JavaMethodDescriptor extends MethodDescriptor<Method> {
public final Class[] parameters;
public final Class returnClass;
public final Class declaringClass;
@Deprecated
public String signature;
@Deprecated
public Class[] argumentTypes;
public JavaMethodDescriptor(Method method) {
super(method);
declaringClass = method.getDeclaringClass();
parameters = method.getParameterTypes();
returnClass = method.getReturnType();
}
public final Class[] getArgumentTypes() {
if (argumentTypes == null) {
int start = (hasContext ? 1 : 0) + (isStatic ? 1 : 0);
int end = parameters.length - (hasBlock ? 1 : 0);
Class[] argumentTypes = new Class[end - start];
System.arraycopy(parameters, start, argumentTypes, 0, end - start);
return this.argumentTypes = argumentTypes;
}
return argumentTypes;
}
public Class getDeclaringClass() {
return declaringClass;
}
public Class[] getParameterClasses() {
return parameters;
}
public Class getReturnClass() {
return returnClass;
}
protected <A extends Annotation> A getAnnotation(Method methodObject, Class<A> annotationType) {
return methodObject.getAnnotation(annotationType);
}
protected int getModifiers(Method methodObject) {
return methodObject.getModifiers();
}
protected String getDeclaringClassName(Method methodObject) {
return methodObject.getDeclaringClass().getName();
}
protected String getSimpleName(Method methodObject) {
return methodObject.getName();
}
protected boolean hasContext(Method methodObject) {
Class[] parameters = methodObject.getParameterTypes();
if (parameters.length > 0) {
return parameters[0] == ThreadContext.class;
}
return false;
}
protected boolean hasBlock(Method methodObject) {
Class[] parameters = methodObject.getParameterTypes();
if (parameters.length > 0) {
return parameters[parameters.length - 1] == Block.class;
}
return false;
}
protected int parameterCount(Method methodObject) {
return methodObject.getParameterTypes().length;
}
protected String parameterAsString(Method methodObject, int index) {
return methodObject.getParameterTypes()[index].getName();
}
}