| Method from groovy.lang.MetaMethod Detail: |
public void checkParameters(Class[] arguments) {
// lets check that the argument types are valid
if (!isValidMethod(arguments)) {
throw new IllegalArgumentException(
"Parameters to method: "
+ getName()
+ " do not match types: "
+ InvokerHelper.toString(getParameterTypes())
+ " for arguments: "
+ InvokerHelper.toString(arguments));
}
}
Checks that the given parameters are valid to call this method |
public Object clone() {
try {
return super.clone();
}
catch (CloneNotSupportedException e) {
throw new GroovyRuntimeException("This should never happen", e);
}
}
|
public Object doMethodInvoke(Object object,
Object[] argumentArray) {
argumentArray = coerceArgumentsToClasses(argumentArray);
try {
return invoke(object, argumentArray);
} catch (Exception e) {
throw processDoMethodInvokeException(e, object, argumentArray);
}
}
|
protected static boolean equal(CachedClass[] a,
Class[] b) {
if (a.length == b.length) {
for (int i = 0, size = a.length; i < size; i++) {
if (!a[i].getTheClass().equals(b[i])) {
return false;
}
}
return true;
}
return false;
}
|
protected static boolean equal(CachedClass[] a,
CachedClass[] b) {
if (a.length == b.length) {
for (int i = 0, size = a.length; i < size; i++) {
if (a[i] != b[i]) {
return false;
}
}
return true;
}
return false;
}
|
abstract public CachedClass getDeclaringClass()
|
public String getDescriptor() {
return BytecodeHelper.getMethodDescriptor(getReturnType(), getNativeParameterTypes());
}
|
abstract public int getModifiers()
|
public String getMopName() {
if (mopName == null) {
String name = getName();
CachedClass declaringClass = getDeclaringClass();
if ((getModifiers() & (Modifier.PUBLIC| Modifier.PROTECTED)) == 0)
mopName = new StringBuffer().append("this$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
else
mopName = new StringBuffer().append("super$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
}
return mopName;
}
|
abstract public String getName()
|
abstract public Class getReturnType()
|
public synchronized String getSignature() {
if (signature == null) {
CachedClass [] parameters = getParameterTypes();
final String name = getName();
StringBuffer buf = new StringBuffer(name.length()+parameters.length*10);
buf.append(getReturnType().getName());
//
buf.append(' ");
buf.append(name);
buf.append('(");
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
buf.append(", ");
}
buf.append(parameters[i].getName());
}
buf.append(')");
signature = buf.toString();
}
return signature;
}
|
abstract public Object invoke(Object object,
Object[] arguments)
|
public boolean isAbstract() {
return (getModifiers() & Modifier.ABSTRACT) != 0;
}
|
public boolean isCacheable() {
return true;
}
|
public boolean isMethod(MetaMethod method) {
return getName().equals(method.getName())
&& getModifiers() == method.getModifiers()
&& getReturnType().equals(method.getReturnType())
&& equal(getParameterTypes(), method.getParameterTypes());
}
|
public final boolean isPrivate() {
return (getModifiers() & Modifier.PRIVATE) != 0;
}
|
public final boolean isProtected() {
return (getModifiers() & Modifier.PROTECTED) != 0;
}
|
public final boolean isPublic() {
return (getModifiers() & Modifier.PUBLIC) != 0;
}
|
public final boolean isSame(MetaMethod method) {
return getName().equals(method.getName())
&& compatibleModifiers(getModifiers(), method.getModifiers())
&& getReturnType().equals(method.getReturnType())
&& equal(getParameterTypes(), method.getParameterTypes());
}
|
public boolean isStatic() {
return (getModifiers() & Modifier.STATIC) != 0;
}
|
public final RuntimeException processDoMethodInvokeException(Exception e,
Object object,
Object[] argumentArray) {
if (e instanceof IllegalArgumentException) {
//TODO: test if this is OK with new MOP, should be changed!
// we don't want the exception being unwrapped if it is a IllegalArgumentException
// but in the case it is for example a IllegalThreadStateException, we want the unwrapping
// from the runtime
//Note: the reason we want unwrapping sometimes and sometimes not is that the method
// invocation tries to invoke the method with and then reacts with type transformation
// if the invocation failed here. This is OK for IllegalArgumentException, but it is
// possible that a Reflector will be used to execute the call and then an Exception from inside
// the method is not wrapped in a InvocationTargetException and we will end here.
boolean setReason = e.getClass() != IllegalArgumentException.class || this instanceof GeneratedMetaMethod;
return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, setReason);
}
if (e instanceof RuntimeException)
return (RuntimeException) e;
return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, true);
}
|
public String toString() {
return super.toString()
+ "[name: "
+ getName()
+ " params: "
+ InvokerHelper.toString(getParameterTypes())
+ " returns: "
+ getReturnType()
+ " owner: "
+ getDeclaringClass()
+ "]";
}
|