public Class getReturnType() { return method.getReturnType(); }
public Class getReturnType() { return metaMethod.getReturnType(); }
/** * Return a descriptor of this method based on the return type and parameters of this method. */ public String getDescriptor() { return BytecodeHelper.getMethodDescriptor(getReturnType(), getNativeParameterTypes()); }
/** * Returns the signature of this method * * @return The signature of this method */ public synchronized String getSignature() { if (signature == null) { CachedClass [] parameters = getParameterTypes(); final String name = getName(); StringBuilder buf = new StringBuilder(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; }
/** *Returns true if this this metamethod represents the same method as the argument. * * @param method A metaMethod instance * @return true if method is for the same method as this method, false otherwise. */ public boolean isMethod(MetaMethod method) { return getName().equals(method.getName()) && getModifiers() == method.getModifiers() && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
private void appendMethods(StringBuilder buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
/** * @param method the method to compare against * @return true if the given method has the same name, parameters, return type * and modifiers but may be defined on another type */ public final boolean isSame(MetaMethod method) { return getName().equals(method.getName()) && compatibleModifiers(getModifiers(), method.getModifiers()) && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
/** * Returns a string representation of this method */ public String toString() { return super.toString() + "[name: " + getName() + " params: " + InvokerHelper.toString(getParameterTypes()) + " returns: " + getReturnType() + " owner: " + getDeclaringClass() + "]"; }
public static boolean isVoidMethod(@Nullable Object target, String method, Object... args) { if (target == null) return false; // no way to tell Class[] argTypes = ReflectionUtil.getTypes(args); // the way we choose metaClass, we won't find methods on java.lang.Class // but since java.lang.Class has no void methods other than the ones inherited // from java.lang.Object, and since we operate on a best effort basis, that's OK // also we will choose a static method like Foo.getName() over the equally // named method on java.lang.Class, but this is consistent with current Groovy semantics // (see http://jira.codehaus.org/browse/GROOVY-3548) // in the end it's probably best to rely on NullAwareInvokeMethodSpec to tell us if // everything is OK MetaClass metaClass = target instanceof Class ? InvokerHelper.getMetaClass((Class) target) : InvokerHelper.getMetaClass(target); // seems to find more methods than getMetaMethod() MetaMethod metaMethod = metaClass.pickMethod(method, argTypes); if (metaMethod == null) return false; // we were unable to figure out which method was called Class returnType = metaMethod.getReturnType(); // although Void.class will occur rarely, it makes sense to handle // it in the same way as void.class return returnType == void.class || returnType == Void.class; }
ret = element; Class returnType = element.getReturnType(); if (isGetter && !(returnType == Void.class || returnType == Void.TYPE) && ret = addElementToList(ret, element); Class returnType = element.getReturnType(); if (isGetter && !(returnType == Void.class || returnType == Void.TYPE) && for (final Object o : ((List) ret)) { MetaMethod element = (MetaMethod) o; int localDistance = distanceToObject(element.getReturnType());
protected String[] methodInfo(MetaMethod method) { String[] result = new String[MEMBER_EXCEPTIONS_IDX + 1]; int mod = method.getModifiers(); result[MEMBER_ORIGIN_IDX] = GROOVY; result[MEMBER_MODIFIER_IDX] = Modifier.toString(mod); result[MEMBER_DECLARER_IDX] = shortName(method.getDeclaringClass().getTheClass()); result[MEMBER_TYPE_IDX] = shortName(method.getReturnType()); result[MEMBER_NAME_IDX] = method.getName(); result[MEMBER_PARAMS_IDX] = makeParamsInfo(method.getNativeParameterTypes()); result[MEMBER_EXCEPTIONS_IDX] = NOT_APPLICABLE; // no exception info for Groovy MetaMethods return withoutNulls(result); }
private IMockInvocation createMockInvocation(MetaMethod metaMethod, Object target, String methodName, Object[] arguments, boolean isStatic) { IMockObject mockObject = new MockObject(configuration.getName(), configuration.getExactType(), target, configuration.isVerified(), configuration.isGlobal(), configuration.getDefaultResponse(), specification, this); IMockMethod mockMethod; if (metaMethod != null) { List<Type> parameterTypes = Arrays.<Type>asList(metaMethod.getNativeParameterTypes()); mockMethod = new DynamicMockMethod(methodName, parameterTypes, metaMethod.getReturnType(), isStatic); } else { mockMethod = new DynamicMockMethod(methodName, arguments.length, isStatic); } return new MockInvocation(mockObject, mockMethod, Arrays.asList(arguments), new GroovyRealMethodInvoker(getAdaptee())); }
/** * @return the matching method which should be found */ private MetaMethod findMethod(CachedMethod aMethod) { Object methods = getMethods(theClass, aMethod.getName(), false); if (methods instanceof FastArray) { FastArray m = (FastArray) methods; final int len = m.size; final Object data[] = m.getArray(); for (int i = 0; i != len; ++i) { MetaMethod method = (MetaMethod) data[i]; if (method.isMethod(aMethod)) { return method; } } } else { MetaMethod method = (MetaMethod) methods; if (method.getName().equals(aMethod.getName()) // TODO: should be better check for case when only diff in modifiers can be SYNTHETIC flag // && method.getModifiers() == aMethod.getModifiers() && method.getReturnType().equals(aMethod.getReturnType()) && MetaMethod.equal(method.getParameterTypes(), aMethod.getParameterTypes())) { return method; } } return aMethod; }
if (isGetter) { return new MetaBeanProperty(propName, propertyMethod.getReturnType(), propertyMethod, null); } else {
public void setMetaMethod(MetaMethod mmeth) { this.metaMethod = mmeth; super.setType(ClassHelper.make(mmeth.getReturnType())); } }
@Override public String getRhsHtml(HtmlFormatter formatter) { // no FQN return types but only the classname, please: String retType = method.getReturnType().getSimpleName(); retType = GroovyUtils.stripPackage(retType); formatter.appendText(retType); return formatter.getText(); }
public boolean isMethod(MetaMethod method) { return getName().equals(method.getName()) && getModifiers() == method.getModifiers() && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
public String toString() { return super.toString() + "[name: " + getName() + " params: " + InvokerHelper.toString(getParameterTypes()) + " returns: " + getReturnType() + " owner: " + getDeclaringClass() + "]"; }
/** * @param method the method to compare against * @return true if the given method has the same name, parameters, return type * and modifiers but may be defined on another type */ public final boolean isSame(MetaMethod method) { return getName().equals(method.getName()) && compatibleModifiers(getModifiers(), method.getModifiers()) && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
public String toString() { return super.toString() + "[name: " + getName() + " params: " + InvokerHelper.toString(getParameterTypes()) + " returns: " + getReturnType() + " owner: " + getDeclaringClass() + "]"; }