protected Class[] getPT() { return method.getNativeParameterTypes(); } }
private static MetaMethod adjustParamTypesForStdMethods(MetaMethod metaMethod, String methodName) { Class[] nativeParamTypes = metaMethod.getNativeParameterTypes(); nativeParamTypes = (nativeParamTypes != null) ? nativeParamTypes : EMPTY_CLASS_ARRAY; // for methodMissing, first parameter should be String type - to allow overriding of this method without // type String explicitly specified for first parameter (missing method name) - GROOVY-2951 if("methodMissing".equals(methodName) && nativeParamTypes.length == 2 && nativeParamTypes[0] != String.class) { nativeParamTypes[0] = String.class; } return metaMethod; } public CachedMethod getDoCall() {
private static List<Pair<Class,Class>> getConflictClasses(List<MetaMethod> sugg, Class[] argumentClasses) { List<Pair<Class,Class>> ret = new LinkedList<Pair<Class,Class>>(); Set<Class> recordedClasses = new HashSet<Class>(); for (MetaMethod method : sugg) { Class[] para = method.getNativeParameterTypes(); for (Class aPara : para) { if (recordedClasses.contains(aPara)) continue; for (Class argumentClass : argumentClasses) { if (argumentClass == null) continue; if (argumentClass == aPara) continue; if (argumentClass.getName().equals(aPara.getName())) { ret.add(new Pair<Class, Class>(argumentClass, aPara)); } } recordedClasses.add(aPara); } } return ret; }
@Override public Type getType() { Method m = MopUtil.methodFor(setterLikeMethod); return m != null ? GenericTypeReflector.getExactParameterTypes(m, ownerType)[0] : setterLikeMethod.getNativeParameterTypes()[0]; }
/** * Return a descriptor of this method based on the return type and parameters of this method. */ public String getDescriptor() { return BytecodeHelper.getMethodDescriptor(getReturnType(), getNativeParameterTypes()); }
public TransformMetaMethod(MetaMethod metaMethod) { this.metaMethod = metaMethod; setParametersTypes(metaMethod.getParameterTypes()); nativeParamTypes = metaMethod.getNativeParameterTypes(); }
public MethodClosure(Object owner, String method) { super(owner); this.method = method; final Class clazz = owner.getClass()==Class.class?(Class) owner:owner.getClass(); maximumNumberOfParameters = 0; parameterTypes = EMPTY_CLASS_ARRAY; List<MetaMethod> methods = InvokerHelper.getMetaClass(clazz).respondsTo(owner, method); for(MetaMethod m : methods) { if (m.getParameterTypes().length > maximumNumberOfParameters) { Class[] pt = m.getNativeParameterTypes(); maximumNumberOfParameters = pt.length; parameterTypes = pt; } } }
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()); } } } }
public void call() { MetaMethod existing = null; try { existing = pickMethod(metaMethodFromSuper.getName(), metaMethodFromSuper.getNativeParameterTypes()); } catch ( GroovyRuntimeException e) { // ignore, this happens with overlapping method definitions } if (existing == null) { addMethodWithKey(metaMethodFromSuper); } else { boolean isGroovyMethod = getMetaMethods().contains(existing); if (isGroovyMethod) { addMethodWithKey(metaMethodFromSuper); } else if (inheritedMetaMethods.contains(existing)) { inheritedMetaMethods.remove(existing); addMethodWithKey(metaMethodFromSuper); } } }
private void registerIfClosure(Object arg, boolean replace) { if (arg instanceof Closure) { if (propertyName.equals(CONSTRUCTOR)) { propertyName = GROOVY_CONSTRUCTOR; } Closure callable = (Closure) arg; final List<MetaMethod> list = ClosureMetaMethod.createMethodList(propertyName, theClass, callable); if (list.isEmpty() && this.isStatic) { Class[] paramTypes = callable.getParameterTypes(); registerStatic(callable, replace, paramTypes); return; } for (MetaMethod method : list) { Class[] paramTypes = method.getNativeParameterTypes(); if (this.isStatic) { registerStatic(callable, replace, paramTypes); } else { registerInstance(method, replace, paramTypes); } } } }
public Object leftShift(Closure c) { if (c != null) { final List<MetaMethod> list = ClosureMetaMethod.createMethodList(GROOVY_CONSTRUCTOR, theClass, c); for (MetaMethod method : list) { Class[] paramTypes = method.getNativeParameterTypes(); Constructor ctor = retrieveConstructor(paramTypes); if (ctor != null) throw new GroovyRuntimeException("Cannot add new constructor for arguments [" + DefaultGroovyMethods.inspect(paramTypes) + "]. It already exists!"); registerInstanceMethod(method); } } return this; } }
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())); }
protected Class[] getPT() { return method.getNativeParameterTypes(); } }
private static MetaMethod adjustParamTypesForStdMethods(MetaMethod metaMethod, String methodName) { Class[] nativeParamTypes = metaMethod.getNativeParameterTypes(); nativeParamTypes = (nativeParamTypes != null) ? nativeParamTypes : new Class[0]; // for methodMissing, first parameter should be String type - to allow overriding of this method without // type String explicitly specified for first parameter (missing method name) - GROOVY-2951 if("methodMissing".equals(methodName) && nativeParamTypes.length == 2 && nativeParamTypes[0] != String.class) { nativeParamTypes[0] = String.class; } return metaMethod; } public CachedMethod getDoCall() {
public TransformMetaMethod(MetaMethod metaMethod) { this.metaMethod = metaMethod; setParametersTypes(metaMethod.getParameterTypes()); nativeParamTypes = metaMethod.getNativeParameterTypes(); }
public TransformMetaMethod(MetaMethod metaMethod) { this.metaMethod = metaMethod; setParametersTypes(metaMethod.getParameterTypes()); nativeParamTypes = metaMethod.getNativeParameterTypes(); }
public TransformMetaMethod(MetaMethod metaMethod) { this.metaMethod = metaMethod; setParametersTypes(metaMethod.getParameterTypes()); nativeParamTypes = metaMethod.getNativeParameterTypes(); }
public TransformMetaMethod(MetaMethod metaMethod) { this.metaMethod = metaMethod; setParametersTypes(metaMethod.getParameterTypes()); nativeParamTypes = metaMethod.getNativeParameterTypes(); }
public String getDescriptor() { return BytecodeHelper.getMethodDescriptor(getReturnType(), getNativeParameterTypes()); }